CCfnX/UserData.pm

filter: Statementstmt 89.1% 41 / 46 Branchbran 77.7% 14 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 84.1% 69 / 82 CC 11 SCAR 11.6
CC
11
Cov
87%
_process_tiefighter
5.0
get_lines
4.1
parse_line
3.0
CRAP 3.2
« CCfnX/DSL/Inheritance.pm ↑ Summary CCfnX/LocateAMI.pm »
1 15 package CCfnX::UserData {
2 15 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 15 ▶ use Cfn;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 15 extends 'Cfn::Value';
6  
7 15 has Value => (isa => 'Cfn::Value', coerce => 1, is => 'rw', required => 0);
8 15 has text => (is => 'ro', required => 1, isa => 'Str|ArrayRef');
9  
10 8 ▶ sub parse_line {
Subroutine parse_line: called CC=3 SCAR=11.0
Pod undocumented
11 8 my ($self, $line) = @_;
12 8 ▶ return $line if (ref($line));
Branch: 1 branch
BranchTrueFalseTotal
if ref $line 0 8 8
13 # Use a capturing group in split so that #-#...#-# is returned
14 8 my @elements = split /(\#\-\#.*?\#\-\#)/, $line;
15 @elements = map {
16 8 ▶ ($_ =~ m/^#\-\#(.*?)\#\-\#$/) ?
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /^#\-\#(.*?)\#\-\#$/ ? : 8 14 22
17 _process_tiefighter("$1") : $_
18 } @elements;
19 8 return @elements;
20 }
21  
22 15 ▶ use CCfnX::Shortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶ sub _process_tiefighter {
Subroutine _process_tiefighter: called CC=5 SCAR=16.2
24 8 my ($tfighter) = @_;
25 8 ▶ if ($tfighter =~ m/^([A-Za-z0-9:-]+?)\-\>([A-Za-z0-9.:-]+?)$/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($tfighter =~ /^([A-Za-z0-9:-]+?)\-\>([A-Za-z0-9.:-]+?)$/) { } 1 7 8
elsif ($tfighter =~ /^Parameter\(['"]{0,1}([A-Za-z0-9:_-]+?)['"]{0,1}\)$/) { } 3 4 7
elsif ($tfighter =~ /^Attribute\(([A-Za-z0-9.:_-]+?)\)$/) { } 3 1 4
elsif ($tfighter =~ /^([A-Za-z0-9:-]+)$/) { } 1 0 1
26 1 return { 'Fn::GetAtt' => [ "$1", "$2" ] };
27 } elsif ($tfighter =~ m/^Parameter\(['"]{0,1}([A-Za-z0-9:_-]+?)['"]{0,1}\)$/) {
28 3 my $param = "$1";
29 3 return CCfnX::Shortcuts::Parameter($param);
30 } elsif ($tfighter =~ m/^Attribute\(([A-Za-z0-9.:_-]+?)\)$/) {
31 3 my $path = "$1";
32 3 return CCfnX::Shortcuts::Attribute($path);
33 } elsif ($tfighter =~ m/^([A-Za-z0-9:-]+)$/) {
34 1 return { Ref => "$1" }
35 } else {
36 0 die "Unrecognized tiefighter syntax for $tfighter";
37 }
38 }
39  
40 8 ▶ sub get_lines {
Subroutine get_lines: called CC=3 SCAR=14.2
Pod undocumented
41 8 my $self = shift;
42 8 ▶ if (defined $self->text) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->text) { } 8 0 8
43 8 ▶ if (ref($self->text) eq 'ARRAY'){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->text eq 'ARRAY') { } 0 8 8
44 0 return [ map { $self->parse_line($_) } @{ $self->text } ];
45 } else {
46 8 return [ $self->parse_line($self->text) ];
47 }
48 } else {
49 0 die "No text for generating UserData";
50 }
51 }
52  
53 8 ▶ sub process_with_context {
Subroutine process_with_context: called CC=3 SCAR=11.0
Pod undocumented
54 8 my ($self, $ctx) = @_;
55 return [ map {
56 22 ▶ (not ref($_) or ref($_) eq 'HASH')?$_:$_->as_hashref($ctx);
Branch: 1 branch
BranchTrueFalseTotal
!ref($_) || ref $_ eq 'HASH' ? : 16 6 22
Condition100%3/3
not ref $_ or ref $_ eq "HASH"
l!l&&r!l&&!r
1426
MC/DC100%2/2
not ref $_ or ref $_ eq "HASH"
not ref $_ ref $_ eq "HASH"
Truth table100%3/3
not(A) or B
A= not ref $_B= ref $_ eq "HASH"
ABresult
1X1
011
000
57 8 } @{ $self->get_lines } ]
58 }
59  
60 8 ▶ sub as_hashref_joins {
Subroutine as_hashref_joins: called CC=1 SCAR=0.0
Pod undocumented
61 8 my $self = shift;
62 return {
63 8 'Fn::Join' => [ '', $self->process_with_context(@_) ]
64 }
65 }
66  
67 4 ▶ around as_hashref => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 4 my ($orig, $self, @rest) = @_;
69 return {
70 4 'Fn::Base64' => $self->as_hashref_joins(@rest)
71 }
72 15 };
73 }
74  
75 15 1;
« CCfnX/DSL/Inheritance.pm ↑ Summary CCfnX/LocateAMI.pm »