JSON/backportPP.pm

filter: Statementstmt 84.9% 841 / 990 Branchbran 78.0% 518 / 664 Conditioncond 61.4% 174 / 283 MC/DCmcdc 46.2% 80 / 173 Subroutinesub 81.7% 134 / 164 Podpod 51.2% 42 / 82 totaltotal 75.9% 1789 / 2356 CC 437 SCAR 30.5
CC
437
Cov
79%
_tag
110.0
_white
104.9
_incr_parse
65.9
CRAP 21.1
« JSON/backportPP/Compat5006.pm ↑ Summary JSON.pm »
1 package # This is JSON::backportPP
2 JSON::PP;
3  
4 # JSON-2.0
5  
6 57 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 57 ▶use Exporter ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 57 ▶BEGIN { @JSON::backportPP::ISA = ('Exporter') }
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 57 ▶use overload ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 57 ▶use JSON::backportPP::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 57 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 57 ▶use Scalar::Util qw(blessed reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 #use Devel::Peek;
18  
19 57 $JSON::backportPP::VERSION = '4.18';
20  
21 57 our @EXPORT = qw(encode_json decode_json from_json to_json);
22  
23 # instead of hash-access, i tried index-access for speed.
24 # but this method is not faster than what i expected. so it will be changed.
25  
26 57 ▶use constant P_ASCII => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 57 ▶use constant P_LATIN1 => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 57 ▶use constant P_UTF8 => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 57 ▶use constant P_INDENT => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 57 ▶use constant P_CANONICAL => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 57 ▶use constant P_SPACE_BEFORE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 57 ▶use constant P_SPACE_AFTER => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 57 ▶use constant P_ALLOW_NONREF => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 57 ▶use constant P_SHRINK => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 57 ▶use constant P_ALLOW_BLESSED => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 57 ▶use constant P_CONVERT_BLESSED => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 57 ▶use constant P_RELAXED => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 57 ▶use constant P_LOOSE => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 57 ▶use constant P_ALLOW_BIGNUM => 13;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 57 ▶use constant P_ALLOW_BAREKEY => 14;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 57 ▶use constant P_ALLOW_SINGLEQUOTE => 15;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 57 ▶use constant P_ESCAPE_SLASH => 16;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 57 ▶use constant P_AS_NONBLESSED => 17;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 57 ▶use constant P_ALLOW_UNKNOWN => 18;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 57 ▶use constant P_ALLOW_TAGS => 19;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 57 ▶use constant USE_B => $ENV{PERL_JSON_PP_USE_B} || 0;
Subroutine BEGIN: called CC=2 SCAR=7.1
Condition50%1/2
$ENV{'PERL_JSON_PP_USE_B'} || 0
l!l
057
MC/DC0%0/1
$ENV{'PERL_JSON_PP_USE_B'} || 0
$ENV{'PERL_JSON_PP_USE_B'}
Truth table50%1/2
A
A= $ENV{'PERL_JSON_PP_USE_B'}
Aresult
11
00
50 57 ▶use constant CORE_BOOL => defined &builtin::is_bool;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 57 my $invalid_char_re;
53  
54 57 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
55 57 $invalid_char_re = "[";
56 57 for my $i (0 .. 0x01F, 0x22, 0x5c) { # '/' is ok
57 1938 $invalid_char_re .= quotemeta chr utf8::unicode_to_native($i);
58 }
59  
60 57 $invalid_char_re = qr/$invalid_char_re]/;
61 }
62  
63 57 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
64 57 if (USE_B) {
65 require B;
66 }
67 }
68  
69 57 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.3
70 57 my @xs_compati_bit_properties = qw(
71 latin1 ascii utf8 indent canonical space_before space_after allow_nonref shrink
72 allow_blessed convert_blessed relaxed allow_unknown
73 allow_tags
74 );
75 57 my @pp_bit_properties = qw(
76 allow_singlequote allow_bignum loose
77 allow_barekey escape_slash as_nonblessed
78 );
79  
80 57 for my $name (@xs_compati_bit_properties, @pp_bit_properties) {
81 1140 my $property_id = 'P_' . uc($name);
82  
83 0 ▶ eval qq/
Subroutine allow_barekey: called CC=3 SCAR=11.5
Subroutine allow_bignum: called CC=3 SCAR=11.5
Subroutine allow_blessed: called CC=3 SCAR=11.5
Subroutine allow_nonref: called CC=3 SCAR=11.5
Subroutine allow_singlequote: called CC=3 SCAR=11.5
Subroutine allow_tags: not called CC=3 SCAR=11.5
Subroutine allow_unknown: called CC=3 SCAR=11.5
Subroutine as_nonblessed: not called CC=3 SCAR=11.5
Subroutine ascii: called CC=3 SCAR=11.5
Subroutine canonical: called CC=3 SCAR=11.5
Subroutine convert_blessed: called CC=3 SCAR=11.5
Subroutine escape_slash: called CC=3 SCAR=11.5
Subroutine get_allow_barekey: not called CC=2 SCAR=7.3
Subroutine get_allow_bignum: not called CC=2 SCAR=7.3
Subroutine get_allow_blessed: called CC=2 SCAR=7.3
Subroutine get_allow_nonref: called CC=2 SCAR=7.3
Subroutine get_allow_singlequote: not called CC=2 SCAR=7.3
Subroutine get_allow_tags: not called CC=2 SCAR=7.3
Subroutine get_allow_unknown: not called CC=2 SCAR=7.3
Subroutine get_as_nonblessed: not called CC=2 SCAR=7.3
Subroutine get_ascii: called CC=2 SCAR=7.3
Subroutine get_canonical: called CC=2 SCAR=7.3
Subroutine get_convert_blessed: called CC=2 SCAR=7.3
Subroutine get_escape_slash: not called CC=2 SCAR=7.3
Subroutine get_indent: called CC=2 SCAR=7.3
Subroutine get_latin1: called CC=2 SCAR=7.3
Subroutine get_loose: not called CC=2 SCAR=7.3
Subroutine get_relaxed: called CC=2 SCAR=7.3
Subroutine get_shrink: called CC=2 SCAR=7.3
Subroutine get_space_after: called CC=2 SCAR=7.3
Subroutine get_space_before: called CC=2 SCAR=7.3
Subroutine get_utf8: called CC=2 SCAR=7.3
Subroutine indent: called CC=3 SCAR=11.5
Subroutine latin1: called CC=3 SCAR=11.5
Subroutine loose: not called CC=3 SCAR=11.5
Subroutine relaxed: called CC=3 SCAR=11.5
Subroutine shrink: called CC=3 SCAR=11.5
Subroutine space_after: called CC=3 SCAR=11.5
Subroutine space_before: called CC=3 SCAR=11.5
Subroutine utf8: called CC=3 SCAR=11.5
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Pod documented
Branch: 60 branches
BranchTrueFalseTotal
defined $_[1] ? : 0 2 2
if ($enable) { } 2 0 2
defined $_[1] ? : 1 0 1
if ($enable) { } 1 0 1
defined $_[1] ? : 3 7 10
if ($enable) { } 7 3 10
defined $_[1] ? : 24623 24 24647
if ($enable) { } 9279 15368 24647
defined $_[1] ? : 0 1 1
if ($enable) { } 1 0 1
defined $_[1] ? : 0 0 0
if ($enable) { } 0 0 0
defined $_[1] ? : 2 1 3
if ($enable) { } 2 1 3
defined $_[1] ? : 0 0 0
if ($enable) { } 0 0 0
defined $_[1] ? : 4 12294 12298
if ($enable) { } 12296 2 12298
defined $_[1] ? : 5 10 15
if ($enable) { } 13 2 15
defined $_[1] ? : 4 8 12
if ($enable) { } 9 3 12
defined $_[1] ? : 0 1 1
if ($enable) { } 1 0 1
$_[0]{'PROPS'}[14] ? : 0 0 0
$_[0]{'PROPS'}[13] ? : 0 0 0
$_[0]{'PROPS'}[9] ? : 4 3 7
$_[0]{'PROPS'}[7] ? : 5 2 7
$_[0]{'PROPS'}[15] ? : 0 0 0
$_[0]{'PROPS'}[19] ? : 0 0 0
$_[0]{'PROPS'}[18] ? : 0 0 0
$_[0]{'PROPS'}[17] ? : 0 0 0
$_[0]{'PROPS'}[0] ? : 4 3 7
$_[0]{'PROPS'}[4] ? : 4 3 7
$_[0]{'PROPS'}[10] ? : 4 3 7
$_[0]{'PROPS'}[16] ? : 0 0 0
$_[0]{'PROPS'}[3] ? : 4 3 7
$_[0]{'PROPS'}[1] ? : 4 3 7
$_[0]{'PROPS'}[12] ? : 0 0 0
$_[0]{'PROPS'}[11] ? : 4 3 7
$_[0]{'PROPS'}[8] ? : 4 3 7
$_[0]{'PROPS'}[6] ? : 4 3 7
$_[0]{'PROPS'}[5] ? : 4 3 7
$_[0]{'PROPS'}[2] ? : 4 276 280
defined $_[1] ? : 8 4 12
if ($enable) { } 8 4 12
defined $_[1] ? : 2 6 8
if ($enable) { } 6 2 8
defined $_[1] ? : 0 0 0
if ($enable) { } 0 0 0
defined $_[1] ? : 2 18 20
if ($enable) { } 18 2 20
defined $_[1] ? : 2 21508 21510
if ($enable) { } 21508 2 21510
defined $_[1] ? : 9 4 13
if ($enable) { } 8 5 13
defined $_[1] ? : 8 4 12
if ($enable) { } 8 4 12
defined $_[1] ? : 6 18497 18503
if ($enable) { } 18501 2 18503
84 sub $name {
85 my \$enable = defined \$_[1] ? \$_[1] : 1;
86  
87 if (\$enable) {
88 \$_[0]->{PROPS}->[$property_id] = 1;
89 }
90 else {
91 \$_[0]->{PROPS}->[$property_id] = 0;
92 }
93  
94 \$_[0];
95 }
96  
97 sub get_$name {
98 \$_[0]->{PROPS}->[$property_id] ? 1 : '';
99 }
100 /;
101 }
102  
103 }
104  
105  
106  
107 # Functions
108  
109 my $JSON; # cache
110  
111 185 ▶sub encode_json ($) { # encode
Subroutine encode_json: called CC=2 SCAR=9.2
Pod documented
112 185 ▶ ($JSON ||= __PACKAGE__->new->utf8)->encode(@_);
Condition33%1/3
$JSON ||= __PACKAGE__->new->utf8
l!l&&r!l&&!r
18500
MC/DC0%0/2
$JSON ||= __PACKAGE__->new->utf8
$JSON __PACKAGE__->new->utf8
Truth table33%1/3
A ||= B
A= $JSONB= __PACKAGE__->new->utf8
ABresult
1X1
011
000
113 }
114  
115  
116 6257 ▶sub decode_json ($) { # decode
Subroutine decode_json: called CC=2 SCAR=7.2
Pod documented
117 6257 ▶ ($JSON ||= __PACKAGE__->new->utf8)->decode(@_);
Condition66%2/3
$JSON ||= __PACKAGE__->new->utf8
l!l&&r!l&&!r
6200570
MC/DC0%0/2
$JSON ||= __PACKAGE__->new->utf8
$JSON __PACKAGE__->new->utf8
Truth table66%2/3
A ||= B
A= $JSONB= __PACKAGE__->new->utf8
ABresult
1X1
011
000
118 }
119  
120 # Obsoleted
121  
122 0 ▶sub to_json($) {
Subroutine to_json: not called CC=1 SCAR=6.9
Pod undocumented
123 0 Carp::croak ("JSON::PP::to_json has been renamed to encode_json.");
124 }
125  
126  
127 0 ▶sub from_json($) {
Subroutine from_json: not called CC=1 SCAR=6.9
Pod undocumented
128 0 Carp::croak ("JSON::PP::from_json has been renamed to decode_json.");
129 }
130  
131  
132 # Methods
133  
134 43190 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
135 43190 my $class = shift;
136 43190 my $self = {
137 max_depth => 512,
138 max_size => 0,
139 indent_length => 3,
140 };
141  
142 43190 $self->{PROPS}[P_ALLOW_NONREF] = 1;
143  
144 43190 bless $self, $class;
145 }
146  
147  
148 25125 ▶sub encode {
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
149 25125 return $_[0]->PP_encode_json($_[1]);
150 }
151  
152  
153 24984 ▶sub decode {
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
154 24984 return $_[0]->PP_decode_json($_[1], 0x00000000);
155 }
156  
157  
158 8 ▶sub decode_prefix {
Subroutine decode_prefix: called CC=1 SCAR=0.0
Pod documented
159 8 return $_[0]->PP_decode_json($_[1], 0x00000001);
160 }
161  
162  
163 # accessor
164  
165  
166 # pretty printing
167  
168 5 ▶sub pretty {
Subroutine pretty: called CC=3 SCAR=11.0
Pod documented
169 5 my ($self, $v) = @_;
170 5 ▶ my $enable = defined $v ? $v : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $v ? : 5 0 5
171  
172 5 ▶ if ($enable) { # indent_length(3) for JSON::XS compatibility
Branch: 1 branch
BranchTrueFalseTotal
if ($enable) { } 3 2 5
173 3 $self->indent(1)->space_before(1)->space_after(1);
174 }
175 else {
176 2 $self->indent(0)->space_before(0)->space_after(0);
177 }
178  
179 5 $self;
180 }
181  
182 # etc
183  
184 7 ▶sub max_depth {
Subroutine max_depth: called CC=2 SCAR=6.9
Pod documented
185 7 ▶ my $max = defined $_[1] ? $_[1] : 0x80000000;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 6 1 7
186 7 $_[0]->{max_depth} = $max;
187 7 $_[0];
188 }
189  
190  
191 358 ▶sub get_max_depth { $_[0]->{max_depth}; }
Subroutine get_max_depth: called CC=1 SCAR=0.0
Pod undocumented
192  
193  
194 5 ▶sub max_size {
Subroutine max_size: called CC=2 SCAR=6.9
Pod documented
195 5 ▶ my $max = defined $_[1] ? $_[1] : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 4 1 5
196 5 $_[0]->{max_size} = $max;
197 5 $_[0];
198 }
199  
200  
201 322 ▶sub get_max_size { $_[0]->{max_size}; }
Subroutine get_max_size: called CC=1 SCAR=0.0
Pod undocumented
202  
203 0 ▶sub boolean_values {
Subroutine boolean_values: not called CC=6 SCAR=36.4
Pod documented
204 0 my $self = shift;
205 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
206 0 my ($false, $true) = @_;
207 0 $self->{false} = $false;
208 0 $self->{true} = $true;
209 0 if (CORE_BOOL) {
210 57 ▶ BEGIN { CORE_BOOL and warnings->unimport(qw(experimental::builtin)) }
Subroutine BEGIN: called CC=1 SCAR=0.0
211 0 ▶ if (builtin::is_bool($true) && builtin::is_bool($false) && $true && !$false) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::is_bool($true) and builtin::is_bool($false) and $true and not $false) { } 0 0 0
Condition0%0/9
builtin::is_bool($true) and builtin::is_bool($false) and $true and not $false
!ll&&!rl&&r
000
builtin::is_bool($true) and builtin::is_bool($false) and $true
!ll&&!rl&&r
000
builtin::is_bool($true) and builtin::is_bool($false)
!ll&&!rl&&r
000
MC/DC0%0/4
builtin::is_bool($true) and builtin::is_bool($false) and $true and not $false
builtin::is_bool($true) builtin::is_bool($false) $true not $false
Truth table0%0/5
A and B and C and not(D)
A= builtin::is_bool($true)B= builtin::is_bool($false)C= $trueD= not $false
ABCDresult
0XXX0
10XX0
110X0
11100
11111
212 0 $self->{core_bools} = !!1;
213 }
214 else {
215 0 delete $self->{core_bools};
216 }
217 }
218 } else {
219 0 delete $self->{false};
220 0 delete $self->{true};
221 0 delete $self->{core_bools};
222 }
223 0 return $self;
224 }
225  
226 0 ▶sub core_bools {
Subroutine core_bools: not called CC=3 SCAR=24.8
Pod documented
227 0 my $self = shift;
228 0 ▶ my $core_bools = defined $_[0] ? $_[0] : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
229 0 ▶ if ($core_bools) {
Branch: 1 branch
BranchTrueFalseTotal
if ($core_bools) { } 0 0 0
230 0 $self->{true} = !!1;
231 0 $self->{false} = !!0;
232 0 $self->{core_bools} = !!1;
233 }
234 else {
235 0 $self->{true} = $JSON::PP::true;
236 0 $self->{false} = $JSON::PP::false;
237 0 $self->{core_bools} = !!0;
238 }
239 0 return $self;
240 }
241  
242 0 ▶sub get_core_bools {
Subroutine get_core_bools: not called CC=1 SCAR=6.9
Pod undocumented
243 0 my $self = shift;
244 0 return !!$self->{core_bools};
245 }
246  
247 0 ▶sub unblessed_bool {
Subroutine unblessed_bool: not called CC=1 SCAR=6.9
Pod undocumented
248 0 my $self = shift;
249 0 return $self->core_bools(@_);
250 }
251  
252 0 ▶sub get_unblessed_bool {
Subroutine get_unblessed_bool: not called CC=1 SCAR=6.9
Pod undocumented
253 0 my $self = shift;
254 0 return $self->get_core_bools(@_);
255 }
256  
257 0 ▶sub get_boolean_values {
Subroutine get_boolean_values: not called CC=3 SCAR=24.8
Pod undocumented
258 0 my $self = shift;
259 0 ▶ if (exists $self->{true} and exists $self->{false}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"true"} and exists $self->{"false"}) 0 0 0
Condition0%0/3
exists $self->{"true"} and exists $self->{"false"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"true"} and exists $self->{"false"}
exists $self->{"true"} exists $self->{"false"}
Truth table0%0/3
A and B
A= exists $self->{"true"}B= exists $self->{"false"}
ABresult
0X0
100
111
260 0 return @$self{qw/false true/};
261 }
262 0 return;
263 }
264  
265 3 ▶sub filter_json_object {
Subroutine filter_json_object: called CC=5 SCAR=16.5
Pod documented
266 3 ▶ if (defined $_[1] and ref $_[1] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1] and ref $_[1] eq 'CODE') { } 2 1 3
Condition66%2/3
defined $_[1] and ref $_[1] eq "CODE"
!ll&&!rl&&r
102
MC/DC50%1/2
defined $_[1] and ref $_[1] eq "CODE"
defined $_[1] ref $_[1] eq "CODE"
Truth table66%2/3
A and B
A= defined $_[1]B= ref $_[1] eq "CODE"
ABresult
0X0
100
111
267 2 $_[0]->{cb_object} = $_[1];
268 } else {
269 1 delete $_[0]->{cb_object};
270 }
271 3 ▶ $_[0]->{F_HOOK} = ($_[0]->{cb_object} or $_[0]->{cb_sk_object}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'cb_object'} || $_[0]{'cb_sk_object'} ? : 3 0 3
Condition66%2/3
$_[0]{"cb_object"} or $_[0]{"cb_sk_object"}
l!l&&r!l&&!r
210
MC/DC0%0/2
$_[0]{"cb_object"} or $_[0]{"cb_sk_object"}
$_[0]{"cb_object"} $_[0]{"cb_sk_object"}
Truth table66%2/3
A or B
A= $_[0]{"cb_object"}B= $_[0]{"cb_sk_object"}
ABresult
1X1
011
000
272 3 $_[0];
273 }
274  
275 4 ▶sub filter_json_single_key_object {
Subroutine filter_json_single_key_object: called CC=9 SCAR=25.4
Pod documented
276 4 ▶ if (@_ == 1 or @_ > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 or @_ > 3) 0 4 4
Condition33%1/3
@_ == 1 or @_ > 3
l!l&&r!l&&!r
004
MC/DC0%0/2
@_ == 1 or @_ > 3
@_ == 1 @_ > 3
Truth table33%1/3
A or B
A= @_ == 1B= @_ > 3
ABresult
1X1
011
000
277 0 Carp::croak("Usage: JSON::PP::filter_json_single_key_object(self, key, callback = undef)");
278 }
279 4 ▶ if (defined $_[2] and ref $_[2] eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[2] and ref $_[2] eq 'CODE') { } 3 1 4
Condition66%2/3
defined $_[2] and ref $_[2] eq "CODE"
!ll&&!rl&&r
103
MC/DC50%1/2
defined $_[2] and ref $_[2] eq "CODE"
defined $_[2] ref $_[2] eq "CODE"
Truth table66%2/3
A and B
A= defined $_[2]B= ref $_[2] eq "CODE"
ABresult
0X0
100
111
280 3 $_[0]->{cb_sk_object}->{$_[1]} = $_[2];
281 } else {
282 1 delete $_[0]->{cb_sk_object}->{$_[1]};
283 1 ▶ delete $_[0]->{cb_sk_object} unless %{$_[0]->{cb_sk_object} || {}};
Branch: 1 branch
BranchTrueFalseTotal
unless %{$_[0]{"cb_sk_object"} or {};} 0 1 1
Condition50%1/2
$_[0]{'cb_sk_object'} || {}
l!l
10
MC/DC0%0/1
$_[0]{'cb_sk_object'} || {}
$_[0]{'cb_sk_object'}
Truth table50%1/2
A
A= $_[0]{'cb_sk_object'}
Aresult
11
00
284 }
285 4 ▶ $_[0]->{F_HOOK} = ($_[0]->{cb_object} or $_[0]->{cb_sk_object}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'cb_object'} || $_[0]{'cb_sk_object'} ? : 4 0 4
Condition33%1/3
$_[0]{"cb_object"} or $_[0]{"cb_sk_object"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$_[0]{"cb_object"} or $_[0]{"cb_sk_object"}
$_[0]{"cb_object"} $_[0]{"cb_sk_object"}
Truth table33%1/3
A or B
A= $_[0]{"cb_object"}B= $_[0]{"cb_sk_object"}
ABresult
1X1
011
000
286 4 $_[0];
287 }
288  
289 0 ▶sub indent_length {
Subroutine indent_length: not called CC=4 SCAR=30.0
Pod documented
290 0 ▶ if (!defined $_[1] or $_[1] > 15 or $_[1] < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $_[1] or $_[1] > 15 or $_[1] < 0) { } 0 0 0
Condition0%0/6
not defined $_[1] or $_[1] > 15 or $_[1] < 0
l!l&&r!l&&!r
000
not defined $_[1] or $_[1] > 15
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $_[1] or $_[1] > 15 or $_[1] < 0
not defined $_[1] $_[1] > 15 $_[1] < 0
Truth table0%0/4
not(A) or B or C
A= not defined $_[1]B= $_[1] > 15C= $_[1] < 0
ABCresult
1XX1
01X1
0011
0000
291 0 Carp::carp "The acceptable range of indent_length() is 0 to 15.";
292 }
293 else {
294 0 $_[0]->{indent_length} = $_[1];
295 }
296 0 $_[0];
297 }
298  
299 0 ▶sub get_indent_length {
Subroutine get_indent_length: not called CC=1 SCAR=6.9
Pod undocumented
300 0 $_[0]->{indent_length};
301 }
302  
303 3 ▶sub sort_by {
Subroutine sort_by: called CC=2 SCAR=7.2
Pod documented
304 3 ▶ $_[0]->{sort_by} = defined $_[1] ? $_[1] : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 3 0 3
305 3 $_[0];
306 }
307  
308 0 ▶sub allow_bigint {
Subroutine allow_bigint: not called CC=1 SCAR=6.9
Pod undocumented
309 0 Carp::carp("allow_bigint() is obsoleted. use allow_bignum() instead.");
310 0 $_[0]->allow_bignum;
311 }
312  
313 ###############################
314  
315 ###
316 ### Perl => JSON
317 ###
318  
319  
320 { # Convert
321  
322 25125 ▶ sub PP_encode_json {
Subroutine PP_encode_json: called CC=8 SCAR=20.8
Pod undocumented
323 25125 my $self = shift;
324 25125 my $obj = shift;
325  
326 25125 $self->{indent_count} = 0;
327 25125 $self->{depth} = 0;
328  
329 25125 my $props = $self->{PROPS};
330  
331 25125 ▶ $self->{keysort} = $self->{PROPS}[P_CANONICAL] ? sub { $a cmp $b } : undef;
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{'PROPS'}[4] ? : 246 24879 25125
332  
333 25125 ▶ if ($self->{sort_by}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sort_by"}) 3 25122 25125
334 $self->{keysort} = ref($self->{sort_by}) eq 'CODE' ? $self->{sort_by}
335 : $self->{sort_by} =~ /\D+/ ? $self->{sort_by}
336 3 ▶ : sub { $a cmp $b };
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
ref $self->{'sort_by'} eq 'CODE' ? : 1 2 3
$self->{'sort_by'} =~ /\D+/ ? : 1 1 2
337 }
338  
339 25125 ▶ encode_error("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj or $props->[7] 0 25125 25125
Condition66%2/3
ref $obj or $props->[7]
l!l&&r!l&&!r
25065600
MC/DC0%0/2
ref $obj or $props->[7]
ref $obj $props->[7]
Truth table66%2/3
A or B
A= ref $objB= $props->[7]
ABresult
1X1
011
000
340 if(!ref $obj and !$props->[ P_ALLOW_NONREF ]);
341  
342 25125 my $str = $self->object_to_json($obj);
343  
344 25107 ▶ $str .= "\n" if ( $self->{PROPS}[P_INDENT] ); # JSON::XS 2.26 compatible
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[3] 7 25100 25107
345  
346 25107 return $str;
347 }
348  
349  
350 25480 ▶ sub object_to_json {
Subroutine object_to_json: called CC=21 SCAR=35.3
Pod undocumented
351 25480 my ($self, $obj) = @_;
352 25480 my $type = ref($obj);
353  
354 25480 ▶ if($type eq 'HASH'){
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'HASH') { } 343 25137 25480
elsif ($type eq 'ARRAY') { } 25019 118 25137
elsif ($type) { } 54 64 118
355 343 return $self->hash_to_json($obj);
356 }
357 elsif($type eq 'ARRAY'){
358 25019 return $self->array_to_json($obj);
359 }
360 elsif ($type) { # blessed object?
361 54 ▶ if (blessed($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($obj)) { } 34 20 54
362  
363 34 ▶ return $self->value_to_json($obj) if ( $obj->isa('JSON::PP::Boolean') );
Branch: 1 branch
BranchTrueFalseTotal
if $obj->isa("JSON::PP::Boolean") 18 16 34
364  
365 16 ▶ if ( $self->{PROPS}[P_ALLOW_TAGS] and $obj->can('FREEZE') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[19] and $obj->can("FREEZE")) 0 16 16
Condition33%1/3
$self->{"PROPS"}[19] and $obj->can("FREEZE")
!ll&&!rl&&r
1600
MC/DC0%0/2
$self->{"PROPS"}[19] and $obj->can("FREEZE")
$self->{"PROPS"}[19] $obj->can("FREEZE")
Truth table33%1/3
A and B
A= $self->{"PROPS"}[19]B= $obj->can("FREEZE")
ABresult
0X0
100
111
366 0 ▶ my $obj_class = ref $obj || $obj;
Condition0%0/3
ref $obj || $obj
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $obj || $obj
ref $obj $obj
Truth table0%0/3
A || B
A= ref $objB= $obj
ABresult
1X1
011
000
367 0 $obj = bless $obj, $obj_class;
368 0 my @results = $obj->FREEZE('JSON');
369 0 ▶ if ( @results and ref $results[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@results and ref $results[0]) 0 0 0
Condition0%0/3
@results and ref $results[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@results and ref $results[0]
@results ref $results[0]
Truth table0%0/3
A and B
A= @resultsB= ref $results[0]
ABresult
0X0
100
111
370 0 ▶ if ( refaddr( $obj ) eq refaddr( $results[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($obj) eq builtin::refaddr($results[0])) 0 0 0
371 0 encode_error( sprintf(
372 "%s::FREEZE method returned same object as was passed instead of a new one",
373 ref $obj
374 ) );
375 }
376 }
377 0 return '("'.$obj_class.'")['.join(',', @results).']';
378 }
379  
380 16 ▶ if ( $self->{PROPS}[P_CONVERT_BLESSED] and $obj->can('TO_JSON') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[10] and $obj->can("TO_JSON")) 8 8 16
Condition100%3/3
$self->{"PROPS"}[10] and $obj->can("TO_JSON")
!ll&&!rl&&r
538
MC/DC100%2/2
$self->{"PROPS"}[10] and $obj->can("TO_JSON")
$self->{"PROPS"}[10] $obj->can("TO_JSON")
Truth table100%3/3
A and B
A= $self->{"PROPS"}[10]B= $obj->can("TO_JSON")
ABresult
0X0
100
111
381 8 my $result = $obj->TO_JSON();
382 8 ▶ if ( defined $result and ref( $result ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $result and ref $result) 4 4 8
Condition66%2/3
defined $result and ref $result
!ll&&!rl&&r
044
MC/DC50%1/2
defined $result and ref $result
defined $result ref $result
Truth table66%2/3
A and B
A= defined $resultB= ref $result
ABresult
0X0
100
111
383 4 ▶ if ( refaddr( $obj ) eq refaddr( $result ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::refaddr($obj) eq builtin::refaddr($result)) 1 3 4
384 1 encode_error( sprintf(
385 "%s::TO_JSON method returned same object as was passed instead of a new one",
386 ref $obj
387 ) );
388 }
389 }
390  
391 7 return $self->object_to_json( $result );
392 }
393  
394 8 ▶ return "$obj" if ( $self->{PROPS}[P_ALLOW_BIGNUM] and _is_bignum($obj) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[13] and _is_bignum($obj) 2 6 8
Condition66%2/3
$self->{"PROPS"}[13] and _is_bignum($obj)
!ll&&!rl&&r
602
MC/DC50%1/2
$self->{"PROPS"}[13] and _is_bignum($obj)
$self->{"PROPS"}[13] _is_bignum($obj)
Truth table66%2/3
A and B
A= $self->{"PROPS"}[13]B= _is_bignum($obj)
ABresult
0X0
100
111
395  
396 6 ▶ if ($self->{PROPS}[P_ALLOW_BLESSED]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[9]) 4 2 6
397 4 ▶ return $self->blessed_to_json($obj) if ($self->{PROPS}[P_AS_NONBLESSED]); # will be removed.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[17] 0 4 4
398 4 return 'null';
399 }
400 2 encode_error( sprintf("encountered object '%s', but neither allow_blessed, convert_blessed nor allow_tags settings are enabled (or TO_JSON/FREEZE method missing)", $obj)
401 );
402 }
403 else {
404 20 return $self->value_to_json($obj);
405 }
406 }
407 else{
408 64 return $self->value_to_json($obj);
409 }
410 }
411  
412  
413 343 ▶ sub hash_to_json {
Subroutine hash_to_json: called CC=9 SCAR=22.0
Pod undocumented
414 343 my ($self, $obj) = @_;
415 343 my @res;
416  
417 encode_error("json text or perl structure exceeds maximum nesting level (max_depth set too low?)")
418 343 ▶ if (++$self->{depth} > $self->{max_depth});
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"depth"} > $self->{"max_depth"} 1 342 343
419  
420 342 ▶ my ($pre, $post) = $self->{PROPS}[P_INDENT] ? $self->_up_indent() : ('', '');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'PROPS'}[3] ? : 7 335 342
421 342 ▶ my $del = ($self->{PROPS}[P_SPACE_BEFORE] ? ' ' : '') . ':' . ($self->{PROPS}[P_SPACE_AFTER] ? ' ' : '');
Branch: 2 branches
BranchTrueFalseTotal
$self->{'PROPS'}[5] ? : 5 337 342
$self->{'PROPS'}[6] ? : 5 337 342
422  
423 342 for my $k ( $self->__sort( $obj ) ) {
424 push @res, $self->string_to_json( $k )
425 . $del
426 663 ▶ . ( ref $obj->{$k} ? $self->object_to_json( $obj->{$k} ) : $self->value_to_json( $obj->{$k} ) );
Branch: 1 branch
BranchTrueFalseTotal
ref $obj->{$k} ? : 33 630 663
427 }
428  
429 340 --$self->{depth};
430 340 ▶ $self->_down_indent() if ($self->{PROPS}[P_INDENT]);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[3] 7 333 340
431  
432 340 ▶ return '{}' unless @res;
Branch: 1 branch
BranchTrueFalseTotal
unless @res 10 330 340
433 330 return '{' . $pre . join( ",$pre", @res ) . $post . '}';
434 }
435  
436  
437 25019 ▶ sub array_to_json {
Subroutine array_to_json: called CC=9 SCAR=22.0
Pod undocumented
438 25019 my ($self, $obj) = @_;
439 25019 my @res;
440  
441 encode_error("json text or perl structure exceeds maximum nesting level (max_depth set too low?)")
442 25019 ▶ if (++$self->{depth} > $self->{max_depth});
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"depth"} > $self->{"max_depth"} 1 25018 25019
443  
444 25018 ▶ my ($pre, $post) = $self->{PROPS}[P_INDENT] ? $self->_up_indent() : ('', '');
Branch: 1 branch
BranchTrueFalseTotal
$self->{'PROPS'}[3] ? : 2 25016 25018
445  
446 25018 for my $v (@$obj){
447 25807 ▶ push @res, ref($v) ? $self->object_to_json($v) : $self->value_to_json($v);
Branch: 1 branch
BranchTrueFalseTotal
ref $v ? : 315 25492 25807
448 }
449  
450 25004 --$self->{depth};
451 25004 ▶ $self->_down_indent() if ($self->{PROPS}[P_INDENT]);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[3] 2 25002 25004
452  
453 25004 ▶ return '[]' unless @res;
Branch: 1 branch
BranchTrueFalseTotal
unless @res 10 24994 25004
454 24994 ▶ my $space = $pre eq '' && $self->{PROPS}[P_SPACE_AFTER] ? ' ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$pre eq '' && $self->{'PROPS'}[6] ? : 0 24994 24994
Condition66%2/3
$pre eq "" and $self->{"PROPS"}[6]
!ll&&!rl&&r
2249920
MC/DC0%0/2
$pre eq "" and $self->{"PROPS"}[6]
$pre eq "" $self->{"PROPS"}[6]
Truth table66%2/3
A and B
A= $pre eq ""B= $self->{"PROPS"}[6]
ABresult
0X0
100
111
455 24994 return '[' . $pre . join( ",$space$pre", @res ) . $post . ']';
456 }
457  
458 26135 ▶ sub _looks_like_number {
Subroutine _looks_like_number: called CC=5 SCAR=16.3
459 26135 my $value = shift;
460 26135 if (USE_B) {
461 my $b_obj = B::svref_2object(\$value);
462 my $flags = $b_obj->FLAGS;
463 return 1 if $flags & ( B::SVp_IOK() | B::SVp_NOK() ) and !( $flags & B::SVp_POK() );
464 return;
465 } else {
466 57 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
467 # if the utf8 flag is on, it almost certainly started as a string
468 26135 ▶ return if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 12487 13648 26135
469 # detect numbers
470 # string & "" -> ""
471 # number & "" -> 0 (with warning)
472 # nan and inf can detect as numbers, so check with * 0
473 13648 ▶ return unless length((my $dummy = "") & $value);
Branch: 1 branch
BranchTrueFalseTotal
unless length((my $dummy = "") & $value) 12851 797 13648
474 797 ▶ return unless 0 + $value eq $value;
Branch: 1 branch
BranchTrueFalseTotal
unless 0 + $value eq $value 0 797 797
475 797 ▶ return 1 if $value * 0 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value * 0 == 0 797 0 797
476 0 return -1; # inf/nan
477 }
478 }
479  
480 26224 ▶ sub value_to_json {
Subroutine value_to_json: called CC=18 SCAR=28.9
Pod undocumented
481 26224 my ($self, $value) = @_;
482  
483 26224 ▶ return 'null' if(!defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 45 26179 26224
484  
485 26179 my $type = ref($value);
486  
487 26179 ▶ if (!$type) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $type) { } 26141 38 26179
elsif (builtin::blessed($value) and $value->isa('JSON::PP::Boolean')) { } 18 20 38
488 57 ▶ BEGIN { CORE_BOOL and warnings->unimport('experimental::builtin') }
Subroutine BEGIN: called CC=1 SCAR=0.0
489 26141 ▶ if (CORE_BOOL && builtin::is_bool($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (builtin::is_bool($value)) { } 6 26135 26141
elsif (_looks_like_number($value)) { } 797 25338 26135
490 6 ▶ return $value ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 3 3 6
491 }
492 elsif (_looks_like_number($value)) {
493 797 return $value;
494 }
495 25338 return $self->string_to_json($value);
496 }
497 ▶ elsif( blessed($value) and $value->isa('JSON::PP::Boolean') ){
Condition66%2/3
builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
!ll&&!rl&&r
20018
MC/DC50%1/2
builtin::blessed($value) and $value->isa("JSON::PP::Boolean")
builtin::blessed($value) $value->isa("JSON::PP::Boolean")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("JSON::PP::Boolean")
ABresult
0X0
100
111
498 18 ▶ return $$value == 1 ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$$value == 1 ? : 9 9 18
499 }
500 else {
501 20 ▶ if ((overload::StrVal($value) =~ /=(\w+)/)[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ((overload::StrVal($value) =~ /=(\w+)/)[0]) 0 20 20
502 0 return $self->value_to_json("$value");
503 }
504  
505 20 ▶ if ($type eq 'SCALAR' and defined $$value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "SCALAR" and defined $$value) 7 13 20
Condition100%3/3
$type eq "SCALAR" and defined $$value
!ll&&!rl&&r
1037
MC/DC100%2/2
$type eq "SCALAR" and defined $$value
$type eq "SCALAR" defined $$value
Truth table100%3/3
A and B
A= $type eq "SCALAR"B= defined $$value
ABresult
0X0
100
111
506 return $$value eq '1' ? 'true'
507 : $$value eq '0' ? 'false'
508 7 ▶ : $self->{PROPS}->[ P_ALLOW_UNKNOWN ] ? 'null'
Branch: 3 branches
BranchTrueFalseTotal
$$value eq '1' ? : 1 6 7
$$value eq '0' ? : 1 5 6
$self->{'PROPS'}[18] ? : 1 4 5
509 : encode_error("cannot encode reference to scalar");
510 }
511  
512 13 ▶ if ( $self->{PROPS}->[ P_ALLOW_UNKNOWN ] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROPS'}[18]) { } 4 9 13
513 4 return 'null';
514 }
515 else {
516 9 ▶ if ( $type eq 'SCALAR' or $type eq 'REF' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'SCALAR' or $type eq 'REF') { } 6 3 9
Condition100%3/3
$type eq "SCALAR" or $type eq "REF"
l!l&&r!l&&!r
243
MC/DC100%2/2
$type eq "SCALAR" or $type eq "REF"
$type eq "SCALAR" $type eq "REF"
Truth table100%3/3
A or B
A= $type eq "SCALAR"B= $type eq "REF"
ABresult
1X1
011
000
517 6 encode_error("cannot encode reference to scalar");
518 }
519 else {
520 3 encode_error("encountered $value, but JSON can only represent references to arrays or hashes");
521 }
522 }
523  
524 }
525 }
526  
527  
528 57 my %esc = (
529 "\n" => '\n',
530 "\r" => '\r',
531 "\t" => '\t',
532 "\f" => '\f',
533 "\b" => '\b',
534 "\"" => '\"',
535 "\\" => '\\\\',
536 "\'" => '\\\'',
537 );
538  
539  
540 26001 ▶ sub string_to_json {
Subroutine string_to_json: called CC=5 SCAR=16.1
Pod undocumented
541 26001 my ($self, $arg) = @_;
542  
543 26001 $arg =~ s/(["\\\n\r\t\f\b])/$esc{$1}/g;
544 26001 ▶ $arg =~ s/\//\\\//g if ($self->{PROPS}[P_ESCAPE_SLASH]);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[16] 1 26000 26001
545  
546 # On ASCII platforms, matches [\x00-\x08\x0b\x0e-\x1f]
547 26001 $arg =~ s/([^\n\t\c?[:^cntrl:][:^ascii:]])/'\\u00' . unpack('H2', $1)/eg;
548  
549 26001 ▶ if ($self->{PROPS}[P_ASCII]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[0]) 12297 13704 26001
550 12297 $arg = _encode_ascii($arg);
551 }
552  
553 26001 ▶ if ($self->{PROPS}[P_LATIN1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[1]) 2 25999 26001
554 2 $arg = _encode_latin1($arg);
555 }
556  
557 26001 ▶ if ($self->{PROPS}[P_UTF8]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[2]) 12545 13456 26001
558 12545 utf8::encode($arg);
559 }
560  
561 26001 return '"' . $arg . '"';
562 }
563  
564  
565 0 ▶ sub blessed_to_json {
Subroutine blessed_to_json: not called CC=4 SCAR=30.0
Pod undocumented
566 0 ▶ my $reftype = reftype($_[1]) || '';
Condition0%0/2
builtin::reftype($_[1]) || ''
l!l
00
MC/DC0%0/1
builtin::reftype($_[1]) || ''
builtin::reftype($_[1])
Truth table0%0/2
A
A= builtin::reftype($_[1])
Aresult
11
00
567 0 ▶ if ($reftype eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 0 0 0
elsif ($reftype eq 'ARRAY') { } 0 0 0
568 0 return $_[0]->hash_to_json($_[1]);
569 }
570 elsif ($reftype eq 'ARRAY') {
571 0 return $_[0]->array_to_json($_[1]);
572 }
573 else {
574 0 return 'null';
575 }
576 }
577  
578  
579 18 ▶ sub encode_error {
Subroutine encode_error: called CC=1 SCAR=0.0
Pod undocumented
580 18 my $error = shift;
581 18 Carp::croak "$error";
582 }
583  
584  
585 342 ▶ sub __sort {
Subroutine __sort: called CC=2 SCAR=6.9
586 342 my $self = shift;
587 342 my $keysort = $self->{keysort};
588 342 ▶ defined $keysort ? (sort $keysort (keys %{$_[0]})) : keys %{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
defined $keysort ? : 222 120 342
589 }
590  
591  
592 9 ▶ sub _up_indent {
Subroutine _up_indent: called CC=1 SCAR=0.0
593 9 my $self = shift;
594 9 my $space = ' ' x $self->{indent_length};
595  
596 9 my ($pre,$post) = ('','');
597  
598 9 $post = "\n" . $space x $self->{indent_count};
599  
600 9 $self->{indent_count}++;
601  
602 9 $pre = "\n" . $space x $self->{indent_count};
603  
604 9 return ($pre,$post);
605 }
606  
607  
608 9 ▶ sub _down_indent { $_[0]->{indent_count}--; }
Subroutine _down_indent: called CC=1 SCAR=0.0
609  
610 } # Convert
611  
612  
613 57 ▶sub _encode_ascii {
Subroutine _encode_ascii: called CC=3 SCAR=11.0
614 join('',
615 map {
616 12297 ▶ chr($_) =~ /[[:ascii:]]/ ?
Branch: 2 branches
BranchTrueFalseTotal
chr($_) =~ /[[:ascii:]]/ ? : 2824908 3440033 6264941
$_ <= 65535 ? : 2312298 1127735 3440033
617 chr($_) :
618 $_ <= 65535 ?
619 sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_));
620 } unpack('U*', $_[0])
621 );
622 }
623  
624  
625 2 ▶sub _encode_latin1 {
Subroutine _encode_latin1: called CC=3 SCAR=11.1
626 join('',
627 map {
628 2 ▶ $_ <= 255 ?
Branch: 2 branches
BranchTrueFalseTotal
$_ <= 255 ? : 21 1 22
$_ <= 65535 ? : 1 0 1
629 chr($_) :
630 $_ <= 65535 ?
631 sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_));
632 } unpack('U*', $_[0])
633 );
634 }
635  
636  
637 1127735 ▶sub _encode_surrogates { # from perlunicode
Subroutine _encode_surrogates: called CC=1 SCAR=0.0
638 1127735 my $uni = $_[0] - 0x10000;
639 1127735 return ($uni / 0x400 + 0xD800, $uni % 0x400 + 0xDC00);
640 }
641  
642  
643 2 ▶sub _is_bignum {
Subroutine _is_bignum: called CC=2 SCAR=6.9
644 2 ▶ $_[0]->isa('Math::BigInt') or $_[0]->isa('Math::BigFloat');
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("Math::BigInt") or $_[0]->isa("Math::BigFloat") 1 1 2
645 }
646  
647  
648  
649 #
650 # JSON => Perl
651 #
652  
653 57 my $max_intsize;
654  
655 57 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
656 57 my $checkint = 1111;
657 57 for my $d (5..64) {
658 969 $checkint .= 1;
659 969 my $int = eval qq| $checkint |;
660 969 ▶ if ($int =~ /[eE]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int =~ /[eE]/) 57 912 969
661 57 $max_intsize = $d - 1;
662 57 last;
663 }
664 }
665 }
666  
667 { # PARSE
668  
669 57 my %escapes = ( # by Jeremy Muhlich <jmuhlich [at] bitflood.org>
670 b => "\b",
671 t => "\t",
672 n => "\n",
673 f => "\f",
674 r => "\r",
675 '\\' => '\\',
676 '"' => '"',
677 '/' => '/',
678 );
679  
680 12453 ▶ sub _detect_utf_encoding {
Subroutine _detect_utf_encoding: called CC=10 SCAR=25.0
681 12453 my $text = shift;
682 12453 my @octets = unpack('C4', $text);
683 12453 ▶ return 'unknown' unless defined $octets[3];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $octets[3] 15 12438 12453
684 12438 ▶ return ( $octets[0] and $octets[1]) ? 'UTF-8'
Branch: 5 branches
BranchTrueFalseTotal
$octets[0] && $octets[1] ? : 12435 3 12438
!$octets[0] && $octets[1] ? : 1 2 3
!($octets[0] || $octets[1]) ? : 0 2 2
$octets[2] ? : 2 0 2
!$octets[2] ? : 0 0 0
Condition66%6/9
$octets[0] and $octets[1]
!ll&&!rl&&r
1212435
not $octets[0] and $octets[1]
!ll&&!rl&&r
201
$octets[0] || $octets[1]
l!l&&r!l&&!r
200
MC/DC100%2/2
$octets[0] and $octets[1]
$octets[0] $octets[1]
MC/DC50%1/2
not $octets[0] and $octets[1]
not $octets[0] $octets[1]
MC/DC0%0/2
$octets[0] || $octets[1]
$octets[0] $octets[1]
Truth table100%3/3
A and B
A= $octets[0]B= $octets[1]
ABresult
0X0
100
111
Truth table66%2/3
not(A) and B
A= not $octets[0]B= $octets[1]
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $octets[0]B= $octets[1]
ABresult
1X1
011
000
685 : (!$octets[0] and $octets[1]) ? 'UTF-16BE'
686 : (!$octets[0] and !$octets[1]) ? 'UTF-32BE'
687 : ( $octets[2] ) ? 'UTF-16LE'
688 : (!$octets[2] ) ? 'UTF-32LE'
689 : 'unknown';
690 }
691  
692 25265 ▶ sub PP_decode_json {
Subroutine PP_decode_json: called CC=16 SCAR=27.7
Pod undocumented
693 25265 my ($self, $text, $want_offset) = @_;
694  
695 25265 @$self{qw/at ch depth/} = (0, '', 0);
696  
697 25265 ▶ if ( !defined $text or ref $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $text or ref $text) 4 25261 25265
Condition100%3/3
not defined $text or ref $text
l!l&&r!l&&!r
1325261
MC/DC100%2/2
not defined $text or ref $text
not defined $text ref $text
Truth table100%3/3
not(A) or B
A= not defined $textB= ref $text
ABresult
1X1
011
000
698 4 $self->_decode_error("malformed JSON string, neither array, object, number, string or atom");
699 }
700  
701 25261 my $props = $self->{PROPS};
702  
703 25261 ▶ if ( $self->{PROPS}[P_UTF8] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROPS'}[2]) { } 12453 12808 25261
704 12453 my $encoding = _detect_utf_encoding($text);
705 12453 ▶ if ($encoding ne 'UTF-8' and $encoding ne 'unknown') {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding ne 'UTF-8' and $encoding ne 'unknown') { } 3 12450 12453
Condition100%3/3
$encoding ne "UTF-8" and $encoding ne "unknown"
!ll&&!rl&&r
12435153
MC/DC100%2/2
$encoding ne "UTF-8" and $encoding ne "unknown"
$encoding ne "UTF-8" $encoding ne "unknown"
Truth table100%3/3
A and B
A= $encoding ne "UTF-8"B= $encoding ne "unknown"
ABresult
0X0
100
111
706 3 require Encode;
707 3 Encode::from_to($text, $encoding, 'utf-8');
708 } else {
709 12450 ▶ utf8::downgrade( $text, 1 ) or Carp::croak("Wide character in subroutine entry");
Branch: 1 branch
BranchTrueFalseTotal
utf8::downgrade($text, 1) or Carp::croak("Wide character in subroutine entry") 12450 0 12450
710 }
711 }
712 else {
713 12808 utf8::encode( $text );
714 }
715  
716 25261 $self->{len} = length $text;
717 25261 $self->{text} = $text;
718  
719 25261 ▶ if ($self->{max_size} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_size"} > 1) 2 25259 25261
720 57 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
721 2 my $bytes = length $text;
722 $self->_decode_error(
723 sprintf("attempted decode of JSON text of %s bytes size, but max_size is set to %s"
724 , $bytes, $self->{max_size}), 1
725 2 ▶ ) if ($bytes > $self->{max_size});
Branch: 1 branch
BranchTrueFalseTotal
if $bytes > $self->{"max_size"} 1 1 2
726 }
727  
728 25260 $self->_white(); # remove head white space
729  
730 25260 ▶ $self->_decode_error("malformed JSON string, neither array, object, number, string or atom") unless defined $self->{ch}; # Is there a first character for JSON structure?
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"ch"} 2 25258 25260
731  
732 25258 my $result = $self->_value();
733  
734 25188 ▶ if ( !$props->[ P_ALLOW_NONREF ] and !ref $result ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($props->[7] or ref $result) 4 25184 25188
Condition100%3/3
$props->[7] or ref $result
l!l&&r!l&&!r
249861984
MC/DC100%2/2
$props->[7] or ref $result
$props->[7] ref $result
Truth table100%3/3
A or B
A= $props->[7]B= ref $result
ABresult
1X1
011
000
735 4 $self->_decode_error(
736 'JSON text must be an object or array (but found number, string, true, false or null,'
737 . ' use allow_nonref to allow this)', 1);
738 }
739  
740 25184 ▶ Carp::croak('something wrong.') if $self->{len} < $self->{at}; # we won't arrive here.
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"len"} < $self->{"at"} 0 25184 25184
741  
742 25184 ▶ my $consumed = defined $self->{ch} ? $self->{at} - 1 : $self->{at}; # consumed JSON text length
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'ch'} ? : 293 24891 25184
743  
744 25184 $self->_white(); # remove tail white space
745  
746 25184 ▶ return ( $result, $consumed ) if $want_offset; # all right if decode_prefix
Branch: 1 branch
BranchTrueFalseTotal
if $want_offset 275 24909 25184
747  
748 24909 ▶ $self->_decode_error("garbage after JSON object") if defined $self->{ch};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ch"} 7 24902 24909
749  
750 24902 $result;
751 }
752  
753  
754 36716614 ▶ sub _next_chr {
Subroutine _next_chr: called CC=2 SCAR=6.9
755 36716614 my $self = shift;
756 36716614 ▶ return $self->{ch} = undef if($self->{at} >= $self->{len});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"at"} >= $self->{"len"} 25085 36691529 36716614
757 36691529 $self->{ch} = substr($self->{text}, $self->{at}++, 1);
758 }
759  
760  
761 55786 ▶ sub _value {
Subroutine _value: called CC=10 SCAR=23.1
762 55786 my $self = shift;
763 55786 $self->_white();
764 55786 my $ch = $self->{ch};
765 55786 ▶ return if(!defined $ch);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ch 0 55786 55786
766 55786 ▶ return $self->_object() if($ch eq '{');
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "{" 2170 53616 55786
767 53616 ▶ return $self->_array() if($ch eq '[');
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "[" 26287 27329 53616
768 27329 ▶ return $self->_tag() if($ch eq '(');
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "(" 0 27329 27329
769 27329 ▶ return $self->_string() if($ch eq '"' or ($self->{PROPS}[P_ALLOW_SINGLEQUOTE] and $ch eq "'"));
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'" 26352 977 27329
Condition83%5/6
$ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'"
l!l&&r!l&&!r
263502977
$self->{"PROPS"}[15] and $ch eq "'"
!ll&&!rl&&r
97702
MC/DC66%2/3
$ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'"
$ch eq "\"" $self->{"PROPS"}[15] $ch eq "'"
Truth table75%3/4
A or B and C
A= $ch eq "\""B= $self->{"PROPS"}[15]C= $ch eq "'"
ABCresult
1XX1
0111
00X0
0100
770 977 ▶ return $self->_number() if($ch =~ /[0-9]/ or $ch eq '-');
Branch: 1 branch
BranchTrueFalseTotal
if $ch =~ /[0-9]/ or $ch eq "-" 891 86 977
Condition100%3/3
$ch =~ /[0-9]/ or $ch eq "-"
l!l&&r!l&&!r
8504186
MC/DC100%2/2
$ch =~ /[0-9]/ or $ch eq "-"
$ch =~ /[0-9]/ $ch eq "-"
Truth table100%3/3
A or B
A= $ch =~ /[0-9]/B= $ch eq "-"
ABresult
1X1
011
000
771 86 return $self->_word();
772 }
773  
774 29811 ▶ sub _string {
Subroutine _string: called CC=27 SCAR=33.3
775 29811 my $self = shift;
776 29811 my $utf16;
777 my $is_utf8;
778  
779 29811 my $utf8_len = 0;
780  
781 29811 my $s = ''; # basically UTF8 flag on
782  
783 29811 my $ch = $self->{ch};
784 29811 ▶ if($ch eq '"' or ($self->{PROPS}[P_ALLOW_SINGLEQUOTE] and $ch eq "'")){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'") 29806 5 29811
Condition83%5/6
$ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'"
l!l&&r!l&&!r
2980245
$self->{"PROPS"}[15] and $ch eq "'"
!ll&&!rl&&r
504
MC/DC66%2/3
$ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'"
$ch eq "\"" $self->{"PROPS"}[15] $ch eq "'"
Truth table75%3/4
A or B and C
A= $ch eq "\""B= $self->{"PROPS"}[15]C= $ch eq "'"
ABCresult
1XX1
0111
00X0
0100
785 29806 my $boundChar = $ch;
786  
787 29806 ▶ OUTER: while( defined($ch = $self->_next_chr()) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($ch = $self->_next_chr)) 10674829 1 10674830
788  
789 10674829 ▶ if($ch eq $boundChar){
Branch: 2 branches
BranchTrueFalseTotal
if ($ch eq $boundChar) { } 29791 10645038 10674829
elsif ($ch eq '\\') { } 5302021 5343017 10645038
790 29791 $self->_next_chr();
791  
792 29791 ▶ if ($utf16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($utf16) 1 29790 29791
793 1 $self->_decode_error("missing low surrogate character in surrogate pair");
794 }
795  
796 29790 ▶ utf8::decode($s) if($is_utf8);
Branch: 1 branch
BranchTrueFalseTotal
if $is_utf8 24802 4988 29790
797  
798 29790 return $s;
799 }
800 elsif($ch eq '\\'){
801 5302021 $ch = $self->_next_chr();
802 5302021 ▶ if(exists $escapes{$ch}){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $escapes{$ch}) { } 153373 5148648 5302021
elsif ($ch eq 'u') { } 5148644 4 5148648
803 153373 $s .= $escapes{$ch};
804 }
805 elsif($ch eq 'u'){ # UNICODE handling
806 5148644 my $u = '';
807  
808 5148644 for(1..4){
809 20594576 $ch = $self->_next_chr();
810 20594576 ▶ last OUTER if($ch !~ /[0-9a-fA-F]/);
Branch: 1 branch
BranchTrueFalseTotal
unless $ch =~ /[0-9a-fA-F]/ 0 20594576 20594576
811 20594576 $u .= $ch;
812 }
813  
814 # U+D800 - U+DBFF
815 5148644 ▶ if ($u =~ /^[dD][89abAB][0-9a-fA-F]{2}/) { # UTF-16 high surrogate?
Branch: 2 branches
BranchTrueFalseTotal
if ($u =~ /^[dD][89abAB][0-9a-fA-F]{2}/) { } 1127737 4020907 5148644
elsif ($u =~ /^[dD][c-fC-F][0-9a-fA-F]{2}/) { } 1127736 2893171 4020907
816 1127737 $utf16 = $u;
817 }
818 # U+DC00 - U+DFFF
819 elsif ($u =~ /^[dD][c-fC-F][0-9a-fA-F]{2}/) { # UTF-16 low surrogate?
820 1127736 ▶ unless (defined $utf16) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $utf16) 1 1127735 1127736
821 1 $self->_decode_error("missing high surrogate character in surrogate pair");
822 }
823 1127735 $is_utf8 = 1;
824 1127735 ▶ $s .= _decode_surrogates($utf16, $u) || next;
Condition50%1/2
_decode_surrogates($utf16, $u) || (next)
l!l
11277350
MC/DC0%0/1
_decode_surrogates($utf16, $u) || (next)
_decode_surrogates($utf16, $u)
Truth table50%1/2
A
A= _decode_surrogates($utf16, $u)
Aresult
11
00
825 1127735 $utf16 = undef;
826 }
827 else {
828 2893171 ▶ if (defined $utf16) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $utf16) 1 2893170 2893171
829 1 $self->_decode_error("surrogate pair expected");
830 }
831  
832 2893170 my $hex = hex( $u );
833 2893170 ▶ if ( chr $u =~ /[[:^ascii:]]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (chr $u =~ /[[:^ascii:]]/) { } 2893170 0 2893170
834 2893170 $is_utf8 = 1;
835 2893170 ▶ $s .= _decode_unicode($u) || next;
Condition50%1/2
_decode_unicode($u) || (next)
l!l
28931700
MC/DC0%0/1
_decode_unicode($u) || (next)
_decode_unicode($u)
Truth table50%1/2
A
A= _decode_unicode($u)
Aresult
11
00
836 }
837 else {
838 0 $s .= chr $hex;
839 }
840 }
841  
842 }
843 else{
844 4 ▶ unless ($self->{PROPS}[P_LOOSE]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"PROPS"}[12]) 4 0 4
845 4 $self->{at} -= 2;
846 4 $self->_decode_error('illegal backslash escape sequence in string');
847 }
848 0 $s .= $ch;
849 }
850 }
851 else{
852  
853 5343017 ▶ if ( $ch =~ /[[:^ascii:]]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /[[:^ascii:]]/) 3440092 1902925 5343017
854 3440092 ▶ unless( $ch = $self->_is_valid_utf8($ch, \$utf8_len) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch = $self->_is_valid_utf8($ch, \$utf8_len)) { } 3440088 4 3440092
855 4 $self->{at} -= 1;
856 4 $self->_decode_error("malformed UTF-8 character in JSON string");
857 }
858 else {
859 3440088 $self->{at} += $utf8_len - 1;
860 }
861  
862 3440088 $is_utf8 = 1;
863 }
864  
865 5343013 ▶ if (!$self->{PROPS}[P_LOOSE]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"PROPS"}[12]) 5343013 0 5343013
866 5343013 ▶ if ($ch =~ $invalid_char_re) { # '/' ok
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /$invalid_char_re/) 4 5343009 5343013
867 4 ▶ if (!$self->{PROPS}[P_RELAXED] or $ch ne "\t") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"PROPS"}[11] or $ch ne "\t") 4 0 4
Condition33%1/3
not $self->{"PROPS"}[11] or $ch ne "\t"
l!l&&r!l&&!r
400
MC/DC0%0/2
not $self->{"PROPS"}[11] or $ch ne "\t"
not $self->{"PROPS"}[11] $ch ne "\t"
Truth table33%1/3
not(A) or B
A= not $self->{"PROPS"}[11]B= $ch ne "\t"
ABresult
1X1
011
000
868 4 $self->{at}--;
869 4 $self->_decode_error(sprintf "invalid character 0x%X"
870 . " encountered while parsing JSON string",
871 ord $ch);
872 }
873 }
874 }
875  
876 5343009 $s .= $ch;
877 }
878 }
879 }
880  
881 6 $self->_decode_error("unexpected end of string while parsing JSON string");
882 }
883  
884  
885 169700 ▶ sub _white {
Subroutine _white: called CC=19 SCAR=46.5
886 169700 my $self = shift;
887 169700 my $ch = $self->{ch};
888 169700 ▶ while( defined $ch ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 197222 25077 222299
889 197222 ▶ if($ch eq '' or $ch =~ /\A[ \t\r\n]\z/){
Branch: 2 branches
BranchTrueFalseTotal
if ($ch eq '' or $ch =~ /\A[ \t\r\n]\z/) { } 52590 144632 197222
elsif ($self->{'PROPS'}[11] and $ch eq '/') { } 0 144632 144632
Condition100%3/3
$ch eq "" or $ch =~ /\A[ \t\r\n]\z/
l!l&&r!l&&!r
2526027330144632
MC/DC100%2/2
$ch eq "" or $ch =~ /\A[ \t\r\n]\z/
$ch eq "" $ch =~ /\A[ \t\r\n]\z/
Truth table100%3/3
A or B
A= $ch eq ""B= $ch =~ /\A[ \t\r\n]\z/
ABresult
1X1
011
000
890 52590 $ch = $self->_next_chr();
891 }
892 ▶ elsif($self->{PROPS}[P_RELAXED] and $ch eq '/'){
Condition66%2/3
$self->{"PROPS"}[11] and $ch eq "/"
!ll&&!rl&&r
1445291030
MC/DC0%0/2
$self->{"PROPS"}[11] and $ch eq "/"
$self->{"PROPS"}[11] $ch eq "/"
Truth table66%2/3
A and B
A= $self->{"PROPS"}[11]B= $ch eq "/"
ABresult
0X0
100
111
893 0 $ch = $self->_next_chr();
894 0 ▶ if(defined $ch and $ch eq '/'){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ch and $ch eq '/') { } 0 0 0
elsif (defined $ch and $ch eq '*') { } 0 0 0
Condition0%0/3
defined $ch and $ch eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ch and $ch eq "/"
defined $ch $ch eq "/"
Truth table0%0/3
A and B
A= defined $chB= $ch eq "/"
ABresult
0X0
100
111
895 0 ▶ 1 while(defined($ch = $self->_next_chr()) and $ch ne "\n" and $ch ne "\r");
Branch: 1 branch
BranchTrueFalseTotal
defined($ch = $self->_next_chr) and $ch ne "\n" and $ch ne "\r" and do { '???' } 0 0 0
Condition0%0/6
defined($ch = $self->_next_chr) and $ch ne "\n" and $ch ne "\r"
!ll&&!rl&&r
000
defined($ch = $self->_next_chr) and $ch ne "\n"
!ll&&!rl&&r
000
MC/DC0%0/3
defined($ch = $self->_next_chr) and $ch ne "\n" and $ch ne "\r"
defined($ch = $self->_next_chr) $ch ne "\n" $ch ne "\r"
Truth table0%0/4
A and B and C
A= defined($ch = $self->_next_chr)B= $ch ne "\n"C= $ch ne "\r"
ABCresult
0XX0
10X0
1100
1111
896 }
897 ▶ elsif(defined $ch and $ch eq '*'){
Condition0%0/3
defined $ch and $ch eq "*"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ch and $ch eq "*"
defined $ch $ch eq "*"
Truth table0%0/3
A and B
A= defined $chB= $ch eq "*"
ABresult
0X0
100
111
898 0 $ch = $self->_next_chr();
899 0 while(1){
900 0 ▶ if(defined $ch){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) { } 0 0 0
901 0 ▶ if($ch eq '*'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq '*') { } 0 0 0
902 0 ▶ if(defined($ch = $self->_next_chr()) and $ch eq '/'){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($ch = $self->_next_chr) and $ch eq "/") 0 0 0
Condition0%0/3
defined($ch = $self->_next_chr) and $ch eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
defined($ch = $self->_next_chr) and $ch eq "/"
defined($ch = $self->_next_chr) $ch eq "/"
Truth table0%0/3
A and B
A= defined($ch = $self->_next_chr)B= $ch eq "/"
ABresult
0X0
100
111
903 0 $ch = $self->_next_chr();
904 0 last;
905 }
906 }
907 else{
908 0 $ch = $self->_next_chr();
909 }
910 }
911 else{
912 0 $self->_decode_error("Unterminated comment");
913 }
914 }
915 0 next;
916 }
917 else{
918 0 $self->{at}--;
919 0 $self->_decode_error("malformed JSON string, neither array, object, number, string or atom");
920 }
921 }
922 else{
923 144632 ▶ if ($self->{PROPS}[P_RELAXED] and $ch eq '#') { # correctly?
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[11] and $ch eq "#") 9 144623 144632
Condition100%3/3
$self->{"PROPS"}[11] and $ch eq "#"
!ll&&!rl&&r
144529949
MC/DC100%2/2
$self->{"PROPS"}[11] and $ch eq "#"
$self->{"PROPS"}[11] $ch eq "#"
Truth table100%3/3
A and B
A= $self->{"PROPS"}[11]B= $ch eq "#"
ABresult
0X0
100
111
924 9 pos($self->{text}) = $self->{at};
925 9 $self->{text} =~ /\G([^\n]*(?:\r\n|\r|\n|$))/g;
926 9 $self->{at} = pos($self->{text});
927 9 $ch = $self->_next_chr;
928 9 next;
929 }
930  
931 144623 last;
932 }
933 }
934 }
935  
936  
937 26287 ▶ sub _array {
Subroutine _array: called CC=13 SCAR=25.7
938 26287 my $self = shift;
939 26287 ▶ my $a = $_[0] || []; # you can use this code to use another array ref object.
Condition50%1/2
$_[0] || []
l!l
026287
MC/DC0%0/1
$_[0] || []
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
940  
941 $self->_decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)')
942 26287 ▶ if (++$self->{depth} > $self->{max_depth});
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"depth"} > $self->{"max_depth"} 3 26284 26287
943  
944 26284 $self->_next_chr();
945 26284 $self->_white();
946  
947 26284 my $ch = $self->{ch};
948 26284 ▶ if(defined $ch and $ch eq ']'){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch and $ch eq ']') { } 22 26262 26284
Condition66%2/3
defined $ch and $ch eq "]"
!ll&&!rl&&r
02626222
MC/DC50%1/2
defined $ch and $ch eq "]"
defined $ch $ch eq "]"
Truth table66%2/3
A and B
A= defined $chB= $ch eq "]"
ABresult
0X0
100
111
949 22 --$self->{depth};
950 22 $self->_next_chr();
951 22 return $a;
952 }
953 else {
954 26262 ▶ while(defined($ch)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 27075 0 27075
955 27075 push @$a, $self->_value();
956  
957 26508 $self->_white();
958  
959 26508 $ch = $self->{ch};
960 26508 ▶ if (!defined $ch) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ch) 3 26505 26508
961 3 last;
962 }
963  
964 26505 ▶ if($ch eq ']'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "]") 25688 817 26505
965 25688 --$self->{depth};
966 25688 $self->_next_chr();
967 25688 return $a;
968 }
969  
970 817 ▶ if($ch ne ','){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch ne ",") 2 815 817
971 2 last;
972 }
973  
974 815 $self->_next_chr();
975 815 $self->_white();
976  
977 815 $ch = $self->{ch};
978 815 ▶ if ($self->{PROPS}[P_RELAXED] and $ch eq ']') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[11] and $ch eq "]") 2 813 815
Condition100%3/3
$self->{"PROPS"}[11] and $ch eq "]"
!ll&&!rl&&r
80492
MC/DC100%2/2
$self->{"PROPS"}[11] and $ch eq "]"
$self->{"PROPS"}[11] $ch eq "]"
Truth table100%3/3
A and B
A= $self->{"PROPS"}[11]B= $ch eq "]"
ABresult
0X0
100
111
979 2 --$self->{depth};
980 2 $self->_next_chr();
981 2 return $a;
982 }
983  
984 }
985 }
986  
987 5 ▶ $self->{at}-- if defined $ch and $ch ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $ch and $ch ne "" 2 3 5
Condition66%2/3
defined $ch and $ch ne ""
!ll&&!rl&&r
302
MC/DC50%1/2
defined $ch and $ch ne ""
defined $ch $ch ne ""
Truth table66%2/3
A and B
A= defined $chB= $ch ne ""
ABresult
0X0
100
111
988 5 $self->_decode_error(", or ] expected while parsing array");
989 }
990  
991 0 ▶ sub _tag {
Subroutine _tag: not called CC=10 SCAR=47.0
992 0 my $self = shift;
993 0 ▶ $self->_decode_error('malformed JSON string, neither array, object, number, string or atom') unless $self->{PROPS}[P_ALLOW_TAGS];
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"PROPS"}[19] 0 0 0
994  
995 0 $self->_next_chr();
996 0 $self->_white();
997  
998 0 my $tag = $self->_value();
999 0 ▶ return unless defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 0 0 0
1000 0 ▶ $self->_decode_error('malformed JSON string, (tag) must be a string') if ref $tag;
Branch: 1 branch
BranchTrueFalseTotal
if ref $tag 0 0 0
1001  
1002 0 $self->_white();
1003  
1004 0 my $ch = $self->{ch};
1005 0 ▶ if (!defined $ch or $ch ne ')') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ch or $ch ne ")") 0 0 0
Condition0%0/3
not defined $ch or $ch ne ")"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $ch or $ch ne ")"
not defined $ch $ch ne ")"
Truth table0%0/3
not(A) or B
A= not defined $chB= $ch ne ")"
ABresult
1X1
011
000
1006 0 $self->_decode_error(') expected after tag');
1007 }
1008  
1009 0 $self->_next_chr();
1010 0 $self->_white();
1011  
1012 0 my $val = $self->_value();
1013 0 ▶ return unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
1014 0 ▶ $self->_decode_error('malformed JSON string, tag value must be an array') unless ref $val eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val eq "ARRAY" 0 0 0
1015  
1016 0 ▶ if (!eval { $tag->can('THAW') }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $tag->can("THAW") } }) 0 0 0
1017 0 ▶ $self->_decode_error('cannot decode perl-object (package does not exist)') if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1018 0 $self->_decode_error('cannot decode perl-object (package does not have a THAW method)');
1019 }
1020 0 $tag->THAW('JSON', @$val);
1021 }
1022  
1023 2170 ▶ sub _object {
Subroutine _object: called CC=21 SCAR=30.7
1024 2170 my $self = shift;
1025 2170 ▶ my $o = $_[0] || {}; # you can use this code to use another hash ref object.
Condition50%1/2
$_[0] || {}
l!l
02170
MC/DC0%0/1
$_[0] || {}
$_[0]
Truth table50%1/2
A
A= $_[0]
Aresult
11
00
1026 2170 my $k;
1027  
1028 $self->_decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)')
1029 2170 ▶ if (++$self->{depth} > $self->{max_depth});
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"depth"} > $self->{"max_depth"} 0 2170 2170
1030 2170 $self->_next_chr();
1031 2170 $self->_white();
1032  
1033 2170 my $ch = $self->{ch};
1034 2170 ▶ if(defined $ch and $ch eq '}'){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch and $ch eq '}') { } 8 2162 2170
Condition66%2/3
defined $ch and $ch eq "}"
!ll&&!rl&&r
021628
MC/DC50%1/2
defined $ch and $ch eq "}"
defined $ch $ch eq "}"
Truth table66%2/3
A and B
A= defined $chB= $ch eq "}"
ABresult
0X0
100
111
1035 8 --$self->{depth};
1036 8 $self->_next_chr();
1037 8 ▶ if ($self->{F_HOOK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"F_HOOK"}) 1 7 8
1038 1 return $self->__json_object_hook($o);
1039 }
1040 7 return $o;
1041 }
1042 else {
1043 2162 ▶ while (defined $ch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 3461 1 3462
1044 3461 ▶ $k = ($self->{PROPS}[P_ALLOW_BAREKEY] and $ch ne '"' and $ch ne "'") ? $self->_bareKey() : $self->_string();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'PROPS'}[14] && $ch ne '"' && $ch ne q['] ? : 2 3459 3461
Condition66%4/6
$self->{"PROPS"}[14] and $ch ne "\"" and $ch ne "'"
!ll&&!rl&&r
345902
$self->{"PROPS"}[14] and $ch ne "\""
!ll&&!rl&&r
345902
MC/DC33%1/3
$self->{"PROPS"}[14] and $ch ne "\"" and $ch ne "'"
$self->{"PROPS"}[14] $ch ne "\"" $ch ne "'"
Truth table50%2/4
A and B and C
A= $self->{"PROPS"}[14]B= $ch ne "\""C= $ch ne "'"
ABCresult
0XX0
10X0
1100
1111
1045 3456 $self->_white();
1046  
1047 3456 $ch = $self->{ch};
1048 3456 ▶ if(!defined $ch or $ch ne ':'){
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ch or $ch ne ":") 3 3453 3456
Condition100%3/3
not defined $ch or $ch ne ":"
l!l&&r!l&&!r
123453
MC/DC100%2/2
not defined $ch or $ch ne ":"
not defined $ch $ch ne ":"
Truth table100%3/3
not(A) or B
A= not defined $chB= $ch ne ":"
ABresult
1X1
011
000
1049 3 $self->{at}--;
1050 3 $self->_decode_error("':' expected");
1051 }
1052  
1053 3453 $self->_next_chr();
1054 3453 $o->{$k} = $self->_value();
1055 2936 $self->_white();
1056  
1057 2936 $ch = $self->{ch};
1058 2936 ▶ last if (!defined $ch);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ch 1 2935 2936
1059  
1060 2935 ▶ if($ch eq '}'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "}") 1630 1305 2935
1061 1630 --$self->{depth};
1062 1630 $self->_next_chr();
1063 1630 ▶ if ($self->{F_HOOK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"F_HOOK"}) 8 1622 1630
1064 8 return $self->__json_object_hook($o);
1065 }
1066 1622 return $o;
1067 }
1068  
1069 1305 ▶ if($ch ne ','){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch ne ",") 4 1301 1305
1070 4 last;
1071 }
1072  
1073 1301 $self->_next_chr();
1074 1301 $self->_white();
1075  
1076 1301 $ch = $self->{ch};
1077 1301 ▶ if ($self->{PROPS}[P_RELAXED] and $ch eq '}') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[11] and $ch eq "}") 1 1300 1301
Condition66%2/3
$self->{"PROPS"}[11] and $ch eq "}"
!ll&&!rl&&r
130001
MC/DC50%1/2
$self->{"PROPS"}[11] and $ch eq "}"
$self->{"PROPS"}[11] $ch eq "}"
Truth table66%2/3
A and B
A= $self->{"PROPS"}[11]B= $ch eq "}"
ABresult
0X0
100
111
1078 1 --$self->{depth};
1079 1 $self->_next_chr();
1080 1 ▶ if ($self->{F_HOOK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"F_HOOK"}) 0 1 1
1081 0 return $self->__json_object_hook($o);
1082 }
1083 1 return $o;
1084 }
1085  
1086 }
1087  
1088 }
1089  
1090 6 ▶ $self->{at}-- if defined $ch and $ch ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $ch and $ch ne "" 4 2 6
Condition66%2/3
defined $ch and $ch ne ""
!ll&&!rl&&r
204
MC/DC50%1/2
defined $ch and $ch ne ""
defined $ch $ch ne ""
Truth table66%2/3
A and B
A= defined $chB= $ch ne ""
ABresult
0X0
100
111
1091 6 $self->_decode_error(", or } expected while parsing object/hash");
1092 }
1093  
1094  
1095 2 ▶ sub _bareKey { # doesn't strictly follow Standard ECMA-262 3rd Edition
Subroutine _bareKey: called CC=2 SCAR=6.9
1096 2 my $self = shift;
1097 2 my $key;
1098 2 my $ch = $self->{ch};
1099 2 ▶ while($ch =~ /[\$\w[:^ascii:]]/){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /[\$\w[:^ascii:]]/) 6 2 8
1100 6 $key .= $ch;
1101 6 $ch = $self->_next_chr();
1102 }
1103 2 return $key;
1104 }
1105  
1106  
1107 86 ▶ sub _word {
Subroutine _word: called CC=10 SCAR=23.2
1108 86 my $self = shift;
1109 86 my $word = substr($self->{text},$self->{at}-1,4);
1110  
1111 86 ▶ if($word eq 'true'){
Branch: 3 branches
BranchTrueFalseTotal
if ($word eq 'true') { } 11 75 86
elsif ($word eq 'null') { } 46 29 75
elsif ($word eq 'fals') { } 8 21 29
1112 11 $self->{at} += 3;
1113 11 $self->_next_chr;
1114 11 ▶ return defined $self->{true} ? $self->{true} : $JSON::PP::true;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'true'} ? : 0 11 11
1115 }
1116 elsif($word eq 'null'){
1117 46 $self->{at} += 3;
1118 46 $self->_next_chr;
1119 46 return undef;
1120 }
1121 elsif($word eq 'fals'){
1122 8 $self->{at} += 3;
1123 8 ▶ if(substr($self->{text},$self->{at},1) eq 'e'){
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->{"text"}, $self->{"at"}, 1) eq "e") 8 0 8
1124 8 $self->{at}++;
1125 8 $self->_next_chr;
1126 8 ▶ return defined $self->{false} ? $self->{false} : $JSON::PP::false;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'false'} ? : 0 8 8
1127 }
1128 }
1129  
1130 21 $self->{at}--; # for decode_error report
1131  
1132 21 ▶ $self->_decode_error("'null' expected") if ($word =~ /^n/);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^n/ 1 20 21
1133 20 ▶ $self->_decode_error("'true' expected") if ($word =~ /^t/);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^t/ 1 19 20
1134 19 ▶ $self->_decode_error("'false' expected") if ($word =~ /^f/);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^f/ 0 19 19
1135 19 $self->_decode_error("malformed JSON string, neither array, object, number, string or atom");
1136 }
1137  
1138  
1139 891 ▶ sub _number {
Subroutine _number: called CC=32 SCAR=34.7
1140 891 my $self = shift;
1141 891 my $n = '';
1142 891 my $v;
1143 my $is_dec;
1144 891 my $is_exp;
1145  
1146 891 my $ch = $self->{ch};
1147 891 ▶ if($ch eq '-'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "-") 41 850 891
1148 41 $n = '-';
1149 41 $ch = $self->_next_chr;
1150 41 ▶ if (!defined $ch or $ch !~ /\d/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ch and $ch =~ /\d/) 1 40 41
Condition66%2/3
defined $ch and $ch =~ /\d/
!ll&&!rl&&r
0140
MC/DC50%1/2
defined $ch and $ch =~ /\d/
defined $ch $ch =~ /\d/
Truth table66%2/3
A and B
A= defined $chB= $ch =~ /\d/
ABresult
0X0
100
111
1151 1 $self->_decode_error("malformed number (no digits after initial minus)");
1152 }
1153 }
1154  
1155 # According to RFC4627, hex or oct digits are invalid.
1156 890 ▶ if($ch eq '0'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq 0) 81 809 890
1157 81 my $peek = substr($self->{text},$self->{at},1);
1158 81 ▶ if($peek =~ /^[0-9a-dfA-DF]/){ # e may be valid (exponential)
Branch: 1 branch
BranchTrueFalseTotal
if ($peek =~ /^[0-9a-dfA-DF]/) 5 76 81
1159 5 $self->_decode_error("malformed number (leading zero must not be followed by another digit)");
1160 }
1161 76 $n .= $ch;
1162 76 $ch = $self->_next_chr;
1163 }
1164  
1165 885 ▶ while(defined $ch and $ch =~ /\d/){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch and $ch =~ /\d/) 1012 885 1897
Condition100%3/3
defined $ch and $ch =~ /\d/
!ll&&!rl&&r
58801012
MC/DC100%2/2
defined $ch and $ch =~ /\d/
defined $ch $ch =~ /\d/
Truth table100%3/3
A and B
A= defined $chB= $ch =~ /\d/
ABresult
0X0
100
111
1166 1012 $n .= $ch;
1167 1012 $ch = $self->_next_chr;
1168 }
1169  
1170 885 ▶ if(defined $ch and $ch eq '.'){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch and $ch eq ".") 27 858 885
Condition100%3/3
defined $ch and $ch eq "."
!ll&&!rl&&r
585327
MC/DC100%2/2
defined $ch and $ch eq "."
defined $ch $ch eq "."
Truth table100%3/3
A and B
A= defined $chB= $ch eq "."
ABresult
0X0
100
111
1171 27 $n .= '.';
1172 27 $is_dec = 1;
1173  
1174 27 $ch = $self->_next_chr;
1175 27 ▶ if (!defined $ch or $ch !~ /\d/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ch && $ch =~ /\d/) { } 1 26 27
Condition66%2/3
defined $ch && $ch =~ /\d/
!ll&&!rl&&r
1026
MC/DC50%1/2
defined $ch && $ch =~ /\d/
defined $ch $ch =~ /\d/
Truth table66%2/3
A && B
A= defined $chB= $ch =~ /\d/
ABresult
0X0
100
111
1176 1 $self->_decode_error("malformed number (no digits after decimal point)");
1177 }
1178 else {
1179 26 $n .= $ch;
1180 }
1181  
1182 26 ▶ while(defined($ch = $self->_next_chr) and $ch =~ /\d/){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($ch = $self->_next_chr) and $ch =~ /\d/) 75 26 101
Condition100%3/3
defined($ch = $self->_next_chr) and $ch =~ /\d/
!ll&&!rl&&r
22475
MC/DC100%2/2
defined($ch = $self->_next_chr) and $ch =~ /\d/
defined($ch = $self->_next_chr) $ch =~ /\d/
Truth table100%3/3
A and B
A= defined($ch = $self->_next_chr)B= $ch =~ /\d/
ABresult
0X0
100
111
1183 75 $n .= $ch;
1184 }
1185 }
1186  
1187 884 ▶ if(defined $ch and ($ch eq 'e' or $ch eq 'E')){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch and $ch eq "e" || $ch eq "E") 36 848 884
Condition100%6/6
defined $ch and $ch eq "e" || $ch eq "E"
!ll&&!rl&&r
784136
$ch eq "e" or $ch eq "E"
l!l&&r!l&&!r
333841
MC/DC100%3/3
defined $ch and $ch eq "e" || $ch eq "E"
defined $ch $ch eq "e" $ch eq "E"
Truth table100%4/4
A and B or C
A= defined $chB= $ch eq "e"C= $ch eq "E"
ABCresult
0XX0
1000
11X1
1011
1188 36 $n .= $ch;
1189 36 $is_exp = 1;
1190 36 $ch = $self->_next_chr;
1191  
1192 36 ▶ if(defined($ch) and ($ch eq '+' or $ch eq '-')){
Branch: 2 branches
BranchTrueFalseTotal
if (defined $ch and $ch eq '+' || $ch eq '-') { } 16 20 36
elsif (defined $ch and $ch =~ /\d/) { } 18 2 20
Condition100%6/6
defined $ch and $ch eq "+" || $ch eq "-"
!ll&&!rl&&r
11916
$ch eq "+" or $ch eq "-"
l!l&&r!l&&!r
10619
MC/DC100%3/3
defined $ch and $ch eq "+" || $ch eq "-"
defined $ch $ch eq "+" $ch eq "-"
Truth table100%4/4
A and B or C
A= defined $chB= $ch eq "+"C= $ch eq "-"
ABCresult
0XX0
1000
11X1
1011
1193 16 $n .= $ch;
1194 16 $ch = $self->_next_chr;
1195 16 ▶ if (!defined $ch or $ch =~ /\D/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ch or $ch =~ /\D/) 2 14 16
Condition66%2/3
not defined $ch or $ch =~ /\D/
l!l&&r!l&&!r
0214
MC/DC50%1/2
not defined $ch or $ch =~ /\D/
not defined $ch $ch =~ /\D/
Truth table66%2/3
not(A) or B
A= not defined $chB= $ch =~ /\D/
ABresult
1X1
011
000
1196 2 $self->_decode_error("malformed number (no digits after exp sign)");
1197 }
1198 14 $n .= $ch;
1199 }
1200 ▶ elsif(defined($ch) and $ch =~ /\d/){
Condition100%3/3
defined $ch and $ch =~ /\d/
!ll&&!rl&&r
1118
MC/DC100%2/2
defined $ch and $ch =~ /\d/
defined $ch $ch =~ /\d/
Truth table100%3/3
A and B
A= defined $chB= $ch =~ /\d/
ABresult
0X0
100
111
1201 18 $n .= $ch;
1202 }
1203 else {
1204 2 $self->_decode_error("malformed number (no digits after exp sign)");
1205 }
1206  
1207 32 ▶ while(defined($ch = $self->_next_chr) and $ch =~ /\d/){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($ch = $self->_next_chr) and $ch =~ /\d/) 11 32 43
Condition100%3/3
defined($ch = $self->_next_chr) and $ch =~ /\d/
!ll&&!rl&&r
161611
MC/DC100%2/2
defined($ch = $self->_next_chr) and $ch =~ /\d/
defined($ch = $self->_next_chr) $ch =~ /\d/
Truth table100%3/3
A and B
A= defined($ch = $self->_next_chr)B= $ch =~ /\d/
ABresult
0X0
100
111
1208 11 $n .= $ch;
1209 }
1210  
1211 }
1212  
1213 880 $v .= $n;
1214  
1215 880 ▶ if ($is_dec or $is_exp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dec or $is_exp) { } 48 832 880
Condition100%3/3
$is_dec or $is_exp
l!l&&r!l&&!r
2622832
MC/DC100%2/2
$is_dec or $is_exp
$is_dec $is_exp
Truth table100%3/3
A or B
A= $is_decB= $is_exp
ABresult
1X1
011
000
1216 48 ▶ if ($self->{PROPS}[P_ALLOW_BIGNUM]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[13]) 1 47 48
1217 1 require Math::BigFloat;
1218 1 return Math::BigFloat->new($v);
1219 }
1220 } else {
1221 832 ▶ if (length $v > $max_intsize) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $v > $max_intsize) 1 831 832
1222 1 ▶ if ($self->{PROPS}[P_ALLOW_BIGNUM]) { # from Adam Sussman
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROPS'}[13]) { } 1 0 1
1223 1 require Math::BigInt;
1224 1 return Math::BigInt->new($v);
1225 }
1226 else {
1227 0 return "$v";
1228 }
1229 }
1230 }
1231  
1232 878 ▶ return $is_dec ? $v/1.0 : 0+$v;
Branch: 1 branch
BranchTrueFalseTotal
$is_dec ? : 25 853 878
1233 }
1234  
1235 # Compute how many bytes are in the longest legal official Unicode
1236 # character
1237 57 my $max_unicode_length = do {
1238 57 ▶ no warnings 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
1239 57 chr 0x10FFFF;
1240 };
1241 57 utf8::encode($max_unicode_length);
1242 57 $max_unicode_length = length $max_unicode_length;
1243  
1244 3440092 ▶ sub _is_valid_utf8 {
Subroutine _is_valid_utf8: called CC=4 SCAR=13.9
1245 3440092 my ($self, $ch, $utf8_len_r) = @_;
1246  
1247 # Returns undef (setting $utf8_len to 0) unless the next bytes in $text
1248 # comprise a well-formed UTF-8 encoded character, in which case,
1249 # return those bytes, setting $utf8_len to their count.
1250  
1251 3440092 my $start_point = substr($self->{text}, $self->{at} - 1);
1252  
1253 # Look no further than the maximum number of bytes in a single
1254 # character
1255 3440092 my $limit = $max_unicode_length;
1256 3440092 ▶ $limit = length($start_point) if $limit > length($start_point);
Branch: 1 branch
BranchTrueFalseTotal
if $limit > length $start_point 7 3440085 3440092
1257  
1258 # Find the number of bytes comprising the first character in $text
1259 # (without having to know the details of its internal representation).
1260 # This loop will iterate just once on well-formed input.
1261 3440092 ▶ while ($limit > 0) { # Until we succeed or exhaust the input
Branch: 1 branch
BranchTrueFalseTotal
if ($limit > 0) 4679188 4 4679192
1262 4679188 my $copy = substr($start_point, 0, $limit);
1263  
1264 # decode() will return true if all bytes are valid; false
1265 # if any aren't.
1266 4679188 ▶ if (utf8::decode($copy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::decode($copy)) 3440088 1239100 4679188
1267  
1268 # Is valid: get the first character, convert back to bytes,
1269 # and return those bytes.
1270 3440088 $copy = substr($copy, 0, 1);
1271 3440088 utf8::encode($copy);
1272 3440088 $$utf8_len_r = length $copy;
1273 3440088 return substr($start_point, 0, $$utf8_len_r);
1274 }
1275  
1276 # If it didn't work, it could be that there is a full legal character
1277 # followed by a partial or malformed one. Narrow the window and
1278 # try again.
1279 1239100 $limit--;
1280 }
1281  
1282 # Failed to find a legal UTF-8 character.
1283 4 $$utf8_len_r = 0;
1284 4 return;
1285 }
1286  
1287  
1288 88 ▶ sub _decode_error {
Subroutine _decode_error: called CC=13 SCAR=26.0
1289 88 my $self = shift;
1290 88 my $error = shift;
1291 88 my $no_rep = shift;
1292 88 ▶ my $str = defined $self->{text} ? substr($self->{text}, $self->{at}) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'text'} ? : 84 4 88
1293 88 my $mess = '';
1294 88 my $type = 'U*';
1295  
1296 88 for my $c ( unpack( $type, $str ) ) { # emulate pv_uni_display() ?
1297 403 my $chr_c = chr($c);
1298 403 ▶ $mess .= $chr_c eq '\\' ? '\\\\'
Branch: 7 branches
BranchTrueFalseTotal
$chr_c eq '\\' ? : 6 397 403
$chr_c =~ /[[:print:]]/ ? : 382 15 397
$chr_c eq '\\a' ? : 0 15 15
$chr_c eq '\\t' ? : 0 15 15
$chr_c eq '\\n' ? : 0 15 15
$chr_c eq '\\r' ? : 0 15 15
$chr_c eq '\\f' ? : 0 15 15
1299 : $chr_c =~ /[[:print:]]/ ? $chr_c
1300 : $chr_c eq '\a' ? '\a'
1301 : $chr_c eq '\t' ? '\t'
1302 : $chr_c eq '\n' ? '\n'
1303 : $chr_c eq '\r' ? '\r'
1304 : $chr_c eq '\f' ? '\f'
1305 : sprintf('\x{%x}', $c)
1306 ;
1307 403 ▶ if ( length $mess >= 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $mess >= 20) 10 393 403
1308 10 $mess .= '...';
1309 10 last;
1310 }
1311 }
1312  
1313 88 ▶ unless ( length $mess ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $mess) 26 62 88
1314 26 $mess = '(end of string)';
1315 }
1316  
1317 Carp::croak (
1318 88 ▶ $no_rep ? "$error" : "$error, at character offset $self->{at} (before \"$mess\")"
Branch: 1 branch
BranchTrueFalseTotal
$no_rep ? : 5 83 88
1319 );
1320  
1321 }
1322  
1323  
1324 9 ▶ sub __json_object_hook {
Subroutine __json_object_hook: called CC=10 SCAR=23.5
1325 9 my $self = shift;
1326 9 my $o = $_[0];
1327 9 my @ks = keys %{$o};
1328  
1329 9 ▶ if ( $self->{cb_sk_object} and @ks == 1 and exists $self->{cb_sk_object}{ $ks[0] } and ref $self->{cb_sk_object}{ $ks[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cb_sk_object"} and @ks == 1 and exists $self->{"cb_sk_object"}{$ks[0]} and ref $self->{"cb_sk_object"}{$ks[0]}) 4 5 9
Condition77%7/9
$self->{"cb_sk_object"} and @ks == 1 and exists $self->{"cb_sk_object"}{$ks[0]} and ref $self->{"cb_sk_object"}{$ks[0]}
!ll&&!rl&&r
504
$self->{"cb_sk_object"} and @ks == 1 and exists $self->{"cb_sk_object"}{$ks[0]}
!ll&&!rl&&r
414
$self->{"cb_sk_object"} and @ks == 1
!ll&&!rl&&r
045
MC/DC50%2/4
$self->{"cb_sk_object"} and @ks == 1 and exists $self->{"cb_sk_object"}{$ks[0]} and ref $self->{"cb_sk_object"}{$ks[0]}
$self->{"cb_sk_object"} @ks == 1 exists $self->{"cb_sk_object"}{$ks[0]} ref $self->{"cb_sk_object"}{$ks[0]}
Truth table60%3/5
A and B and C and D
A= $self->{"cb_sk_object"}B= @ks == 1C= exists $self->{"cb_sk_object"}{$ks[0]}D= ref $self->{"cb_sk_object"}{$ks[0]}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1330 4 my @val = $self->{cb_sk_object}{ $ks[0] }->( $o->{$ks[0]} );
1331 4 ▶ if (@val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@val == 0) { } 1 3 4
elsif (@val == 1) { } 3 0 3
1332 1 return $o;
1333 }
1334 elsif (@val == 1) {
1335 3 return $val[0];
1336 }
1337 else {
1338 0 Carp::croak("filter_json_single_key_object callbacks must not return more than one scalar");
1339 }
1340 }
1341  
1342 5 ▶ my @val = $self->{cb_object}->($o) if ($self->{cb_object});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cb_object"} 4 1 5
1343 5 ▶ if (@val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@val == 0) { } 3 2 5
elsif (@val == 1) { } 2 0 2
1344 3 return $o;
1345 }
1346 elsif (@val == 1) {
1347 2 return $val[0];
1348 }
1349 else {
1350 0 Carp::croak("filter_json_object callbacks must not return more than one scalar");
1351 }
1352 }
1353  
1354 } # PARSE
1355  
1356  
1357 57 ▶sub _decode_surrogates { # from perlunicode
Subroutine _decode_surrogates: called CC=1 SCAR=0.0
1358 1127735 my $uni = 0x10000 + (hex($_[0]) - 0xD800) * 0x400 + (hex($_[1]) - 0xDC00);
1359 1127735 my $un = pack('U*', $uni);
1360 1127735 utf8::encode( $un );
1361 1127735 return $un;
1362 }
1363  
1364  
1365 2893170 ▶sub _decode_unicode {
Subroutine _decode_unicode: called CC=1 SCAR=0.0
1366 2893170 my $un = pack('U', hex shift);
1367 2893170 utf8::encode( $un );
1368 2893170 return $un;
1369 }
1370  
1371 637 ▶sub incr_parse {
Subroutine incr_parse: called CC=2 SCAR=7.1
Pod documented
1372 637 local $Carp::CarpLevel = 1;
1373 637 ▶ ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_parse( @_ );
Condition66%2/3
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
l!l&&r!l&&!r
611260
MC/DC0%0/2
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
$_[0]{"_incr_parser"} "JSON::PP::IncrParser"->new
Truth table66%2/3
A ||= B
A= $_[0]{"_incr_parser"}B= "JSON::PP::IncrParser"->new
ABresult
1X1
011
000
1374 }
1375  
1376  
1377 2 ▶sub incr_skip {
Subroutine incr_skip: called CC=2 SCAR=9.2
Pod documented
1378 2 ▶ ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_skip;
Condition33%1/3
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
l!l&&r!l&&!r
200
MC/DC0%0/2
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
$_[0]{"_incr_parser"} "JSON::PP::IncrParser"->new
Truth table33%1/3
A ||= B
A= $_[0]{"_incr_parser"}B= "JSON::PP::IncrParser"->new
ABresult
1X1
011
000
1379 }
1380  
1381  
1382 0 ▶sub incr_reset {
Subroutine incr_reset: not called CC=2 SCAR=17.9
Pod documented
1383 0 ▶ ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_reset;
Condition0%0/3
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
$_[0]{"_incr_parser"} "JSON::PP::IncrParser"->new
Truth table0%0/3
A ||= B
A= $_[0]{"_incr_parser"}B= "JSON::PP::IncrParser"->new
ABresult
1X1
011
000
1384 }
1385  
1386 293 ▶sub incr_text : lvalue {
Subroutine incr_text: called CC=3 SCAR=13.3
Pod documented
1387 293 ▶ $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new;
Condition33%1/3
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
l!l&&r!l&&!r
29300
MC/DC0%0/2
$_[0]{"_incr_parser"} ||= "JSON::PP::IncrParser"->new
$_[0]{"_incr_parser"} "JSON::PP::IncrParser"->new
Truth table33%1/3
A ||= B
A= $_[0]{"_incr_parser"}B= "JSON::PP::IncrParser"->new
ABresult
1X1
011
000
1388  
1389 293 ▶ if ( $_[0]->{_incr_parser}->{incr_pos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"_incr_parser"}{"incr_pos"}) 0 293 293
1390 0 Carp::croak("incr_text cannot be called when the incremental parser already started parsing");
1391 }
1392 293 $_[0]->{_incr_parser}->{incr_text};
1393 }
1394  
1395  
1396 ###############################
1397 # Utilities
1398 #
1399  
1400 # shamelessly copied and modified from JSON::XS code.
1401  
1402 57 $JSON::PP::true = do { bless \(my $dummy = 1), "JSON::PP::Boolean" };
1403 57 $JSON::PP::false = do { bless \(my $dummy = 0), "JSON::PP::Boolean" };
1404  
1405 5 ▶sub is_bool {
Subroutine is_bool: called CC=4 SCAR=15.9
Pod documented
1406 5 ▶ if (blessed $_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0])) { } 2 3 5
1407 return (
1408 2 ▶ $_[0]->isa("JSON::PP::Boolean")
Condition33%2/6
$_[0]->isa('JSON::PP::Boolean') || $_[0]->isa('Types::Serialiser::BooleanBase') || $_[0]->isa('JSON::XS::Boolean')
l!l&&r!l&&!r
200
$_[0]->isa("JSON::PP::Boolean") or $_[0]->isa("Types::Serialiser::BooleanBase")
l!l&&r!l&&!r
200
MC/DC0%0/3
$_[0]->isa('JSON::PP::Boolean') || $_[0]->isa('Types::Serialiser::BooleanBase') || $_[0]->isa('JSON::XS::Boolean')
$_[0]->isa("JSON::PP::Boolean") $_[0]->isa("Types::Serialiser::BooleanBase") $_[0]->isa('JSON::XS::Boolean')
Truth table25%1/4
A or B || C
A= $_[0]->isa("JSON::PP::Boolean")B= $_[0]->isa("Types::Serialiser::BooleanBase")C= $_[0]->isa('JSON::XS::Boolean')
ABCresult
1XX1
01X1
0011
0000
1409 or $_[0]->isa("Types::Serialiser::BooleanBase")
1410 or $_[0]->isa("JSON::XS::Boolean")
1411 );
1412 }
1413 elsif (CORE_BOOL) {
1414 57 ▶ BEGIN { CORE_BOOL and warnings->unimport('experimental::builtin') }
Subroutine BEGIN: called CC=1 SCAR=0.0
1415 3 return builtin::is_bool($_[0]);
1416 }
1417 0 return !!0;
1418 }
1419  
1420 0 ▶sub true { $JSON::PP::true }
Subroutine true: not called CC=1 SCAR=6.9
Pod documented
1421 0 ▶sub false { $JSON::PP::false }
Subroutine false: not called CC=1 SCAR=6.9
Pod documented
1422 0 ▶sub null { undef; }
Subroutine null: not called CC=1 SCAR=6.9
Pod documented
1423  
1424 ###############################
1425  
1426 package # hide from PAUSE
1427 JSON::PP::IncrParser;
1428  
1429 57 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1430  
1431 57 ▶use constant INCR_M_WS => 0; # initial whitespace skipping
Subroutine BEGIN: called CC=1 SCAR=0.0
1432 57 ▶use constant INCR_M_STR => 1; # inside string
Subroutine BEGIN: called CC=1 SCAR=0.0
1433 57 ▶use constant INCR_M_BS => 2; # inside backslash
Subroutine BEGIN: called CC=1 SCAR=0.0
1434 57 ▶use constant INCR_M_JSON => 3; # outside anything, count nesting
Subroutine BEGIN: called CC=1 SCAR=0.0
1435 57 ▶use constant INCR_M_C0 => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
1436 57 ▶use constant INCR_M_C1 => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
1437 57 ▶use constant INCR_M_TFN => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
1438 57 ▶use constant INCR_M_NUM => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
1439  
1440 57 $JSON::backportPP::VERSION = '1.01';
1441  
1442 26 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
1443 26 my ( $class ) = @_;
1444  
1445 26 bless {
1446 incr_nest => 0,
1447 incr_text => undef,
1448 incr_pos => 0,
1449 incr_mode => 0,
1450 }, $class;
1451 }
1452  
1453  
1454 637 ▶sub incr_parse {
Subroutine incr_parse: called CC=18 SCAR=28.9
1455 637 my ( $self, $coder, $text ) = @_;
1456  
1457 637 ▶ $self->{incr_text} = '' unless ( defined $self->{incr_text} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"incr_text"} 26 611 637
1458  
1459 637 ▶ if ( defined $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 329 308 637
1460 329 $self->{incr_text} .= $text;
1461 }
1462  
1463 637 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 319 318 637
1464 319 my $max_size = $coder->get_max_size;
1465 319 my $p = $self->{incr_pos};
1466 319 my @ret;
1467 {
1468 319 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
wantarray and do { do { unless ($self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3) { $self->_incr_parse($coder); if ($max_size and $self->{"incr_pos"} > $max_size) { Carp::croak(qq[attempted decode of JSON text of $self->{"incr_pos"} bytes size, but max_size is set to $max_size]); } ; unless ($self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3) { if ($self->{"incr_mode"} == 0 and $self->{"incr_pos"}) { $self->{"incr_pos"} = 0; $self->{"incr_text"} = ""; } ; last; } ; } ; unless ($coder->get_utf8) { utf8::decode($self->{"incr_text"}); } ; () = $coder->PP_decode_json($self->{"incr_text"}, 1); push @ret, $obj; use bytes; $self->{"incr_text"} = substr($self->{"incr_text"}, $offset || 0); $self->{"incr_pos"} = 0; $self->{"incr_nest"} = 0; $self->{"incr_mode"} = 0; last unless wantarray } } 2 0 2
1469 321 ▶ unless ( $self->{incr_nest} <= 0 and $self->{incr_mode} == INCR_M_JSON ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3) 320 1 321
Condition100%3/3
$self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3
!ll&&!rl&&r
23181
MC/DC100%2/2
$self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3
$self->{"incr_nest"} <= 0 $self->{"incr_mode"} == 3
Truth table100%3/3
A and B
A= $self->{"incr_nest"} <= 0B= $self->{"incr_mode"} == 3
ABresult
0X0
100
111
1470 320 $self->_incr_parse( $coder );
1471  
1472 319 ▶ if ( $max_size and $self->{incr_pos} > $max_size ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_size and $self->{"incr_pos"} > $max_size) 1 318 319
Condition100%3/3
$max_size and $self->{"incr_pos"} > $max_size
!ll&&!rl&&r
31711
MC/DC100%2/2
$max_size and $self->{"incr_pos"} > $max_size
$max_size $self->{"incr_pos"} > $max_size
Truth table100%3/3
A and B
A= $max_sizeB= $self->{"incr_pos"} > $max_size
ABresult
0X0
100
111
1473 1 Carp::croak("attempted decode of JSON text of $self->{incr_pos} bytes size, but max_size is set to $max_size");
1474 }
1475 318 ▶ unless ( $self->{incr_nest} <= 0 and $self->{incr_mode} == INCR_M_JSON ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3) 46 272 318
Condition100%3/3
$self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3
!ll&&!rl&&r
244272
MC/DC100%2/2
$self->{"incr_nest"} <= 0 and $self->{"incr_mode"} == 3
$self->{"incr_nest"} <= 0 $self->{"incr_mode"} == 3
Truth table100%3/3
A and B
A= $self->{"incr_nest"} <= 0B= $self->{"incr_mode"} == 3
ABresult
0X0
100
111
1476 # as an optimisation, do not accumulate white space in the incr buffer
1477 46 ▶ if ( $self->{incr_mode} == INCR_M_WS and $self->{incr_pos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"incr_mode"} == 0 and $self->{"incr_pos"}) 4 42 46
Condition100%3/3
$self->{"incr_mode"} == 0 and $self->{"incr_pos"}
!ll&&!rl&&r
4384
MC/DC100%2/2
$self->{"incr_mode"} == 0 and $self->{"incr_pos"}
$self->{"incr_mode"} == 0 $self->{"incr_pos"}
Truth table100%3/3
A and B
A= $self->{"incr_mode"} == 0B= $self->{"incr_pos"}
ABresult
0X0
100
111
1478 4 $self->{incr_pos} = 0;
1479 4 $self->{incr_text} = '';
1480 }
1481 46 last;
1482 }
1483 }
1484  
1485 273 ▶ unless ( $coder->get_utf8 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($coder->get_utf8) 273 0 273
1486 273 utf8::decode( $self->{incr_text} );
1487 }
1488  
1489 273 my ($obj, $offset) = $coder->PP_decode_json( $self->{incr_text}, 0x00000001 );
1490 269 push @ret, $obj;
1491 57 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1492 269 ▶ $self->{incr_text} = substr( $self->{incr_text}, $offset || 0 );
Condition50%1/2
$offset || 0
l!l
2690
MC/DC0%0/1
$offset || 0
$offset
Truth table50%1/2
A
A= $offset
Aresult
11
00
1493 269 $self->{incr_pos} = 0;
1494 269 $self->{incr_nest} = 0;
1495 269 $self->{incr_mode} = 0;
1496 269 ▶ last unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 267 2 269
1497 } while ( wantarray );
1498 }
1499  
1500 313 ▶ if ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 309 313
1501 4 return @ret;
1502 }
1503 else { # in scalar context
1504 309 ▶ return defined $ret[0] ? $ret[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ret[0] ? : 267 42 309
1505 }
1506 }
1507 }
1508  
1509  
1510 320 ▶sub _incr_parse {
Subroutine _incr_parse: called CC=54 SCAR=41.9
1511 320 my ($self, $coder) = @_;
1512 320 my $text = $self->{incr_text};
1513 320 my $len = length $text;
1514 320 my $p = $self->{incr_pos};
1515  
1516 INCR_PARSE:
1517 320 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 291 46 337
1518 2550 my $s = substr( $text, $p, 1 );
1519 2550 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 2550 2550
1520 2550 my $mode = $self->{incr_mode};
1521  
1522 2550 ▶ if ( $mode == INCR_M_WS ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($mode == 0) { } 284 2266 2550
elsif ($mode == 2) { } 0 2266 2266
elsif ($mode == 4 or $mode == 5) { } 9 2257 2266
elsif ($mode == 6) { } 35 2222 2257
elsif ($mode == 7) { } 380 1842 2222
elsif ($mode == 1) { } 585 1257 1842
elsif ($mode == 3) { } 1257 0 1257
1523 284 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 516 4 520
1524 516 $s = substr( $text, $p, 1 );
1525 516 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 516 516
1526 516 ▶ if ( ord($s) > ord " " ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $s > 32) 280 236 516
1527 280 ▶ if ( $s eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq '#') { } 6 274 280
1528 6 $self->{incr_mode} = INCR_M_C0;
1529 6 redo INCR_PARSE;
1530 } else {
1531 274 $self->{incr_mode} = INCR_M_JSON;
1532 274 redo INCR_PARSE;
1533 }
1534 }
1535 236 $p++;
1536 }
1537 } elsif ( $mode == INCR_M_BS ) {
1538 0 $p++;
1539 0 $self->{incr_mode} = INCR_M_STR;
1540 0 redo INCR_PARSE;
1541 ▶ } elsif ( $mode == INCR_M_C0 or $mode == INCR_M_C1 ) {
Condition100%3/3
$mode == 4 or $mode == 5
l!l&&r!l&&!r
632257
MC/DC100%2/2
$mode == 4 or $mode == 5
$mode == 4 $mode == 5
Truth table100%3/3
A or B
A= $mode == 4B= $mode == 5
ABresult
1X1
011
000
1542 9 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 45 0 45
1543 45 $s = substr( $text, $p, 1 );
1544 45 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 45 45
1545 45 ▶ if ( $s eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "\n") 9 36 45
1546 9 ▶ $self->{incr_mode} = $self->{incr_mode} == INCR_M_C0 ? INCR_M_WS : INCR_M_JSON;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'incr_mode'} == 4 ? : 6 3 9
1547 9 last;
1548 }
1549 36 $p++;
1550 }
1551 9 next;
1552 } elsif ( $mode == INCR_M_TFN ) {
1553 35 ▶ last INCR_PARSE if $p >= $len && $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $len and $self->{"incr_nest"} 0 35 35
Condition33%1/3
$p >= $len and $self->{"incr_nest"}
!ll&&!rl&&r
3500
MC/DC0%0/2
$p >= $len and $self->{"incr_nest"}
$p >= $len $self->{"incr_nest"}
Truth table33%1/3
A and B
A= $p >= $lenB= $self->{"incr_nest"}
ABresult
0X0
100
111
1554 35 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 140 0 140
1555 140 $s = substr( $text, $p++, 1 );
1556 140 ▶ next if defined $s and $s =~ /[rueals]/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s and $s =~ /[rueals]/ 105 35 140
Condition66%2/3
defined $s and $s =~ /[rueals]/
!ll&&!rl&&r
035105
MC/DC50%1/2
defined $s and $s =~ /[rueals]/
defined $s $s =~ /[rueals]/
Truth table66%2/3
A and B
A= defined $sB= $s =~ /[rueals]/
ABresult
0X0
100
111
1557 35 last;
1558 }
1559 35 $p--;
1560 35 $self->{incr_mode} = INCR_M_JSON;
1561  
1562 35 ▶ last INCR_PARSE unless $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incr_nest"} 0 35 35
1563 35 redo INCR_PARSE;
1564 } elsif ( $mode == INCR_M_NUM ) {
1565 380 ▶ last INCR_PARSE if $p >= $len && $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
if $p >= $len and $self->{"incr_nest"} 0 380 380
Condition33%1/3
$p >= $len and $self->{"incr_nest"}
!ll&&!rl&&r
38000
MC/DC0%0/2
$p >= $len and $self->{"incr_nest"}
$p >= $len $self->{"incr_nest"}
Truth table33%1/3
A and B
A= $p >= $lenB= $self->{"incr_nest"}
ABresult
0X0
100
111
1566 380 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 391 5 396
1567 391 $s = substr( $text, $p++, 1 );
1568 391 ▶ next if defined $s and $s =~ /[0-9eE.+\-]/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $s and $s =~ /[0-9eE.+\-]/ 16 375 391
Condition66%2/3
defined $s and $s =~ /[0-9eE.+\-]/
!ll&&!rl&&r
037516
MC/DC50%1/2
defined $s and $s =~ /[0-9eE.+\-]/
defined $s $s =~ /[0-9eE.+\-]/
Truth table66%2/3
A and B
A= defined $sB= $s =~ /[0-9eE.+\-]/
ABresult
0X0
100
111
1569 375 last;
1570 }
1571 380 $p--;
1572 380 $self->{incr_mode} = INCR_M_JSON;
1573  
1574 380 ▶ last INCR_PARSE unless $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incr_nest"} 5 375 380
1575 375 redo INCR_PARSE;
1576 } elsif ( $mode == INCR_M_STR ) {
1577 585 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 2063 2 2065
1578 2063 $s = substr( $text, $p, 1 );
1579 2063 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 2063 2063
1580 2063 ▶ if ( $s eq '"' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s eq '"') { } 583 1480 2063
elsif ($s eq '\\') { } 498 982 1480
1581 583 $p++;
1582 583 $self->{incr_mode} = INCR_M_JSON;
1583  
1584 583 ▶ last INCR_PARSE unless $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incr_nest"} 15 568 583
1585 568 redo INCR_PARSE;
1586 }
1587 elsif ( $s eq '\\' ) {
1588 498 $p++;
1589 498 ▶ if ( !defined substr($text, $p, 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined substr($text, $p, 1)) 0 498 498
1590 0 $self->{incr_mode} = INCR_M_BS;
1591 0 last INCR_PARSE;
1592 }
1593 }
1594 1480 $p++;
1595 }
1596 } elsif ( $mode == INCR_M_JSON ) {
1597 1257 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 3126 2 3128
1598 3126 $s = substr( $text, $p++, 1 );
1599 3126 ▶ if ( $s eq "\x00" ) {
Branch: 8 branches
BranchTrueFalseTotal
if ($s eq "\000") { } 0 3126 3126
elsif ($s =~ /^[\t\n\r ]$/) { } 682 2444 3126
elsif ($s eq 't' or $s eq 'f' or $s eq 'n') { } 35 2409 2444
elsif ($s =~ /^[0-9\-]$/) { } 380 2029 2409
elsif ($s eq '"') { } 583 1446 2029
elsif ($s eq '[' or $s eq '{') { } 355 1091 1446
elsif ($s eq ']' or $s eq '}') { } 352 739 1091
elsif ($s eq '#') { } 3 736 739
1600 0 $p--;
1601 0 last INCR_PARSE;
1602 } elsif ( $s =~ /^[\t\n\r ]$/) {
1603 682 ▶ if ( !$self->{incr_nest} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"incr_nest"}) 0 682 682
1604 0 $p--; # do not eat the whitespace, let the next round do it
1605 0 last INCR_PARSE;
1606 }
1607 682 next;
1608 ▶ } elsif ( $s eq 't' or $s eq 'f' or $s eq 'n' ) {
Condition50%3/6
$s eq "t" or $s eq "f" or $s eq "n"
l!l&&r!l&&!r
0352409
$s eq "t" or $s eq "f"
l!l&&r!l&&!r
002444
MC/DC33%1/3
$s eq "t" or $s eq "f" or $s eq "n"
$s eq "t" $s eq "f" $s eq "n"
Truth table50%2/4
A or B or C
A= $s eq "t"B= $s eq "f"C= $s eq "n"
ABCresult
1XX1
01X1
0011
0000
1609 35 $self->{incr_mode} = INCR_M_TFN;
1610 35 redo INCR_PARSE;
1611 } elsif ( $s =~ /^[0-9\-]$/ ) {
1612 380 $self->{incr_mode} = INCR_M_NUM;
1613 380 redo INCR_PARSE;
1614 } elsif ( $s eq '"' ) {
1615 583 $self->{incr_mode} = INCR_M_STR;
1616 583 redo INCR_PARSE;
1617 ▶ } elsif ( $s eq '[' or $s eq '{' ) {
Condition100%3/3
$s eq "[" or $s eq "{"
l!l&&r!l&&!r
1861691091
MC/DC100%2/2
$s eq "[" or $s eq "{"
$s eq "[" $s eq "{"
Truth table100%3/3
A or B
A= $s eq "["B= $s eq "{"
ABresult
1X1
011
000
1618 355 ▶ if ( ++$self->{incr_nest} > $coder->get_max_depth ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"incr_nest"} > $coder->get_max_depth) 1 354 355
1619 1 Carp::croak('json text or perl structure exceeds maximum nesting level (max_depth set too low?)');
1620 }
1621 354 next;
1622 ▶ } elsif ( $s eq ']' or $s eq '}' ) {
Condition100%3/3
$s eq "]" or $s eq "}"
l!l&&r!l&&!r
183169739
MC/DC100%2/2
$s eq "]" or $s eq "}"
$s eq "]" $s eq "}"
Truth table100%3/3
A or B
A= $s eq "]"B= $s eq "}"
ABresult
1X1
011
000
1623 352 ▶ if ( --$self->{incr_nest} <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$self->{"incr_nest"} <= 0) 253 99 352
1624 253 last INCR_PARSE;
1625 }
1626 } elsif ( $s eq '#' ) {
1627 3 $self->{incr_mode} = INCR_M_C1;
1628 3 redo INCR_PARSE;
1629 }
1630 }
1631 }
1632 }
1633  
1634 319 $self->{incr_pos} = $p;
1635 319 ▶ $self->{incr_parsing} = $p ? 1 : 0; # for backward compatibility
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 281 38 319
1636 }
1637  
1638  
1639 0 ▶sub incr_text {
Subroutine incr_text: not called CC=2 SCAR=17.9
1640 0 ▶ if ( $_[0]->{incr_pos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"incr_pos"}) 0 0 0
1641 0 Carp::croak("incr_text cannot be called when the incremental parser already started parsing");
1642 }
1643 0 $_[0]->{incr_text};
1644 }
1645  
1646  
1647 2 ▶sub incr_skip {
Subroutine incr_skip: called CC=1 SCAR=0.0
1648 2 my $self = shift;
1649 2 $self->{incr_text} = substr( $self->{incr_text}, $self->{incr_pos} );
1650 2 $self->{incr_pos} = 0;
1651 2 $self->{incr_mode} = 0;
1652 2 $self->{incr_nest} = 0;
1653 }
1654  
1655  
1656 0 ▶sub incr_reset {
Subroutine incr_reset: not called CC=1 SCAR=6.9
1657 0 my $self = shift;
1658 0 $self->{incr_text} = undef;
1659 0 $self->{incr_pos} = 0;
1660 0 $self->{incr_mode} = 0;
1661 0 $self->{incr_nest} = 0;
1662 }
1663  
1664 ###############################
1665  
1666  
1667 57 1;
1668 __END__
« JSON/backportPP/Compat5006.pm ↑ Summary JSON.pm »