| 1 | package App::FargateStack::Builder::Utils; | ||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Log::Log4perl; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | # this register ths package as a wrapper class helps resolve | ||||||||||||||||||||||||||||||||||||||
| 9 | # callstack issue when covering Log4perl methods. | ||||||||||||||||||||||||||||||||||||||
| 10 | 2 | Log::Log4perl->wrapper_register(__PACKAGE__); | |||||||||||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Date::Parse qw(str2time); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use English qw(no_match_vars); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use List::Util qw(any none); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Scalar::Util qw(blessed reftype refaddr looks_like_number); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use Time::HiRes qw(time); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Text::Diff; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use Role::Tiny; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use parent qw(Exporter Class::Accessor::Fast); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||
| 30 | 2 | __PACKAGE__->follow_best_practice; | |||||||||||||||||||||||||||||||||||||
| 31 | 2 | __PACKAGE__->mk_accessors(qw(_var_pool)); | |||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||
| 33 | 2 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||
| 34 | ToCamelCase | ||||||||||||||||||||||||||||||||||||||
| 35 | choose | ||||||||||||||||||||||||||||||||||||||
| 36 | common_args | ||||||||||||||||||||||||||||||||||||||
| 37 | confirm | ||||||||||||||||||||||||||||||||||||||
| 38 | display_diffs | ||||||||||||||||||||||||||||||||||||||
| 39 | dmp | ||||||||||||||||||||||||||||||||||||||
| 40 | elapsed_time | ||||||||||||||||||||||||||||||||||||||
| 41 | jmespath_mapping | ||||||||||||||||||||||||||||||||||||||
| 42 | log_die | ||||||||||||||||||||||||||||||||||||||
| 43 | normalize_name | ||||||||||||||||||||||||||||||||||||||
| 44 | normalize_time_range | ||||||||||||||||||||||||||||||||||||||
| 45 | normalize_timestamp | ||||||||||||||||||||||||||||||||||||||
| 46 | toCamelCase | ||||||||||||||||||||||||||||||||||||||
| 47 | slurp_file | ||||||||||||||||||||||||||||||||||||||
| 48 | write_json_file | ||||||||||||||||||||||||||||||||||||||
| 49 | fetch_acm | ||||||||||||||||||||||||||||||||||||||
| 50 | fetch_cloudtrail | ||||||||||||||||||||||||||||||||||||||
| 51 | fetch_application_autoscaling | ||||||||||||||||||||||||||||||||||||||
| 52 | fetch_ecr | ||||||||||||||||||||||||||||||||||||||
| 53 | fetch_ec2 | ||||||||||||||||||||||||||||||||||||||
| 54 | fetch_ecs | ||||||||||||||||||||||||||||||||||||||
| 55 | fetch_ecr | ||||||||||||||||||||||||||||||||||||||
| 56 | fetch_elbv2 | ||||||||||||||||||||||||||||||||||||||
| 57 | fetch_events | ||||||||||||||||||||||||||||||||||||||
| 58 | fetch_efs | ||||||||||||||||||||||||||||||||||||||
| 59 | fetch_iam | ||||||||||||||||||||||||||||||||||||||
| 60 | fetch_logs | ||||||||||||||||||||||||||||||||||||||
| 61 | fetch_secrets | ||||||||||||||||||||||||||||||||||||||
| 62 | fetch_sts | ||||||||||||||||||||||||||||||||||||||
| 63 | fetch_route53 | ||||||||||||||||||||||||||||||||||||||
| 64 | fetch_cli_api | ||||||||||||||||||||||||||||||||||||||
| 65 | fetch_wafv2 | ||||||||||||||||||||||||||||||||||||||
| 66 | ); | ||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||
| 68 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub fetch_application_autoscaling { return shift->fetch_cli_api( 'Application-Autoscaling', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_application_autoscaling: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub fetch_acm { return shift->fetch_cli_api( 'ACM', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_acm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub fetch_cloudtrail { return shift->fetch_cli_api( 'CloudTrail', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_cloudtrail: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub fetch_iam { return shift->fetch_cli_api( 'IAM', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_iam: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub fetch_logs { return shift->fetch_cli_api( 'Logs', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_logs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub fetch_efs { return shift->fetch_cli_api( 'EFS', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_efs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub fetch_ecs { return shift->fetch_cli_api( 'ECS', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_ecs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub fetch_ec2 { return shift->fetch_cli_api( 'EC2', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_ec2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub fetch_ecr { return shift->fetch_cli_api( 'ECR', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_ecr: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub fetch_events { return shift->fetch_cli_api( 'Events', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_events: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | sub fetch_sts { return shift->fetch_cli_api( 'STS', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_sts: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub fetch_secrets { return shift->fetch_cli_api( 'Secrets', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_secrets: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub fetch_elbv2 { return shift->fetch_cli_api( 'ElbV2', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_elbv2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub fetch_route53 { return shift->fetch_cli_api( 'Route53', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_route53: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub fetch_wafv2 { return shift->fetch_cli_api( 'WafV2', @_ ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_wafv2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 84 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub fetch_cli_api { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_cli_api: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 86 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my ( $self, $api, %options ) = @_; | |||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $class = $self->get( lc $api ); | |||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return $class | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$class and not keys %options
MC/DC0%0/2
$class and not keys %options
$class
not keys %options
Truth table0%0/3
A and not(B)
A= $classB= not keys %options
| |||||||||||||||||||||||||||||||||||||||
| 92 | if $class && !keys %options; | ||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ( !$class ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $normalized_name = $api; | |||||||||||||||||||||||||||||||||||||
| 96 | 0 | $normalized_name =~ s/[\-]//xsm; | |||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $class_path = sprintf 'App/%s.pm', $normalized_name; | |||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | 0 | require $class_path; | |||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $class_name = sprintf 'App::%s', $normalized_name; | |||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $self->set( lc $api, $class_name->new( _service_name => lc $api, %{ $self->get_global_options }, %options ) ); | |||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $class = $self->get( lc $api ); | |||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | foreach ( keys %options ) { | |||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | next if !defined $options{$_}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $class->set( $_, $options{$_} ); | |||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $class; | |||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||
| 118 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub maybe_color { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
maybe_color: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 120 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ( $self, $color, $text ) = @_; | |||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $text | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 124 | if !$self->get_color; | ||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return colored( $text, $color ); | |||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub create_default { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
create_default: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 131 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my ( $self, $what, @args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||
| 134 | 0 | require App::FargateStack::Constants; | |||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||
| 136 | croak "no default for $what\n" | ||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if !exists $App::FargateStack::Constants::DEFAULT_NAMES{$what}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $default = $App::FargateStack::Constants::DEFAULT_NAMES{$what}; | |||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return ref $default ? $default->( $self, @args ) : $default; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||
| 144 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | sub confirm { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
confirm: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 146 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my ( $prompt, @args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||
| 149 | 0 | print sprintf "$prompt [y/N] ", @args; | |||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | chomp( my $answer = <STDIN> ); | |||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | return $answer =~ /^y(es)?$/xsmi; | |||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||
| 156 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub common_args { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
common_args: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 158 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 159 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||
| 161 | 0 | my $config = $self->get_config; | |||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | my $var_pool = { | ||||||||||||||||||||||||||||||||||||||
| 164 | config => $config, | ||||||||||||||||||||||||||||||||||||||
| 165 | cache => $self->get_cache, | ||||||||||||||||||||||||||||||||||||||
| 166 | dryrun => $self->get_dryrun, | ||||||||||||||||||||||||||||||||||||||
| 167 | # these just avoid a bunch of hash digging | ||||||||||||||||||||||||||||||||||||||
| 168 | tasks => $config->{tasks}, | ||||||||||||||||||||||||||||||||||||||
| 169 | cluster => $config->{cluster}, | ||||||||||||||||||||||||||||||||||||||
| 170 | security_groups => $config->{security_groups}, | ||||||||||||||||||||||||||||||||||||||
| 171 | route53 => $config->{route53}, | ||||||||||||||||||||||||||||||||||||||
| 172 | alb => $config->{alb}, | ||||||||||||||||||||||||||||||||||||||
| 173 | app => $config->{app}, | ||||||||||||||||||||||||||||||||||||||
| 174 | subnets => $config->{subnets}, | ||||||||||||||||||||||||||||||||||||||
| 175 | role => $config->{role}, | ||||||||||||||||||||||||||||||||||||||
| 176 | events_role => $config->{events_role}, | ||||||||||||||||||||||||||||||||||||||
| 177 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $self->set__var_pool($var_pool); | |||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | return $var_pool | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 182 | if !@args; | ||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my @invalid_args = grep { !exists $var_pool->{$_} } @args; | |||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | croak sprintf "invalid argument(s): %s\n", join q{,}, @invalid_args | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 187 | if @invalid_args; | ||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||
| 189 | 0 | return @{$var_pool}{@args}; | |||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||
| 192 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | sub display_diffs { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
display_diffs: not called CC=12 SCAR=50.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 194 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my ( $self, $old, $new, $options ) = @_; | |||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $json = JSON->new->canonical->pretty->allow_blessed->convert_blessed; | |||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $old_str = $json->encode($old); | |||||||||||||||||||||||||||||||||||||
| 200 | 0 | my $new_str = $json->encode($new); | |||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||
| 202 | # normalize line endings + ensure trailing newline (helps diff output) | ||||||||||||||||||||||||||||||||||||||
| 203 | 0 | for my $str ( $old_str, $new_str ) { | |||||||||||||||||||||||||||||||||||||
| 204 | 0 | $str =~ s/\r\n/\n/xsmg; | |||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | next if $str =~ /\n\z/xsm; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $str .= "\n"; | |||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my $style = ( $options && ref $options ) ? ( $options->{style} // 'Table' ) : 'Table'; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$options and ref $options
$options->{"style"} // "Table"
MC/DC0%0/2
$options and ref $options
$options
ref $options
MC/DC0%0/1
$options->{"style"} // "Table"
$options->{"style"}
Truth table0%0/3
A and B
A= $optionsB= ref $options
Truth table0%0/2
A
A= $options->{"style"}
| |||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | my $diffs = diff( \$old_str, \$new_str, { STYLE => $style } ) // q{}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
diff(\$old_str, \$new_str, {"STYLE", $style}) // ""
MC/DC0%0/1
diff(\$old_str, \$new_str, {"STYLE", $style}) // ""
diff(\$old_str, \$new_str, {"STYLE", $style})
Truth table0%0/2
A
A= diff(\$old_str, \$new_str, {"STYLE", $style})
| |||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | return $diffs | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$options and ref $options
MC/DC0%0/2
$options and ref $options
$options
ref $options
Truth table0%0/3
A and B
A= $optionsB= ref $options
| |||||||||||||||||||||||||||||||||||||||
| 213 | if !$options || !ref $options; | ||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | return q{} if !length $diffs; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | my $log_level = $options->{log_level} // 'error'; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"log_level"} // "error"
MC/DC0%0/1
$options->{"log_level"} // "error"
$options->{"log_level"}
Truth table0%0/2
A
A= $options->{"log_level"}
| |||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $title = $options->{title} //= 'objects differ:'; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$options->{"title"} //= "objects differ:"
MC/DC0%0/1
$options->{"title"} //= "objects differ:"
$options->{"title"}
Truth table0%0/2
A
A= $options->{"title"}
| |||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $self->get_logger->$log_level( sprintf "\t%s", $title ); | |||||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->get_logger->$log_level( sprintf "\n\t%s", $diffs ); | |||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return $diffs; | |||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||
| 226 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 227 | 5 | ▶ | sub ToCamelCase { goto &_toCamelCase; } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
ToCamelCase: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 228 | 2 | ▶ | sub toCamelCase { return _toCamelCase( $_[0], $_[1], 1 ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
toCamelCase: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 229 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 230 | 7 | ▶ | sub _toCamelCase { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_toCamelCase: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||
| 231 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 232 | 7 | my ( $snake_case, $want_hash, $lc_first ) = @_; | |||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||
| 234 | 7 | ▶ | $want_hash //= wantarray ? 0 : 1; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$want_hash //= wantarray ? 0 : 1
MC/DC100%1/1
$want_hash //= wantarray ? 0 : 1
$want_hash
Truth table100%2/2
A
A= $want_hash
| |||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||
| 236 | my @CamelCase = map { | ||||||||||||||||||||||||||||||||||||||
| 237 | 20 | ▶ | ( $want_hash ? $_ : (), join q{}, map {ucfirst} split /_/xsm ) | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 238 | 7 | } @{$snake_case}; | |||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||
| 240 | 7 | ▶ | return $want_hash ? {@CamelCase} : @CamelCase | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 241 | if !$lc_first; | ||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | return map {lcfirst} @CamelCase | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 244 | if !$want_hash; | ||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||
| 246 | 1 | my %camelCase = @CamelCase; | |||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||
| 248 | 1 | %camelCase = map { $_ => lcfirst $camelCase{$_} } keys %camelCase; | |||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||
| 250 | 1 | return \%camelCase; | |||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||
| 253 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | sub jmespath_mapping { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
jmespath_mapping: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 255 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my ( $prefix, $elems, $ucfirst ) = @_; | |||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | $ucfirst //= 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$ucfirst //= 0
MC/DC0%0/1
$ucfirst //= 0
$ucfirst
Truth table0%0/2
A
A= $ucfirst
| |||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | my $hash_list = reftype($elems) eq 'HASH' ? $elems : $ucfirst ? ToCamelCase($elems) : toCamelCase($elems); | ||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $list = sprintf '%s.%s', $prefix, encode_json $hash_list; | |||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $list =~ s/"//gxsm; | |||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||
| 265 | 0 | return $list; | |||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||
| 268 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | sub elapsed_time { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
elapsed_time: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 270 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my ($start_time) = @_; | |||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | return q{-} | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 274 | if !$start_time; | ||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||
| 276 | # Extract timestamp and offset | ||||||||||||||||||||||||||||||||||||||
| 277 | 0 | my ( $date, $time, $sign, $h_offset, $m_offset ) = $start_time =~ m{ | |||||||||||||||||||||||||||||||||||||
| 278 | ^(\d{4}-\d{2}-\d{2}) # date | ||||||||||||||||||||||||||||||||||||||
| 279 | T(\d{2}:\d{2}:\d{2}) # time | ||||||||||||||||||||||||||||||||||||||
| 280 | \.\d+ # fractional seconds | ||||||||||||||||||||||||||||||||||||||
| 281 | ([+-])(\d{2}):(\d{2})$ # offset | ||||||||||||||||||||||||||||||||||||||
| 282 | }x; | ||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||
| 284 | # Parse local time (as in the string, which is relative to its own offset) | ||||||||||||||||||||||||||||||||||||||
| 285 | 0 | my $tp = Time::Piece->strptime( "$date $time", '%Y-%m-%d %H:%M:%S' ); | |||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||
| 287 | # Calculate total offset in seconds | ||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $offset_sec = ( $h_offset * 3600 + $m_offset * 60 ) * ( $sign eq '+' ? 1 : -1 ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||
| 290 | # Convert to UTC epoch (add offset to local time to get UTC) | ||||||||||||||||||||||||||||||||||||||
| 291 | 0 | my $epoch_utc = $tp->epoch - $offset_sec; | |||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||
| 293 | # Get current UTC time | ||||||||||||||||||||||||||||||||||||||
| 294 | 0 | my $now = time; | |||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||
| 296 | # Elapsed time in seconds | ||||||||||||||||||||||||||||||||||||||
| 297 | 0 | my $elapsed = int( $now - $epoch_utc ); | |||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||
| 299 | # Break into minutes and seconds | ||||||||||||||||||||||||||||||||||||||
| 300 | 0 | my $minutes = int( $elapsed / 60 ); | |||||||||||||||||||||||||||||||||||||
| 301 | 0 | my $seconds = $elapsed % 60; | |||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||
| 303 | 0 | return sprintf '%d:%02d', $minutes, $seconds; | |||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||
| 306 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub choose (&) { return $_[0]->(); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
choose: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 308 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||
| 310 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | sub dmp { return print {*STDERR} Dumper( [@_] ); } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
dmp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 312 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||
| 314 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | sub _inc { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_inc: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 316 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 317 | 0 | my ( $what, $self, $key, $value ) = @_; | |||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | my $resources = $self->get($what) // {}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->get($what) // {}
MC/DC0%0/1
$self->get($what) // {}
$self->get($what)
Truth table0%0/2
A
A= $self->get($what)
| |||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ( ref $value && reftype($value) eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and builtin::reftype($value) eq "ARRAY"
MC/DC0%0/2
ref $value and builtin::reftype($value) eq "ARRAY"
ref $value
builtin::reftype($value) eq "ARRAY"
Truth table0%0/3
A and B
A= ref $valueB= builtin::reftype($value) eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ($value) = @{$value}; | |||||||||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $resources->{$key} //= []; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$resources->{$key} //= []
MC/DC0%0/1
$resources->{$key} //= []
$resources->{$key}
Truth table0%0/2
A
A= $resources->{$key}
| |||||||||||||||||||||||||||||||||||||||
| 324 | 0 | push @{ $resources->{$key} }, $value; | |||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||
| 326 | else { | ||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $resources->{$key} = $value; | |||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $self->set( $what, $resources ); | |||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||
| 332 | 0 | return $resources; | |||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||
| 335 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub inc_existing_resources { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
inc_existing_resources: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 337 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 338 | 0 | return _inc( 'existing_resources', @_ ); | |||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||
| 341 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | sub inc_required_resources { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
inc_required_resources: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 343 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 344 | 0 | return _inc( 'required_resources', @_ ); | |||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||
| 347 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub write_json_file { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
write_json_file: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 349 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my ( $self, $file, $obj ) = @_; | |||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | open my $fh, '>', $file | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 353 | or croak "could not open $file for writing\n"; | ||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||
| 355 | 0 | my $json = JSON->new->pretty->encode($obj); | |||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||
| 357 | 0 | print {$fh} $json; | |||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||
| 359 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return $json; | |||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||
| 364 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | sub slurp_file { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
slurp_file: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 366 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my ( $file, $json ) = @_; | |||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||
| 369 | 0 | local $RS = undef; | |||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | open my $fh, '<', $file | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 372 | or croak "could not open $file\n"; | ||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||
| 374 | 0 | my $content = <$fh>; | |||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||
| 376 | 0 | close $fh; | |||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||
| 378 | 0 | ▶ | return $json ? decode_json($content) : $content; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||
| 381 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | sub section_break { return shift->get_logger->info( q{-} x 80 ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
section_break: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 383 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||
| 385 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 386 | 0 | ▶ | sub normalize_name { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 387 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my ( $self, $name ) = @_; | |||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||
| 390 | 0 | return join q{}, map {ucfirst} split /[_-]+/xsm, $name; | |||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||
| 393 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | sub abbrev { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
abbrev: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 395 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my ( $text, $len, $offset ) = @_; | |||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | $offset //= 0; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$offset //= 0
MC/DC0%0/1
$offset //= 0
$offset
Truth table0%0/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | $text //= q{}; | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$text //= ""
MC/DC0%0/1
$text //= ""
$text
Truth table0%0/2
A
A= $text
| |||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||
| 400 | 0 | return sprintf '%s...', substr $text, $offset, $len; | |||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||
| 403 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | sub is_service_running { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
is_service_running: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 405 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my ( $self, $task_name ) = @_; | |||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my ( $config, $cluster ) = $self->common_args(qw(config cluster)); | |||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $cluster_name = $cluster->{name}; | |||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my $ecs = $self->fetch_ecs; | |||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $services = $ecs->list_services( $cluster_name, 'serviceArns' ); | |||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | croak sprintf "ERROR: could not list services for: [%s]\n%s", $cluster_name, $ecs->get_error | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 416 | if !$services; | ||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||
| 418 | return | ||||||||||||||||||||||||||||||||||||||
| 419 | 0 | ▶ | if none {/\/$task_name/xsm} @{$services}; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||
| 421 | 0 | my $status = $ecs->describe_services( | |||||||||||||||||||||||||||||||||||||
| 422 | cluster_name => $cluster_name, | ||||||||||||||||||||||||||||||||||||||
| 423 | service_name => $task_name, | ||||||||||||||||||||||||||||||||||||||
| 424 | query => 'services[0].runningCount' | ||||||||||||||||||||||||||||||||||||||
| 425 | ); | ||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | croak sprintf "ERROR: could not describe services for: [%s/%s]\n%s", $cluster_name, $task_name, $ecs->get_error | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 428 | if !defined $status; | ||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||
| 430 | 0 | return $status; | |||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||
| 433 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | sub _log { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_log: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 435 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 436 | 0 | my ( $logger, $level, @args ) = @_; | |||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||
| 438 | # If first arg looks like a sprintf format string AND we have more args, call sprintf | ||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ( @args > 1 && $args[0] =~ /%/xsm ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@args > 1 and $args[0] =~ /%/msx
MC/DC0%0/2
@args > 1 and $args[0] =~ /%/msx
@args > 1
$args[0] =~ /%/msx
Truth table0%0/3
A and B
A= @args > 1B= $args[0] =~ /%/msx
| |||||||||||||||||||||||||||||||||||||||
| 440 | 0 | return $logger->$level( sprintf shift(@args), @args ); | |||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||
| 442 | else { | ||||||||||||||||||||||||||||||||||||||
| 443 | 0 | return $logger->$level(@args); | |||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | sub log_info { return _log( shift->get_logger, 'info', @_ ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | sub log_debug { return _log( shift->get_logger, 'debug', @_ ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_debug: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | sub log_warn { return _log( shift->get_logger, 'warn', @_ ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_warn: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | sub log_error { return _log( shift->get_logger, 'error', @_ ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | sub log_die { _log( shift->get_logger, 'error', @_ ); die q{}; } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_die: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub log_trace { return _log( shift->get_logger, 'trace', @_ ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_trace: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub log_fatal { return _log( shift->get_logger, 'fatal', @_ ) } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
log_fatal: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||
| 455 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | sub normalize_timestamp { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_timestamp: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 457 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my ($ts) = @_; | |||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||
| 460 | return | ||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | if !$ts; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||
| 463 | # Already epoch? | ||||||||||||||||||||||||||||||||||||||
| 464 | 0 | ▶ | return int $ts if $ts =~ /^\d{10}$/xsm; # seconds | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 465 | 0 | ▶ | return int $ts / 1000 if $ts =~ /^\d{13}$/xsm; # millis | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my $s = "$ts"; | |||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||
| 469 | # Common cleanups: | ||||||||||||||||||||||||||||||||||||||
| 470 | 0 | $s =~ s/,//xsmg; # "Aug 12, 2025, 4:55:04 PM" -> "Aug 12 2025 4:55:04 PM" | |||||||||||||||||||||||||||||||||||||
| 471 | 0 | $s =~ s/Z$/+0000/xsm; # ISO8601Z -> explicit offset | |||||||||||||||||||||||||||||||||||||
| 472 | 0 | $s =~ s/([+\-]\d\d):(\d\d)$/$1$2/xsm; # "+05:30" -> "+0530" | |||||||||||||||||||||||||||||||||||||
| 473 | 0 | $s =~ s/[.]\d+(?=(?:Z|[+\-]\d\d:?\d\d)$)//xsm; # strip fractional seconds if present | |||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||
| 475 | # Some services append " UTC" or similar—strip trailing timezone words | ||||||||||||||||||||||||||||||||||||||
| 476 | 0 | $s =~ s/\s+UTC$//xsmi; | |||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $epoch = str2time($s); | |||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | die "unrecognized timestamp: [$ts]" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 481 | if !defined $epoch; | ||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||
| 483 | 0 | return int $epoch; | |||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||
| 486 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||
| 488 | 2 | Readonly::Scalar our $SEC_PER_MIN => 60; | |||||||||||||||||||||||||||||||||||||
| 489 | 2 | Readonly::Scalar our $SEC_PER_HOUR => 60 * $SEC_PER_MIN; | |||||||||||||||||||||||||||||||||||||
| 490 | 2 | Readonly::Scalar our $SEC_PER_DAY => 24 * $SEC_PER_HOUR; | |||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||
| 492 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | sub normalize_time_range { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
normalize_time_range: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 494 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my ( $start, $end ) = @_; | |||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||
| 497 | return | ||||||||||||||||||||||||||||||||||||||
| 498 | 0 | ▶ | if !$start; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||
| 500 | 0 | my $now = time; | |||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||
| 502 | 0 | my $start_epoch = _to_epoch( $start, $now ); | |||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | my $end_epoch = defined $end ? _to_epoch( $end, $now ) : undef; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||
| 505 | 0 | ▶ | croak 'start is in the future' if $start_epoch > $now; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 506 | 0 | ▶ | croak 'end is in the future' if defined $end_epoch && $end_epoch > $now; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $end_epoch and $end_epoch > $now
MC/DC0%0/2
defined $end_epoch and $end_epoch > $now
defined $end_epoch
$end_epoch > $now
Truth table0%0/3
A and B
A= defined $end_epochB= $end_epoch > $now
| |||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | croak 'start > end' if defined $end_epoch && $start_epoch > $end_epoch; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $end_epoch and $start_epoch > $end_epoch
MC/DC0%0/2
defined $end_epoch and $start_epoch > $end_epoch
defined $end_epoch
$start_epoch > $end_epoch
Truth table0%0/3
A and B
A= defined $end_epochB= $start_epoch > $end_epoch
| |||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||
| 509 | 0 | ▶ | return ( $start_epoch * 1000, defined $end_epoch ? $end_epoch * 1000 : undef ); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||
| 512 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 513 | 0 | ▶ | sub _to_epoch { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_epoch: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||
| 514 | ######################################################################## | ||||||||||||||||||||||||||||||||||||||
| 515 | 0 | my ( $value, $now ) = @_; | |||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||
| 517 | # Duration syntax (e.g. 5d, 30m, 2h) | ||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | if ( $value =~ /^(\d+)([dmh])$/xsmi ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 519 | 0 | my ( $n, $unit ) = ( $1, lc $2 ); | |||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | croak 'duration cannot be zero' if $n == 0; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||||||||
| 522 | 0 | my %span = ( | |||||||||||||||||||||||||||||||||||||
| 523 | d => $SEC_PER_DAY, | ||||||||||||||||||||||||||||||||||||||
| 524 | h => $SEC_PER_HOUR, | ||||||||||||||||||||||||||||||||||||||
| 525 | m => $SEC_PER_MIN, | ||||||||||||||||||||||||||||||||||||||
| 526 | ); | ||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||
| 528 | 0 | return $now - $n * $span{$unit}; | |||||||||||||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||
| 531 | # Date string ‑ let Date::Parse do the heavy lifting | ||||||||||||||||||||||||||||||||||||||
| 532 | 0 | my $epoch = str2time($value); | |||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | croak "unrecognized date format: [$value]" | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 535 | if !defined $epoch; | ||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||
| 537 | 0 | return $epoch; | |||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||
| 540 | 2 | 1; | |||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||
| 542 | __END__ | ||||||||||||||||||||||||||||||||||||||