| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 43 | 8 | ▶ | if (ref($self->text) eq 'ARRAY'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not ref $_ or ref $_ eq "HASH"
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"
| |||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||