Cfn/YAML/Schema.pm

filter: Statementstmt 57.4% 54 / 94 Branchbran 16.6% 6 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.1% 16 / 21 Podpod 0.0% 0 / 2 totaltotal 49.6% 76 / 153 CC 19 SCAR 35.9
CC
19
Cov
46%
__ANON__
90.0
__ANON__
72.0
new
2.0
CRAP 36.3
↑ Summary Cfn/Diff.pm »
1 package Cfn::YAML::Schema;
2 2 ▶ use base 'YAML::PP::Schema';
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub new {
7 0 ▶ my ($class, %args) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
8 0 my $self = bless {}, $class;
9 0 return $self;
10 }
11  
12 our $tag_subs = {
13 71 ▶ '!Ref' => sub { { Ref => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 3 ▶ '!Condition' => sub { { Condition => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 1 ▶ '!Base64' => sub { { 'Fn::Base64' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
16 4 ▶ '!Sub' => sub { { 'Fn::Sub' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 5 ▶ '!GetAZs' => sub { { 'Fn::GetAZs' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 6 ▶ '!ImportValue' => sub { { 'Fn::ImportValue' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 '!GetAtt' => sub {
20 1 ▶ my $value = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
21 1 my @parts = split /\./, $value, 2;
22 1 { 'Fn::GetAtt' => [ $parts[0], $parts[1] ] }
23 },
24 2 };
25  
26 2 our $sequence_tags = {
27 GetAtt => 1, Cidr => 1, Join => 1, FindInMap => 1, Split => 1,
28 Sub => 1, Equals => 1, Or => 1, And => 1, If => 1, Not => 1,
29 Select => 1,
30 };
31  
32 2 our $mapping_tags = {
33 Transform => 1,
34 Base64 => 1,
35 };
36  
37 sub register {
38 13 ▶ my ($self, %args) = @_;
Subroutine register: called CC=1 SCAR=2.3
Pod undocumented
39 13 my $schema = $args{schema};
40  
41 $schema->add_resolver(
42 tag => qr/^!.*/,
43 implicit => 0,
44 match => [ regex => qr{^(.*)$} => sub {
45 92 ▶ my ($self, $event) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
46 92 my $tag = $event->{ tag };
47 92 ▶ die "Unsupported scalar tag '$tag'" if (not defined $tag_subs->{ $tag });
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Cfn::YAML::Schema::tag_subs->{$tag} 1 91 92
48 91 return $tag_subs->{ $tag }->($event->{ value });
49 13 } ]
50 );
51  
52 $schema->add_sequence_resolver(
53 tag => qr/^!.*/,
54 on_create => sub {
55 51 ▶ my ($constructor, $event) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
56 51 my $tag = $event->{ tag };
57 51 $tag =~ s/^!//;
58 51 ▶ die "Unsupported sequence tag '$event->{ tag }'" if (not defined $sequence_tags->{ $tag });
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Cfn::YAML::Schema::sequence_tags->{$tag} 1 50 51
59 50 return { "Fn::$tag" => [ ] };
60 },
61 on_data => sub {
62 50 ▶ my ($constructor, $ref, $items) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
63 50 my $struct = $$ref;
64 50 my $key = [ keys %$struct ]->[ 0 ];
65 50 push @{ $struct->{ $key } }, @$items;
66 },
67 13 );
68  
69 $schema->add_mapping_resolver(
70 tag => qr/^!.*/,
71 on_create => sub {
72 3 ▶ my ($constructor, $event) = @_;
Subroutine __ANON__: called CC=2 SCAR=6.9
73 3 my $tag = $event->{ tag };
74 3 $tag =~ s/^!//;
75 3 ▶ die "Unsupported mapping tag '$event->{ tag }'" if (not defined $mapping_tags->{ $tag });
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Cfn::YAML::Schema::mapping_tags->{$tag} 1 2 3
76 2 return { "Fn::$tag" => { } };
77 },
78 on_data => sub {
79 2 ▶ my ($constructor, $ref, $items) = @_;
Subroutine __ANON__: called CC=1 SCAR=0.0
80 2 my $struct = $$ref;
81 2 my $key = [ keys %$struct ]->[ 0 ];
82 2 $struct->{ $key } = { @$items };
83 }
84 13 );
85
86 $schema->add_representer(
87 class_equals => 'Cfn',
88 code => sub {
89 0 ▶ my ($representer, $node) = @_;
Subroutine __ANON__: not called CC=9 SCAR=45.0
90 0 my $self = $node->{ value };
91 $node->{ data } = {
92 (defined $self->AWSTemplateFormatVersion)?(AWSTemplateFormatVersion => $self->AWSTemplateFormatVersion):(),
93 (defined $self->Description)?(Description => $self->Description):(),
94 (defined $self->Transform) ? (Transform => $self->Transform) : (),
95 0 ▶ (defined $self->Mappings)?(Mappings => { map { ($_ => $self->Mappings->{ $_ }->Value) } keys %{ $self->Mappings } }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Parameters ? : 0 0 0
96 0 ▶ (defined $self->Parameters)?(Parameters => { map { ($_ => $self->Parameters->{ $_ }->Value) } keys %{ $self->Parameters } }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Outputs ? : 0 0 0
97 0 ▶ (defined $self->Outputs)?(Outputs => { map { ($_ => $self->Outputs->{ $_ }->Value) } keys %{ $self->Outputs } }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Conditions ? : 0 0 0
98 0 ▶ (defined $self->Conditions)?(Conditions => { map { ($_ => $self->Condition($_)->Value) } $self->ConditionList }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Metadata ? : 0 0 0
99 0 (defined $self->Metadata)?(Metadata => { map { ($_ => $self->Metadata->{ $_ }->Value) } $self->MetadataList }):(),
100 0 ▶ Resources => { map { ($_ => $self->Resource($_)) } $self->ResourceList },
Branch: 4 branches
BranchTrueFalseTotal
defined $self->AWSTemplateFormatVersion ? : 0 0 0
defined $self->Description ? : 0 0 0
defined $self->Transform ? : 0 0 0
defined $self->Mappings ? : 0 0 0
101 };
102 0 return 1;
103 },
104 13 );
105
106 $schema->add_representer(
107 class_equals => 'Cfn::DynamicValue',
108 0 ▶ code => sub { die "Implement me" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
109 13 );
110
111 $schema->add_representer(
112 class_equals => 'Cfn::Value::TypedValue',
113 0 ▶ code => sub { die "Implement me" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
114 13 );
115
116 $schema->add_representer(
117 class_matches => 1,
118 code => sub {
119 0 ▶ my ($representer, $node) = @_;
Subroutine __ANON__: not called CC=8 SCAR=42.8
120 0 my $value = $node->{ value };
121 0 ▶ if ($value->isa('Cfn::Resource')) {
Branch: 5 branches
BranchTrueFalseTotal
if ($value->isa('Cfn::Resource')) { } 0 0 0
elsif ($value->isa('Cfn::Resource::Properties')) { } 0 0 0
elsif ($value->isa('Cfn::Value::Function::Ref')) { } 0 0 0
elsif ($value->isa('Cfn::Value::Function')) { } 0 0 0
elsif ($value->isa('Cfn::Value')) { } 0 0 0
122 0 my $self = $value;
123 $node->{ data } = {
124 (defined $self->Properties) ? (Properties => $self->Properties) : (),
125 0 (map { $_ => $self->$_->Value }
126 0 grep { defined $self->$_ } qw/Metadata UpdatePolicy/),
127 0 (map { $_ => $self->$_ }
128 0 ▶ grep { defined $self->$_ } qw/Type DeletionPolicy DependsOn CreationPolicy Condition/),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Properties ? : 0 0 0
129 };
130 0 return 1;
131 } elsif ($value->isa('Cfn::Resource::Properties')) {
132 0 my $self = $value;
133 0 ▶ $node->{ data } = { map { my $name = $_->name; (defined $self->$name)?($name => $self->$name):() } $self->meta->get_all_attributes };
Branch: 1 branch
BranchTrueFalseTotal
defined $self->$name ? : 0 0 0
134 0 return 1;
135 } elsif ($value->isa('Cfn::Value::Function::Ref')) {
136 #$node->{ tag } = '!Ref';
137 0 $node->{ data } = { 'Ref' => $value->LogicalId };
138 } elsif ($value->isa('Cfn::Value::Function')) {
139 0 my $value = $node->{ value };
140 #$node->{ tag } = sprintf '!%s', $value->Function;
141 0 $node->{ data } = { $value->Function => $value->Value->Value };
142 0 return 1;
143 } elsif ($value->isa('Cfn::Value')) {
144 0 $node->{ data } = $value->Value;
145 0 return 1;
146 } else {
147 0 die "Don't know how to serialize a $value";
148 }
149 }
150 13 );
151 }
152 2 1;
↑ Summary Cfn/Diff.pm »