PP.pm

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