File Coverage

blib/lib/CCfnX/CreateAMIUserData.pm
Criterion Covered Total %
statement 6 13 46.1
branch n/a
condition n/a
subroutine 2 3 66.6
pod 0 1 0.0
total 8 17 47.0


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