AWS.pm

filter: Statementstmt 38.3% 33 / 86 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 23 Subroutinesub 66.6% 10 / 15 Podpod 0.0% 0 / 4 totaltotal 22.5% 43 / 191 CC 28 SCAR 52.3
CC
28
Cov
22%
check_result
380.0
command
72.0
profile
6.0
CRAP 186.5
« FargateStack/Builder/Events.pm ↑ Summary FargateStack/Builder/Autoscaling.pm »
1 package App::AWS;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use App::FargateStack::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use List::Util qw(none);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 __PACKAGE__->follow_best_practice();
19 1 __PACKAGE__->mk_accessors(qw(_service_name));
20  
21 ########################################################################
22 0 ▶sub profile {
Subroutine profile: not called CC=2 SCAR=17.9
Pod undocumented
23 ########################################################################
24 0 my ($self) = @_;
25  
26 0 ▶ return $self->get_profile // $ENV{AWS_PROFILE};
Condition0%0/3
$self->get_profile // $ENV{"AWS_PROFILE"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_profile // $ENV{"AWS_PROFILE"}
$self->get_profile $ENV{"AWS_PROFILE"}
Truth table0%0/3
A // B
A= $self->get_profileB= $ENV{"AWS_PROFILE"}
ABresult
1X1
011
000
27 }
28  
29 ########################################################################
30 0 ▶sub region {
Subroutine region: not called CC=2 SCAR=17.9
Pod undocumented
31 ########################################################################
32 0 my ($self) = @_;
33  
34 0 ▶ return $self->get_region // 'us-east-1';
Condition0%0/2
$self->get_region // "us-east-1"
l!l
00
MC/DC0%0/1
$self->get_region // "us-east-1"
$self->get_region
Truth table0%0/2
A
A= $self->get_region
Aresult
11
00
35 }
36  
37 ########################################################################
38 0 ▶sub command {
Subroutine command: not called CC=8 SCAR=42.8
Pod undocumented
39 ########################################################################
40 0 my ( $self, $command, $extra ) = @_;
41  
42 0 my $service = $self->get__service_name;
43  
44 0 ▶ if ( !$service ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($service) 0 0 0
45 0 ($service) = ref($self) =~ /App::(.*)$/xsm;
46 0 $service = lc $service;
47 }
48  
49 0 my @cmd = ( 'aws', $service, $command );
50  
51 my @args = (
52 '--profile' => $self->profile,
53 '--region' => $self->region,
54 0 ▶ @{ $extra || [] },
Condition0%0/2
$extra || []
l!l
00
MC/DC0%0/1
$extra || []
$extra
Truth table0%0/2
A
A= $extra
Aresult
11
00
55 );
56  
57 0 my $result = $self->execute( @cmd, @args );
58  
59 0 ▶ $self->get_logger->trace( sub { return Dumper( [ result => $result ] ); } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
60  
61 return
62 0 ▶ if !$result;
Branch: 1 branch
BranchTrueFalseTotal
unless $result 0 0 0
63  
64 0 chomp $result;
65  
66 0 my $obj = eval {
67 0 ▶ return $result
Branch: 1 branch
BranchTrueFalseTotal
if join("", @args) =~ /outputtext/msx 0 0 0
68 if join( q{}, @args ) =~ /outputtext/xsm;
69  
70 0 return JSON->new->utf8->decode($result);
71 };
72  
73 0 ▶ if ( !$obj || $EVAL_ERROR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $obj or $App::AWS::EVAL_ERROR) 0 0 0
Condition0%0/3
not $obj or $App::AWS::EVAL_ERROR
l!l&&r!l&&!r
000
MC/DC0%0/2
not $obj or $App::AWS::EVAL_ERROR
not $obj $App::AWS::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not $objB= $App::AWS::EVAL_ERROR
ABresult
1X1
011
000
74 0 $self->get_logger->error($EVAL_ERROR);
75 0 $self->get_logger->error( join q{ }, @cmd, @args );
76 }
77  
78 0 ▶ return $obj ? $obj : $result;
Branch: 1 branch
BranchTrueFalseTotal
$obj ? : 0 0 0
79 }
80  
81 ########################################################################
82 0 ▶sub check_result {
Subroutine check_result: not called CC=19 SCAR=59.4
Pod undocumented
83 ########################################################################
84 0 my ( $self, @options ) = @_;
85  
86 # unpack args
87 # check_result({ message => '', params => [] });
88 # check_result( message => '', params => []);
89 # check_result( message => '', single-param);
90 # check_result( { message => '' }, multiple-params);
91  
92 0 my $args;
93  
94 0 ▶ if ( @options == 1 || ref $options[0] ) {
Branch: 2 branches
BranchTrueFalseTotal
if (@options == 1 or ref $options[0]) { } 0 0 0
elsif (@options % 2) { } 0 0 0
Condition0%0/3
@options == 1 or ref $options[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
@options == 1 or ref $options[0]
@options == 1 ref $options[0]
Truth table0%0/3
A or B
A= @options == 1B= ref $options[0]
ABresult
1X1
011
000
95 0 $args = shift @options;
96 0 ▶ $args->{params} //= [@options];
Condition0%0/2
$args->{"params"} //= [@options]
l!l
00
MC/DC0%0/1
$args->{"params"} //= [@options]
$args->{"params"}
Truth table0%0/2
A
A= $args->{"params"}
Aresult
11
00
97 }
98 elsif ( @options % 2 ) {
99 0 my $param = pop @options;
100 0 $args = {@options};
101 0 $args->{params} = [$param];
102 }
103 else {
104 0 $args = {@options};
105 }
106  
107 0 ▶ my $msg = $args->{message} // 'Operation failed';
Condition0%0/2
$args->{"message"} // "Operation failed"
l!l
00
MC/DC0%0/1
$args->{"message"} // "Operation failed"
$args->{"message"}
Truth table0%0/2
A
A= $args->{"message"}
Aresult
11
00
108 0 ▶ my $params = $args->{params} || [];
Condition0%0/2
$args->{'params'} || []
l!l
00
MC/DC0%0/1
$args->{'params'} || []
$args->{'params'}
Truth table0%0/2
A
A= $args->{'params'}
Aresult
11
00
109 0 my $regexp = $args->{regexp};
110 0 ▶ my $warn = $args->{warn} // $FALSE;
Condition0%0/3
$args->{"warn"} // $App::AWS::FALSE
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"warn"} // $App::AWS::FALSE
$args->{"warn"} $App::AWS::FALSE
Truth table0%0/3
A // B
A= $args->{"warn"}B= $App::AWS::FALSE
ABresult
1X1
011
000
111  
112 0 ▶ my $croak = $args->{croak} // $TRUE;
Condition0%0/3
$args->{"croak"} // $App::AWS::TRUE
l!l&&r!l&&!r
000
MC/DC0%0/2
$args->{"croak"} // $App::AWS::TRUE
$args->{"croak"} $App::AWS::TRUE
Truth table0%0/3
A // B
A= $args->{"croak"}B= $App::AWS::TRUE
ABresult
1X1
011
000
113  
114 0 my $result = $self->get_last_result;
115 0 ▶ my $err = $self->get_error // q{};
Condition0%0/2
$self->get_error // ""
l!l
00
MC/DC0%0/1
$self->get_error // ""
$self->get_error
Truth table0%0/2
A
A= $self->get_error
Aresult
11
00
116  
117 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $result or not $err 0 0 0
Condition0%0/3
$result or not $err
l!l&&r!l&&!r
000
MC/DC0%0/2
$result or not $err
$result not $err
Truth table0%0/3
A or not(B)
A= $resultB= not $err
ABresult
1X1
011
000
118 if $result || !$err;
119  
120 # Accept either a qr// or a plain string for regexp
121 0 ▶ if ( defined $regexp && ref $regexp ne 'Regexp' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $regexp and ref $regexp ne "Regexp") 0 0 0
Condition0%0/3
defined $regexp and ref $regexp ne "Regexp"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $regexp and ref $regexp ne "Regexp"
defined $regexp ref $regexp ne "Regexp"
Truth table0%0/3
A and B
A= defined $regexpB= ref $regexp ne "Regexp"
ABresult
0X0
100
111
122 0 $regexp = qr/$regexp/xsm;
123 }
124  
125 0 my $base_msg = sprintf $msg, @{$params};
126 0 my $full_msg = $base_msg . "\n$err";
127  
128 0 ▶ if ( $regexp && $err && $err =~ $regexp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regexp and $err and $err =~ /$regexp/) 0 0 0
Condition0%0/6
$regexp and $err and $err =~ /$regexp/
!ll&&!rl&&r
000
$regexp and $err
!ll&&!rl&&r
000
MC/DC0%0/3
$regexp and $err and $err =~ /$regexp/
$regexp $err $err =~ /$regexp/
Truth table0%0/4
A and B and C
A= $regexpB= $errC= $err =~ /$regexp/
ABCresult
0XX0
10X0
1100
1111
129 0 ▶ if ($warn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($warn) 0 0 0
130 0 $self->get_logger->warn($full_msg);
131 }
132 0 return $FALSE;
133 }
134  
135 0 ▶ croak $full_msg
Branch: 1 branch
BranchTrueFalseTotal
if $croak 0 0 0
136 if $croak;
137  
138 0 $self->log_warn($full_msg);
139  
140 0 return $FALSE;
141 }
142  
143 1 1;
« FargateStack/Builder/Events.pm ↑ Summary FargateStack/Builder/Autoscaling.pm »