CCfnX/Attachments.pm

filter: Statementstmt 81.8% 18 / 22 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 2 / 3 Podpod 0.0% 0 / 1 totaltotal 75.0% 24 / 32 CC 5 SCAR 14.6
CC
5
Cov
79%
attachment
5.4
__ANON__
2.0
BEGIN
1.0
CRAP 4.3
« CloudDeploy/DeploymentCollection.pm ↑ Summary CCfnX/InstanceRoot.pm »
1 package CCfnX::Attachments;
2 2 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 Moose::Exporter->setup_import_methods(
5 with_meta => [ 'attachment' ],
6 );
7  
8 3 ▶sub attachment {
Subroutine attachment: called CC=5 SCAR=16.9
Pod undocumented
9 3 ▶ Moose->throw_error(
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 3 3
10 'Usage: attachment \'name\' => (type => \'Type\', documentation => \'\',' .
11 ' provides => { param => key_from_attachment, ... })'
12 ) if (@_ < 2);
13 3 my ( $meta, $name, %options ) = @_;
14  
15 # Add the attachment
16 $meta->add_attribute(
17 $name,
18 is => 'rw',
19 isa => 'Str',
20 type => $options{ type },
21 traits => [ 'Attachable' ],
22 3 generates_params => [ keys %{ $options{provides} } ],
23 );
24  
25 # Every attachment will declare that it provides some extra parameters in the provides
26 # these will be converted in attributes. If they start with "-", then they will not be
27 # StackParameters, that is they will not be accessible in CF via a Ref.
28 3 foreach my $attribute (keys %{ $options{ provides } }){
29 6 my $lookup_in_attachment = $options{ provides }->{$attribute};
30  
31 6 ▶ if ($meta->find_attribute_by_name($attribute)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->find_attribute_by_name($attribute)) 1 5 6
32 1 Moose->throw_error("An attribute with name $attribute already exists");
33 }
34  
35 5 my @extra_traits = ();
36 5 ▶ if (substr($attribute,0,1) eq '-'){
Branch: 1 branch
BranchTrueFalseTotal
if (substr($attribute, 0, 1) eq '-') { } 0 5 5
37 # Strip off the '-' in the attribute name
38 0 substr($attribute,0,1) = '';
39 } else {
40 5 push @extra_traits, 'StackParameter';
41 }
42  
43 $meta->add_attribute(
44 $attribute,
45 is => 'rw',
46 isa => 'Any',
47 lazy => 1,
48 traits => [ 'NoGetopt', 'Attached', @extra_traits ],
49 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
50 0 my $params = $_[0];
51 0 my $param = $params->meta->find_attribute_by_name($name);
52 0 return $param->get_info($params->$name, $lookup_in_attachment)
53 },
54 5 );
55 }
56 }
57  
58 2 1;
« CloudDeploy/DeploymentCollection.pm ↑ Summary CCfnX/InstanceRoot.pm »