CCfn.pm

filter: Statementstmt 84.7% 117 / 138 Branchbran 62.5% 15 / 24 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 86.6% 26 / 30 Podpod 0.0% 0 / 6 totaltotal 79.1% 159 / 201 CC 18 SCAR 13.8
CC
18
Cov
81%
BUILD
10.7
add_to_stash
6.0
get_deployer
6.0
CRAP 4.0
« Imager/CommandLine/Vagrant.pm ↑ Summary CloudDeploy/AMIDB.pm »
1 15 package CCfn {
2 15 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 extends 'Cfn';
4  
5 15 ▶ use Cfn;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶ use CCfnX::DynamicValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 has stash => (
9 is => 'ro',
10 isa => 'HashRef',
11 27 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 15 );
13  
14 # Holds the mappings from logical output name, to the output name that will be sent and retrieved from cloudformation
15 # This is done to support characters in the output names that cloudformation doesn't
16 has output_mappings => (
17 is => 'rw',
18 isa => 'HashRef[Str]',
19 27 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
20 15 );
21 27 ▶ has debug => (is => 'ro', default => sub { return $ENV{ CLOUDDEPLOY_DEBUG } ? 1 : 0 });
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'CLOUDDEPLOY_DEBUG'} ? : 0 27 27
22  
23 # Helper to safely add things to stash
24 0 ▶ sub add_to_stash {
Subroutine add_to_stash: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my ($self, $name, $value) = @_;
26 0 ▶ die "An element is already in the stash with name $name" if (exists $self->stash->{$name});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->stash->{$name} 0 0 0
27 0 $self->stash->{ $name } = $value;
28 }
29  
30 # Small helper to map a Moose class (parameters have a type) to a CloudFormation type
31 4 ▶ sub _moose_to_cfn_class {
Subroutine _moose_to_cfn_class: called CC=2 SCAR=7.6
32 return {
33 Str => 'String',
34 Int => 'Number',
35 Num => 'Number',
36 4 ▶ }->{ $_[0] } || 'String';
Condition50%1/2
{'Str', 'String', 'Int', 'Number', 'Num', 'Number'}->{$_[0]} || 'String'
l!l
04
MC/DC0%0/1
{'Str', 'String', 'Int', 'Number', 'Num', 'Number'}->{$_[0]} || 'String'
{'Str', 'String', 'Int', 'Number', 'Num', 'Number'}->{$_[0]}
Truth table50%1/2
A
A= {'Str', 'String', 'Int', 'Number', 'Num', 'Number'}->{$_[0]}
Aresult
11
00
37 }
38  
39 # When the object is instanced, we want any of the attributes declared in the class to be created
40 # That means that attributes with Resource, Output, Condition or Output roles are "attached" to the object
41 # This is done to make the newly created object represent all that the user has declared "in the class" when
42 # they call ->new
43 # All these attributes are normally created with CCfnX::Shortcuts, but can really be created by hand (not recommended)
44 27 ▶ sub BUILD {
Subroutine BUILD: called CC=10 SCAR=23.7
Pod undocumented
45 27 my $self = shift;
46 27 my $class_meta = $self->meta;
47 27 my @attrs = $class_meta->get_all_attributes;
48 27 foreach my $att (@attrs) {
49 517 my $name = $att->name;
50 517 ▶ if ($att->does('CCfnX::Meta::Attribute::Trait::Resource')) {
Branch: 6 branches
BranchTrueFalseTotal
if ($att->does('CCfnX::Meta::Attribute::Trait::Resource')) { } 75 442 517
elsif ($att->does('CCfnX::Meta::Attribute::Trait::Output')) { } 4 438 442
elsif ($att->does('CCfnX::Meta::Attribute::Trait::Condition')) { } 0 438 438
elsif ($att->does('CCfnX::Meta::Attribute::Trait::Mapping')) { } 0 438 438
elsif ($att->does('CCfnX::Meta::Attribute::Trait::Metadata')) { } 4 434 438
elsif ($att->does('CCfnX::Meta::Attribute::Trait::Transform')) { } 0 434 434
51 75 $self->addResource($name, $self->$name);
52 } elsif ($att->does('CCfnX::Meta::Attribute::Trait::Output')){
53 4 $self->addOutput($name, $self->$name);
54 } elsif ($att->does('CCfnX::Meta::Attribute::Trait::Condition')){
55 0 $self->addCondition($name, $self->$name);
56 } elsif ($att->does('CCfnX::Meta::Attribute::Trait::Mapping')){
57 0 $self->addMapping($name, $self->$name);
58 } elsif ($att->does('CCfnX::Meta::Attribute::Trait::Metadata')){
59 4 $self->addMetadata($name, $self->$name);
60 } elsif ($att->does('CCfnX::Meta::Attribute::Trait::Transform')){
61 0 $self->addTransform($name, $self->$name);
62 }
63 }
64  
65 27 my $params_meta = $self->params->meta;
66 27 @attrs = $params_meta->get_all_attributes;
67 27 foreach my $param (@attrs) {
68 255 ▶ if ($param->does('CCfnX::Meta::Attribute::Trait::StackParameter')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->does("CCfnX::Meta::Attribute::Trait::StackParameter")) 4 251 255
69 4 my $type = $param->type_constraint->name;
70 4 $self->addParameter($param->name, _moose_to_cfn_class($type));
71 }
72 }
73  
74 }
75  
76 0 ▶ sub get_stackversion_from_metadata {
Subroutine get_stackversion_from_metadata: not called CC=1 SCAR=6.9
Pod undocumented
77 0 my $self = shift;
78 0 $self->Metadata('StackVersion');
79 }
80  
81 19 ▶ before as_hashref => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
82 19 my $self = shift;
83 # This triggers any actions that the class
84 # wants to do while building the cloudformation
85 19 $self->build();
86 15 };
87  
88 8 ▶ around addOutput => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
89 8 my ($orig, $self, $name, $output, @rest) = @_;
90 8 my $new_name = $name;
91 8 $new_name =~ s/\W//g;
92 8 ▶ if (defined $self->Output($new_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->Output($new_name)) 0 8 8
93 0 die "The output name clashed with an existing output name. Be aware that outputs are stripped of all non-alphanumeric chars before being declared";
94 }
95 8 ▶ if ($new_name ne $name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_name ne $name) 1 7 8
96 1 $self->output_mappings->{ $new_name } = $name;
97 }
98 8 $self->$orig($new_name, $output, @rest);
99 15 };
100  
101 15 ▶ use Data::Graph::Util qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
102  
103 2 ▶ sub _creation_order {
Subroutine _creation_order: called CC=2 SCAR=6.9
104 2 my ($self) = @_;
105  
106 2 my $graph = {};
107 2 foreach my $resource ($self->ResourceList) {
108 20 $graph->{ $resource } = $self->Resource($resource)->dependencies;
109 }
110  
111 2 my @result = Data::Graph::Util::toposort($graph, [ sort $self->ResourceList ]);
112  
113 2 return reverse @result;
114 }
115  
116 19 ▶ sub build {}
Subroutine build: called CC=1 SCAR=0.0
Pod undocumented
117  
118 15 ▶ use Module::Runtime qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 0 ▶ sub get_deployer {
Subroutine get_deployer: not called CC=2 SCAR=17.9
Pod undocumented
120 0 my ($self, $params, @roles) = @_;
121 0 Module::Runtime::require_module($_) for ('CCfnX::Deployment', @roles);
122 0 my $dep = CCfnX::Deployment->new_with_roles({ %$params, origin => $self }, @roles);
123 0 return $dep;
124 }
125 }
126  
127 15 package CCfnX::Meta::Attribute::Trait::RefValue {
128 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 15 Moose::Util::meta_attribute_alias('RefValue');
130 }
131  
132 15 package CCfnX::Meta::Attribute::Trait::StackParameter {
133 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
134 15 Moose::Util::meta_attribute_alias('StackParameter');
135 }
136  
137 15 package CCfnX::Meta::Attribute::Trait::Resource {
138 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
139 15 Moose::Util::meta_attribute_alias('Resource');
140 }
141  
142 15 package CCfnX::Meta::Attribute::Trait::Metadata {
143 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
144 15 Moose::Util::meta_attribute_alias('Metadata');
145 }
146  
147 15 package CCfnX::Meta::Attribute::Trait::Condition {
148 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
149 15 Moose::Util::meta_attribute_alias('Condition');
150 }
151  
152 15 package CCfnX::Meta::Attribute::Trait::Output {
153 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
154 15 Moose::Util::meta_attribute_alias('Output');
155 }
156  
157 15 package CCfnX::Meta::Attribute::Trait::Mapping {
158 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 15 Moose::Util::meta_attribute_alias('Mapping');
160 }
161  
162 15 package CCfnX::Meta::Attribute::Trait::Transform {
163 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
164 15 Moose::Util::meta_attribute_alias('Transform');
165 }
166  
167 15 package CCfnX::Meta::Attribute::Trait::PostOutput {
168 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
169 15 Moose::Util::meta_attribute_alias('PostOutput');
170 }
171  
172 15 package CCfnX::Meta::Attribute::Trait::Attached {
173 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
174 15 Moose::Util::meta_attribute_alias('Attached');
175 }
176  
177 15 package CCfnX::Meta::Attribute::Trait::Attachable {
178 15 ▶ use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
179 15 ▶ use CCfnX::Deployment;
Subroutine BEGIN: called CC=1 SCAR=0.0
180 15 Moose::Util::meta_attribute_alias('Attachable');
181 15 has type => (is => 'ro', isa => 'Str', required => 1);
182 15 has generates_params => (is => 'ro', isa => 'ArrayRef[Str]', required => 1);
183  
184 0 ▶ sub get_info {
Subroutine get_info: not called CC=2 SCAR=17.9
Pod undocumented
185 0 my ($self, $name, $key) = @_;
186 0 ▶ die "Please specify a name for Attachment " . $self->name if (not defined $name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
187 0 my $dep = CCfnX::Deployment->new_with_roles({ name => $name }, 'CCfnX::CloudFormationDeployer', 'CCfnX::PersistentDeployment');
188 0 $dep->get_from_mongo;
189  
190 0 my $output;
191 0 eval { $output = $dep->output($key) };
192
193 0 return $output;
194 }
195 }
196  
197 15 1;
« Imager/CommandLine/Vagrant.pm ↑ Summary CloudDeploy/AMIDB.pm »