Cfn/YAML/Schema.pm

filter: Statementstmt 89.3% 84 / 94 Branchbran 72.2% 26 / 36 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 18 / 21 Podpod 0.0% 0 / 2 totaltotal 83.6% 128 / 153 CC 19 SCAR 17.1
CC
19
Cov
85%
__ANON__
13.4
__ANON__
8.1
new
2.0
CRAP 5.6
« Cfn/Crawler.pm ↑ Summary Cfn/Resource/AWS/Batch/JobDefinition.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 0 ▶ sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
7 0 my ($class, %args) = @_;
8 0 my $self = bless {}, $class;
9 0 return $self;
10 }
11  
12 our $tag_subs = {
13 18 ▶ '!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 3 ▶ '!Sub' => sub { { 'Fn::Sub' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 1 ▶ '!GetAZs' => sub { { 'Fn::GetAZs' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
18 2 ▶ '!ImportValue' => sub { { 'Fn::ImportValue' => $_[0] } },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 1 ▶ '!GetAtt' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 1 my $value = shift;
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 5 ▶ sub register {
Subroutine register: called CC=1 SCAR=0.0
Pod undocumented
38 5 my ($self, %args) = @_;
39 5 my $schema = $args{schema};
40  
41 $schema->add_resolver(
42 tag => qr/^!.*/,
43 implicit => 0,
44 30 ▶ match => [ regex => qr{^(.*)$} => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
45 30 my ($self, $event) = @_;
46 30 my $tag = $event->{ tag };
47 30 ▶ die "Unsupported scalar tag '$tag'" if (not defined $tag_subs->{ $tag });
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Cfn::YAML::Schema::tag_subs->{$tag} 1 29 30
48 29 return $tag_subs->{ $tag }->($event->{ value });
49 5 } ]
50 );
51  
52 $schema->add_sequence_resolver(
53 tag => qr/^!.*/,
54 27 ▶ on_create => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
55 27 my ($constructor, $event) = @_;
56 27 my $tag = $event->{ tag };
57 27 $tag =~ s/^!//;
58 27 ▶ 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 26 27
59 26 return { "Fn::$tag" => [ ] };
60 },
61 26 ▶ on_data => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
62 26 my ($constructor, $ref, $items) = @_;
63 26 my $struct = $$ref;
64 26 my $key = [ keys %$struct ]->[ 0 ];
65 26 push @{ $struct->{ $key } }, @$items;
66 },
67 5 );
68  
69 $schema->add_mapping_resolver(
70 tag => qr/^!.*/,
71 2 ▶ on_create => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
72 2 my ($constructor, $event) = @_;
73 2 my $tag = $event->{ tag };
74 2 $tag =~ s/^!//;
75 2 ▶ 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 1 2
76 1 return { "Fn::$tag" => { } };
77 },
78 1 ▶ on_data => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
79 1 my ($constructor, $ref, $items) = @_;
80 1 my $struct = $$ref;
81 1 my $key = [ keys %$struct ]->[ 0 ];
82 1 $struct->{ $key } = { @$items };
83 }
84 5 );
85
86 $schema->add_representer(
87 class_equals => 'Cfn',
88 2 ▶ code => sub {
Subroutine __ANON__: called CC=9 SCAR=26.0
89 2 my ($representer, $node) = @_;
90 2 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 1 ▶ (defined $self->Mappings)?(Mappings => { map { ($_ => $self->Mappings->{ $_ }->Value) } keys %{ $self->Mappings } }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Parameters ? : 1 0 1
96 0 ▶ (defined $self->Parameters)?(Parameters => { map { ($_ => $self->Parameters->{ $_ }->Value) } keys %{ $self->Parameters } }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Outputs ? : 1 0 1
97 0 ▶ (defined $self->Outputs)?(Outputs => { map { ($_ => $self->Outputs->{ $_ }->Value) } keys %{ $self->Outputs } }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Conditions ? : 1 0 1
98 1 ▶ (defined $self->Conditions)?(Conditions => { map { ($_ => $self->Condition($_)->Value) } $self->ConditionList }):(),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Metadata ? : 1 0 1
99 0 (defined $self->Metadata)?(Metadata => { map { ($_ => $self->Metadata->{ $_ }->Value) } $self->MetadataList }):(),
100 2 ▶ Resources => { map { ($_ => $self->Resource($_)) } $self->ResourceList },
Branch: 4 branches
BranchTrueFalseTotal
defined $self->AWSTemplateFormatVersion ? : 2 0 2
defined $self->Description ? : 0 2 2
defined $self->Transform ? : 0 2 2
defined $self->Mappings ? : 2 0 2
101 };
102 1 return 1;
103 },
104 5 );
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 5 );
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 5 );
115
116 $schema->add_representer(
117 class_matches => 1,
118 10 ▶ code => sub {
Subroutine __ANON__: called CC=8 SCAR=20.9
119 10 my ($representer, $node) = @_;
120 10 my $value = $node->{ value };
121 10 ▶ if ($value->isa('Cfn::Resource')) {
Branch: 5 branches
BranchTrueFalseTotal
if ($value->isa('Cfn::Resource')) { } 1 9 10
elsif ($value->isa('Cfn::Resource::Properties')) { } 1 8 9
elsif ($value->isa('Cfn::Value::Function::Ref')) { } 2 6 8
elsif ($value->isa('Cfn::Value::Function')) { } 3 3 6
elsif ($value->isa('Cfn::Value')) { } 3 0 3
122 1 my $self = $value;
123 $node->{ data } = {
124 (defined $self->Properties) ? (Properties => $self->Properties) : (),
125 0 (map { $_ => $self->$_->Value }
126 2 grep { defined $self->$_ } qw/Metadata UpdatePolicy/),
127 1 (map { $_ => $self->$_ }
128 1 ▶ grep { defined $self->$_ } qw/Type DeletionPolicy DependsOn CreationPolicy Condition/),
Branch: 1 branch
BranchTrueFalseTotal
defined $self->Properties ? : 1 0 1
129 };
130 1 return 1;
131 } elsif ($value->isa('Cfn::Resource::Properties')) {
132 1 my $self = $value;
133 1 ▶ $node->{ data } = { map { my $name = $_->name; (defined $self->$name)?($name => $self->$name):() } $self->meta->get_all_attributes };
Branch: 1 branch
BranchTrueFalseTotal
defined $self->$name ? : 2 4 6
134 1 return 1;
135 } elsif ($value->isa('Cfn::Value::Function::Ref')) {
136 #$node->{ tag } = '!Ref';
137 2 $node->{ data } = { 'Ref' => $value->LogicalId };
138 } elsif ($value->isa('Cfn::Value::Function')) {
139 3 my $value = $node->{ value };
140 #$node->{ tag } = sprintf '!%s', $value->Function;
141 3 $node->{ data } = { $value->Function => $value->Value->Value };
142 3 return 1;
143 } elsif ($value->isa('Cfn::Value')) {
144 3 $node->{ data } = $value->Value;
145 3 return 1;
146 } else {
147 0 die "Don't know how to serialize a $value";
148 }
149 }
150 5 );
151 }
152 2 1;
« Cfn/Crawler.pm ↑ Summary Cfn/Resource/AWS/Batch/JobDefinition.pm »