| 1 | 1 | package CCfnX::CreateAMIUserData { | |||||||||
| 2 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | extends 'CCfnX::UserData'; | |||||||||
| 4 | 1 | ▶ | use autodie; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | has '+text' => (lazy => 1, | ||||||||||
| 7 | 0 | ▶ | default => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 8 | 0 | my $self = shift; | |||||||||
| 9 | 0 | ▶ | die "No files defined for generating UserData" unless defined $self->files; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 10 | 0 | return [ map { $self->file_to_lines($_) } @{ $self->files } ] | |||||||||
| 11 | 1 | }); | |||||||||
| 12 | 1 | has files => (is => 'ro', required => 1, isa => 'ArrayRef[Str]'); | |||||||||
| 13 | 1 | has signal => (is => 'ro', isa => 'Bool', default => 1); | |||||||||
| 14 | 1 | has os_family => (is => 'ro', isa => 'Str', default => 'linux'); | |||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub file_to_lines { | ||||||||
|
Subroutine
file_to_lines: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 17 | 0 | my ($self, $file) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 0 | open my $fh, '<', $file; | |||||||||
| 20 | 0 | my @lines = (); | |||||||||
| 21 | 0 | ▶ | while (my $line = <$fh>) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | push @lines, $self->parse_line($line); | |||||||||
| 23 | } | ||||||||||
| 24 | 0 | close $fh; | |||||||||
| 25 | |||||||||||
| 26 | 0 | return @lines; | |||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | around get_lines => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 30 | 0 | my ($orig, $self) = @_; | |||||||||
| 31 | 0 | my $lines = [ @{ $self->text } ]; | |||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | if ($self->os_family eq 'linux') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | ▶ | if ($self->signal) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 0 | push @$lines, $self->parse_line(qq|cfn-signal -e 0 -r "cfn-int setup complete" '#-#WaitHandle#-#'\n|); | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | else{ | ||||||||||
| 39 | 0 | unshift @$lines, "<powershell>\n"; | |||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | if ($self->signal) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 0 | push @$lines, { "Fn::Join" => [ " ", [ "& cfn-signal.exe -e 0", { "Fn::Base64" => { "Ref" => "WaitHandle" } } ] ] }; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | push @$lines, "\n</powershell>"; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | return $lines; | |||||||||
| 49 | 1 | }; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | 1; | |||||||||