| 1 | package Amazon::API::Utils; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use JSON qw(decode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 10 | ▶ | use Scalar::Util qw(openhandle); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 10 | our @EXPORT_OK = qw(choose slurp slurp_json); | |||||||||||||||||||||||||||
| 13 | #our $VERSION = '2.8.2'; | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | ######################################################################## | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub choose(&) { ## no critic | ||||||||||||||||||||||||||
|
Subroutine
choose: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | ######################################################################## | ||||||||||||||||||||||||||||
| 18 | 0 | my $code = shift; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Pass the correct context down to the block | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 22 | 0 | return $code->(); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | elsif ( defined wantarray ) { | ||||||||||||||||||||||||||||
| 25 | 0 | return scalar $code->(); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | else { | ||||||||||||||||||||||||||||
| 28 | 0 | $code->(); | |||||||||||||||||||||||||||
| 29 | 0 | return; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ######################################################################## | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub slurp_json { | ||||||||||||||||||||||||||
|
Subroutine
slurp_json: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | ######################################################################## | ||||||||||||||||||||||||||||
| 36 | 0 | my ($file) = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | my $json = eval { return decode_json( slurp($file) ) }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | croak "ERROR: could not decode JSON string:\n$EVAL_ERROR\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $json or $Amazon::API::Utils::EVAL_ERROR
MC/DC0%0/2
not $json or $Amazon::API::Utils::EVAL_ERROR
not $json
$Amazon::API::Utils::EVAL_ERROR
Truth table0%0/3
not(A) or B
A= not $jsonB= $Amazon::API::Utils::EVAL_ERROR
| |||||||||||||||||||||||||||||
| 41 | if !$json || $EVAL_ERROR; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | return $json; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | ######################################################################## | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub slurp { | ||||||||||||||||||||||||||
|
Subroutine
slurp: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | ######################################################################## | ||||||||||||||||||||||||||||
| 49 | 0 | my ($file) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | local $RS = undef; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | return <$file> | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if openhandle $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | open my $fh, '<:raw', $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | or croak "ERROR: could not open $file\n"; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | my $content = <$fh>; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | close $fh | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | or croak "ERROR: could not close $file\n"; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | return $content; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 10 | 1; | |||||||||||||||||||||||||||