API/Utils.pm

filter: Statementstmt 56.1% 23 / 41 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 0.0% 0 / 3 totaltotal 42.2% 30 / 71 CC 8 SCAR 22.4
CC
8
Cov
41%
slurp
20.0
choose
12.0
slurp_json
12.0
CRAP 9.4
« API/Role/ModuleNames.pm ↑ Summary API/Signature4.pm »
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
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
elsif (defined wantarray) { } 0 0 0
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
BranchTrueFalseTotal
if not $json or $Amazon::API::Utils::EVAL_ERROR 0 0 0
Condition0%0/3
not $json or $Amazon::API::Utils::EVAL_ERROR
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if &openhandle($file) 0 0 0
55  
56 0 ▶ open my $fh, '<:raw', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:raw", $file or croak("ERROR: could not open $file\n") 0 0 0
57 or croak "ERROR: could not open $file\n";
58  
59 0 my $content = <$fh>;
60  
61 0 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or croak("ERROR: could not close $file\n") 0 0 0
62 or croak "ERROR: could not close $file\n";
63  
64 0 return $content;
65 }
66  
67 10 1;
« API/Role/ModuleNames.pm ↑ Summary API/Signature4.pm »