Base/JSON.pm

filter: Statementstmt 93.6% 44 / 47 Branchbran 87.5% 7 / 8 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 6 totaltotal 73.8% 65 / 88 CC 8 SCAR 12.8
CC
8
Cov
84%
cli_encode_json_as_bytes
7.5
cli_json_type_of
2.3
cli_json_type
2.0
CRAP 3.6
« blib/lib/MOP4Import/Util/CallTester.pm ↑ Summary Opts.pm »
1 package MOP4Import::Base::JSON;
2 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 13 ▶use constant DEBUG => $ENV{DEBUG_MOP4IMPORT};
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 13 ▶use MOP4Import::Base::Configure -as_base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use constant USING_CPANEL_JSON_XS => JSON()->isa("Cpanel::JSON::XS");
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Only works with Cpanel::JSON::XS. JSON::XS prohibits use of restricted hash.
12 sub TO_JSON {
13 1 ▶ my ($self) = @_;
Subroutine TO_JSON: called CC=1 SCAR=0.0
Pod undocumented
14 1 +{map(($_ => $self->{$_}), grep {!/^_/} keys %$self)}
15 }
16  
17 sub cli_json_type {
18 0 ▶ (my MY $self) = @_;
Subroutine cli_json_type: not called CC=1 SCAR=6.9
Pod undocumented
19 0 $self->cli_json_type_of($self);
20 }
21  
22 sub cli_json_type_of {
23 26 ▶ (my MY $self, my $objOrTypeName) = @_;
Subroutine cli_json_type_of: called CC=2 SCAR=8.1
Pod undocumented
24 26 ▶ $self->JSON_TYPE_HANDLER->lookup_json_type(ref $objOrTypeName || $objOrTypeName);
Condition33%1/3
ref $objOrTypeName || $objOrTypeName
l!l&&r!l&&!r
0260
MC/DC0%0/2
ref $objOrTypeName || $objOrTypeName
ref $objOrTypeName $objOrTypeName
Truth table33%1/3
A || B
A= ref $objOrTypeNameB= $objOrTypeName
ABresult
1X1
011
000
25 }
26  
27 sub cli_json_encoder {
28 24 ▶ (my MY $self) = @_;
Subroutine cli_json_encoder: called CC=1 SCAR=0.0
Pod undocumented
29 24 my $js = JSON()->new->canonical->allow_nonref;
30 24 if (USING_CPANEL_JSON_XS) {
31 24 $js->convert_blessed;
32 }
33 24 $js;
34 }
35  
36 sub cli_encode_json {
37 24 ▶ (my MY $self, my ($obj, $json_type)) = @_;
Subroutine cli_encode_json: called CC=1 SCAR=0.0
Pod undocumented
38 24 my $json = $self->cli_encode_json_as_bytes($obj, $json_type);
39 24 $json;
40 }
41  
42 sub cli_encode_json_as_bytes {
43 24 ▶ (my MY $self, my ($obj, $json_type)) = @_;
Subroutine cli_encode_json_as_bytes: called CC=7 SCAR=20.2
Pod undocumented
44 24 my $codec = $self->cli_json_encoder;
45 24 my @opts;
46 24 my $json = do {
47 24 ▶ if (not USING_CPANEL_JSON_XS) {
Branch: 3 branches
BranchTrueFalseTotal
if (do { defined $json_type }) { } 3 21 24
elsif (my $sub = UNIVERSAL::can($obj, 'TO_JSON')) { } 3 18 21
elsif (ref $obj and my(@opts) = $self->cli_json_type_of(ref $obj)) { } 18 0 18
48 $codec->encode($obj);
49 }
50 elsif (defined $json_type) {
51 3 ▶ $codec->encode($obj, $self->cli_json_type_of($json_type) // $json_type);
Condition33%1/3
$self->cli_json_type_of($json_type) // $json_type
l!l&&r!l&&!r
300
MC/DC0%0/2
$self->cli_json_type_of($json_type) // $json_type
$self->cli_json_type_of($json_type) $json_type
Truth table33%1/3
A // B
A= $self->cli_json_type_of($json_type)B= $json_type
ABresult
1X1
011
000
52 }
53 elsif (my $sub = UNIVERSAL::can($obj, 'TO_JSON')) {
54 3 my $conv = $sub->($obj);
55 3 ▶ if (ref $conv eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $conv eq 'HASH') { } 2 1 3
56 2 $codec->encode($conv, $self->cli_json_type_of(ref $obj));
57 } else {
58 1 $codec->encode($conv);
59 }
60 }
61 ▶ elsif (ref $obj and my @opts = $self->cli_json_type_of(ref $obj)) {
Condition33%1/3
ref $obj and my(@opts) = $self->cli_json_type_of(ref $obj)
!ll&&!rl&&r
0018
MC/DC0%0/2
ref $obj and my(@opts) = $self->cli_json_type_of(ref $obj)
ref $obj my(@opts) = $self->cli_json_type_of(ref $obj)
Truth table33%1/3
A and B
A= ref $objB= my(@opts) = $self->cli_json_type_of(ref $obj)
ABresult
0X0
100
111
62 18 $codec->encode($obj, @opts);
63 }
64 else {
65 0 $codec->encode($obj);
66 }
67 };
68 24 $json;
69 }
70  
71 13 1;
« blib/lib/MOP4Import/Util/CallTester.pm ↑ Summary Opts.pm »