PP.pm

filter: Statementstmt 88.5% 876 / 989 Branchbran 76.0% 505 / 664 Conditioncond 68.3% 190 / 278 MC/DCmcdc 49.4% 84 / 170 Subroutinesub 79.8% 131 / 164 Podpod 51.2% 42 / 82 totaltotal 77.8% 1828 / 2347 SCAR 74.2
CC
435
Cov
81%
_white
104.9
_incr_parse
59.7
_number
32.1
CRAP 1661.1
↑ 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.17_01';
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 BEGIN {
54 67 ▶ $invalid_char_re = "[";
Subroutine BEGIN: called CC=2 SCAR=6.9
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 BEGIN {
63 67 ▶ if (USE_B) {
Subroutine BEGIN: called CC=1 SCAR=0.0
64 require B;
65 }
66 }
67  
68 BEGIN {
69 67 ▶ my @xs_compati_bit_properties = qw(
Subroutine BEGIN: called CC=2 SCAR=8.8
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 1340 ▶ 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 sub encode_json ($) { # encode
111 191 ▶ ($JSON ||= __PACKAGE__->new->utf8)->encode(@_);
Subroutine encode_json: called CC=2 SCAR=9.2
Pod documented
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 sub decode_json { # decode
116 6273 ▶ ($JSON ||= __PACKAGE__->new->utf8)->decode(@_);
Subroutine decode_json: called CC=2 SCAR=7.2
Pod documented
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 sub to_json($) {
122 0 ▶ Carp::croak ("JSON::PP::to_json has been renamed to encode_json.");
Subroutine to_json: not called CC=1 SCAR=6.9
Pod undocumented
123 }
124  
125  
126 sub from_json($) {
127 0 ▶ Carp::croak ("JSON::PP::from_json has been renamed to decode_json.");
Subroutine from_json: not called CC=1 SCAR=6.9
Pod undocumented
128 }
129  
130  
131 # Methods
132  
133 sub new {
134 43220 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
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 sub encode {
148 25148 ▶ return $_[0]->PP_encode_json($_[1]);
Subroutine encode: called CC=1 SCAR=0.0
Pod documented
149 }
150  
151  
152 sub decode {
153 25019 ▶ return $_[0]->PP_decode_json($_[1], 0x00000000);
Subroutine decode: called CC=1 SCAR=0.0
Pod documented
154 }
155  
156  
157 sub decode_prefix {
158 8 ▶ return $_[0]->PP_decode_json($_[1], 0x00000001);
Subroutine decode_prefix: called CC=1 SCAR=0.0
Pod documented
159 }
160  
161  
162 # accessor
163  
164  
165 # pretty printing
166  
167 sub pretty {
168 5 ▶ my ($self, $v) = @_;
Subroutine pretty: called CC=3 SCAR=11.0
Pod documented
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 sub max_depth {
184 5 ▶ my $max = defined $_[1] ? $_[1] : 0x80000000;
Subroutine max_depth: called CC=2 SCAR=7.1
Pod documented
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 sub max_size {
194 3 ▶ my $max = defined $_[1] ? $_[1] : 0;
Subroutine max_size: called CC=2 SCAR=7.1
Pod documented
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 sub boolean_values {
203 6 ▶ my $self = shift;
Subroutine boolean_values: called CC=6 SCAR=17.9
Pod documented
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 sub core_bools {
226 1 ▶ my $self = shift;
Subroutine core_bools: called CC=3 SCAR=12.3
Pod documented
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 sub get_core_bools {
242 4 ▶ my $self = shift;
Subroutine get_core_bools: called CC=1 SCAR=0.0
Pod undocumented
243 4 return !!$self->{core_bools};
244 }
245  
246 sub unblessed_bool {
247 0 ▶ my $self = shift;
Subroutine unblessed_bool: not called CC=1 SCAR=6.9
Pod undocumented
248 0 return $self->core_bools(@_);
249 }
250  
251 sub get_unblessed_bool {
252 0 ▶ my $self = shift;
Subroutine get_unblessed_bool: not called CC=1 SCAR=6.9
Pod undocumented
253 0 return $self->get_core_bools(@_);
254 }
255  
256 sub get_boolean_values {
257 5 ▶ my $self = shift;
Subroutine get_boolean_values: called CC=3 SCAR=11.0
Pod undocumented
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 sub filter_json_object {
265 3 ▶ if (defined $_[1] and ref $_[1] eq 'CODE') {
Subroutine filter_json_object: called CC=5 SCAR=16.5
Pod documented
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 sub filter_json_single_key_object {
275 4 ▶ if (@_ == 1 or @_ > 3) {
Subroutine filter_json_single_key_object: called CC=9 SCAR=25.4
Pod documented
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: 2 branches
BranchTrueFalseTotal
unless %{$_[0]{"cb_sk_object"} or {};} 0 1 1
$_[0]{"cb_sk_object"} or {} 0 1 1
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 sub indent_length {
289 0 ▶ if (!defined $_[1] or $_[1] > 15 or $_[1] < 0) {
Subroutine indent_length: not called CC=4 SCAR=30.0
Pod documented
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 sub get_indent_length {
299 0 ▶ $_[0]->{indent_length};
Subroutine get_indent_length: not called CC=1 SCAR=6.9
Pod undocumented
300 }
301  
302 sub sort_by {
303 3 ▶ $_[0]->{sort_by} = defined $_[1] ? $_[1] : 1;
Subroutine sort_by: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
defined $_[1] ? : 3 0 3
304 3 $_[0];
305 }
306  
307 sub allow_bigint {
308 0 ▶ Carp::carp("allow_bigint() is obsoleted. use allow_bignum() instead.");
Subroutine allow_bigint: not called CC=1 SCAR=6.9
Pod undocumented
309 0 $_[0]->allow_bignum;
310 }
311  
312 ###############################
313  
314 ###
315 ### Perl => JSON
316 ###
317  
318  
319 { # Convert
320  
321 sub PP_encode_json {
322 25148 ▶ my $self = shift;
Subroutine PP_encode_json: called CC=8 SCAR=20.8
Pod undocumented
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 sub object_to_json {
350 25504 ▶ my ($self, $obj) = @_;
Subroutine object_to_json: called CC=21 SCAR=31.3
Pod undocumented
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 sub hash_to_json {
413 346 ▶ my ($self, $obj) = @_;
Subroutine hash_to_json: called CC=9 SCAR=22.0
Pod undocumented
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 sub array_to_json {
437 25017 ▶ my ($self, $obj) = @_;
Subroutine array_to_json: called CC=7 SCAR=19.5
Pod undocumented
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 return '[' . $pre . join( ",$pre", @res ) . $post . ']';
454 }
455  
456 sub _looks_like_number {
457 26233 ▶ my $value = shift;
Subroutine _looks_like_number: called CC=5 SCAR=16.2
458 26233 if (USE_B) {
459 my $b_obj = B::svref_2object(\$value);
460 my $flags = $b_obj->FLAGS;
461 return 1 if $flags & ( B::SVp_IOK() | B::SVp_NOK() ) and !( $flags & B::SVp_POK() );
462 return;
463 } else {
464 67 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
465 # if the utf8 flag is on, it almost certainly started as a string
466 26233 ▶ return if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 12487 13746 26233
467 # detect numbers
468 # string & "" -> ""
469 # number & "" -> 0 (with warning)
470 # nan and inf can detect as numbers, so check with * 0
471 13746 ▶ return unless length((my $dummy = "") & $value);
Branch: 1 branch
BranchTrueFalseTotal
unless length((my $dummy = "") & $value) 12929 817 13746
472 817 ▶ return unless 0 + $value eq $value;
Branch: 1 branch
BranchTrueFalseTotal
unless 0 + $value eq $value 1 816 817
473 816 ▶ return 1 if $value * 0 == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $value * 0 == 0 816 0 816
474 0 return -1; # inf/nan
475 }
476 }
477  
478 sub value_to_json {
479 26319 ▶ my ($self, $value) = @_;
Subroutine value_to_json: called CC=18 SCAR=28.9
Pod undocumented
480  
481 26319 ▶ return 'null' if(!defined $value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 44 26275 26319
482  
483 26275 my $type = ref($value);
484  
485 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
486 67 ▶ BEGIN { CORE_BOOL and warnings->unimport('experimental::builtin') }
Subroutine BEGIN: called CC=1 SCAR=0.0
487 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
488 2 ▶ return $value ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 1 1 2
489 }
490 elsif (_looks_like_number($value)) {
491 816 return $value;
492 }
493 25417 return $self->string_to_json($value);
494 }
495 ▶ 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
496 20 ▶ return $$value == 1 ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$$value == 1 ? : 10 10 20
497 }
498 else {
499 20 ▶ if ((overload::StrVal($value) =~ /=(\w+)/)[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ((overload::StrVal($value) =~ /=(\w+)/)[0]) 0 20 20
500 0 return $self->value_to_json("$value");
501 }
502  
503 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
504 return $$value eq '1' ? 'true'
505 : $$value eq '0' ? 'false'
506 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
507 : encode_error("cannot encode reference to scalar");
508 }
509  
510 13 ▶ if ( $self->{PROPS}->[ P_ALLOW_UNKNOWN ] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROPS'}[18]) { } 4 9 13
511 4 return 'null';
512 }
513 else {
514 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
515 6 encode_error("cannot encode reference to scalar");
516 }
517 else {
518 3 encode_error("encountered $value, but JSON can only represent references to arrays or hashes");
519 }
520 }
521  
522 }
523 }
524  
525  
526 67 my %esc = (
527 "\n" => '\n',
528 "\r" => '\r',
529 "\t" => '\t',
530 "\f" => '\f',
531 "\b" => '\b',
532 "\"" => '\"',
533 "\\" => '\\\\',
534 "\'" => '\\\'',
535 );
536  
537  
538 sub string_to_json {
539 26161 ▶ my ($self, $arg) = @_;
Subroutine string_to_json: called CC=5 SCAR=16.1
Pod undocumented
540  
541 26161 $arg =~ s/(["\\\n\r\t\f\b])/$esc{$1}/g;
542 26161 ▶ $arg =~ s/\//\\\//g if ($self->{PROPS}[P_ESCAPE_SLASH]);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"PROPS"}[16] 1 26160 26161
543  
544 # On ASCII platforms, matches [\x00-\x08\x0b\x0e-\x1f]
545 26161 $arg =~ s/([^\n\t\c?[:^cntrl:][:^ascii:]])/'\\u00' . unpack('H2', $1)/eg;
546  
547 26161 ▶ if ($self->{PROPS}[P_ASCII]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[0]) 12297 13864 26161
548 12297 $arg = _encode_ascii($arg);
549 }
550  
551 26161 ▶ if ($self->{PROPS}[P_LATIN1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[1]) 2 26159 26161
552 2 $arg = _encode_latin1($arg);
553 }
554  
555 26161 ▶ if ($self->{PROPS}[P_UTF8]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[2]) 12551 13610 26161
556 12551 utf8::encode($arg);
557 }
558  
559 26161 return '"' . $arg . '"';
560 }
561  
562  
563 sub blessed_to_json {
564 0 ▶ my $reftype = reftype($_[1]) || '';
Subroutine blessed_to_json: not called CC=4 SCAR=30.0
Pod undocumented
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
565 0 ▶ if ($reftype eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if ($reftype eq 'HASH') { } 0 0 0
elsif ($reftype eq 'ARRAY') { } 0 0 0
566 0 return $_[0]->hash_to_json($_[1]);
567 }
568 elsif ($reftype eq 'ARRAY') {
569 0 return $_[0]->array_to_json($_[1]);
570 }
571 else {
572 0 return 'null';
573 }
574 }
575  
576  
577 sub encode_error {
578 18 ▶ my $error = shift;
Subroutine encode_error: called CC=1 SCAR=0.0
Pod undocumented
579 18 Carp::croak "$error";
580 }
581  
582  
583 sub __sort {
584 345 ▶ my $self = shift;
Subroutine __sort: called CC=2 SCAR=6.9
585 345 my $keysort = $self->{keysort};
586 345 ▶ defined $keysort ? (sort $keysort (keys %{$_[0]})) : keys %{$_[0]};
Branch: 1 branch
BranchTrueFalseTotal
defined $keysort ? : 222 123 345
587 }
588  
589  
590 sub _up_indent {
591 9 ▶ my $self = shift;
Subroutine _up_indent: called CC=1 SCAR=0.0
592 9 my $space = ' ' x $self->{indent_length};
593  
594 9 my ($pre,$post) = ('','');
595  
596 9 $post = "\n" . $space x $self->{indent_count};
597  
598 9 $self->{indent_count}++;
599  
600 9 $pre = "\n" . $space x $self->{indent_count};
601  
602 9 return ($pre,$post);
603 }
604  
605  
606 9 ▶ sub _down_indent { $_[0]->{indent_count}--; }
Subroutine _down_indent: called CC=1 SCAR=0.0
607  
608 } # Convert
609  
610  
611 67 sub _encode_ascii {
612 join('',
613 map {
614 12297 ▶ chr($_) =~ /[[:ascii:]]/ ?
Subroutine _encode_ascii: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
chr($_) =~ /[[:ascii:]]/ ? : 2818604 3440933 6259537
$_ <= 65535 ? : 2312958 1127975 3440933
615 chr($_) :
616 $_ <= 65535 ?
617 sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_));
618 } unpack('U*', $_[0])
619 );
620 }
621  
622  
623 sub _encode_latin1 {
624 join('',
625 map {
626 2 ▶ $_ <= 255 ?
Subroutine _encode_latin1: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
$_ <= 255 ? : 21 1 22
$_ <= 65535 ? : 1 0 1
627 chr($_) :
628 $_ <= 65535 ?
629 sprintf('\u%04x', $_) : sprintf('\u%x\u%x', _encode_surrogates($_));
630 } unpack('U*', $_[0])
631 );
632 }
633  
634  
635 sub _encode_surrogates { # from perlunicode
636 1127975 ▶ my $uni = $_[0] - 0x10000;
Subroutine _encode_surrogates: called CC=1 SCAR=0.0
637 1127975 return ($uni / 0x400 + 0xD800, $uni % 0x400 + 0xDC00);
638 }
639  
640  
641 sub _is_bignum {
642 3 ▶ $_[0]->isa('Math::BigInt') or $_[0]->isa('Math::BigFloat');
Subroutine _is_bignum: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->isa("Math::BigInt") or $_[0]->isa("Math::BigFloat") 1 2 3
643 }
644  
645  
646  
647 #
648 # JSON => Perl
649 #
650  
651 67 my $max_intsize;
652  
653 BEGIN {
654 67 ▶ my $checkint = 1111;
Subroutine BEGIN: called CC=3 SCAR=11.0
655 67 for my $d (5..64) {
656 1139 $checkint .= 1;
657 1139 my $int = eval qq| $checkint |;
658 1139 ▶ if ($int =~ /[eE]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($int =~ /[eE]/) 67 1072 1139
659 67 $max_intsize = $d - 1;
660 67 last;
661 }
662 }
663 }
664  
665 { # PARSE
666  
667 67 my %escapes = ( # by Jeremy Muhlich <jmuhlich [at] bitflood.org>
668 b => "\b",
669 t => "\t",
670 n => "\n",
671 f => "\f",
672 r => "\r",
673 '\\' => '\\',
674 '"' => '"',
675 '/' => '/',
676 );
677  
678 sub _detect_utf_encoding {
679 12477 ▶ my $text = shift;
Subroutine _detect_utf_encoding: called CC=10 SCAR=25.0
680 12477 my @octets = unpack('C4', $text);
681 12477 ▶ return 'unknown' unless defined $octets[3];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $octets[3] 20 12457 12477
682 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
683 : (!$octets[0] and $octets[1]) ? 'UTF-16BE'
684 : (!$octets[0] and !$octets[1]) ? 'UTF-32BE'
685 : ( $octets[2] ) ? 'UTF-16LE'
686 : (!$octets[2] ) ? 'UTF-32LE'
687 : 'unknown';
688 }
689  
690 sub PP_decode_json {
691 25336 ▶ my ($self, $text, $want_offset) = @_;
Subroutine PP_decode_json: called CC=16 SCAR=27.7
Pod undocumented
692  
693 25336 @$self{qw/at ch depth/} = (0, '', 0);
694  
695 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
696 4 $self->_decode_error("malformed JSON string, neither array, object, number, string or atom");
697 }
698  
699 25332 my $props = $self->{PROPS};
700  
701 25332 ▶ if ( $self->{PROPS}[P_UTF8] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROPS'}[2]) { } 12477 12855 25332
702 12477 my $encoding = _detect_utf_encoding($text);
703 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
704 3 require Encode;
705 3 Encode::from_to($text, $encoding, 'utf-8');
706 } else {
707 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") 1 12473 12474
708 }
709 }
710 else {
711 12855 utf8::encode( $text );
712 }
713  
714 25331 $self->{len} = length $text;
715 25331 $self->{text} = $text;
716  
717 25331 ▶ if ($self->{max_size} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"max_size"} > 1) 2 25329 25331
718 67 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
719 2 my $bytes = length $text;
720 $self->_decode_error(
721 sprintf("attempted decode of JSON text of %s bytes size, but max_size is set to %s"
722 , $bytes, $self->{max_size}), 1
723 2 ▶ ) if ($bytes > $self->{max_size});
Branch: 1 branch
BranchTrueFalseTotal
if $bytes > $self->{"max_size"} 1 1 2
724 }
725  
726 25330 $self->_white(); # remove head white space
727  
728 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
729  
730 25328 my $result = $self->_value();
731  
732 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
733 5 $self->_decode_error(
734 'JSON text must be an object or array (but found number, string, true, false or null,'
735 . ' use allow_nonref to allow this)', 1);
736 }
737  
738 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
739  
740 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
741  
742 25246 $self->_white(); # remove tail white space
743  
744 25246 ▶ return ( $result, $consumed ) if $want_offset; # all right if decode_prefix
Branch: 1 branch
BranchTrueFalseTotal
if $want_offset 304 24942 25246
745  
746 24942 ▶ $self->_decode_error("garbage after JSON object") if defined $self->{ch};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ch"} 12 24930 24942
747  
748 24930 $result;
749 }
750  
751  
752 sub _next_chr {
753 36803671 ▶ my $self = shift;
Subroutine _next_chr: called CC=2 SCAR=6.9
754 36803671 ▶ return $self->{ch} = undef if($self->{at} >= $self->{len});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"at"} >= $self->{"len"} 25137 36778534 36803671
755 36778534 $self->{ch} = substr($self->{text}, $self->{at}++, 1);
756 }
757  
758  
759 sub _value {
760 56178 ▶ my $self = shift;
Subroutine _value: called CC=10 SCAR=23.1
761 56178 $self->_white();
762 56178 my $ch = $self->{ch};
763 56178 ▶ return if(!defined $ch);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ch 0 56178 56178
764 56178 ▶ return $self->_object() if($ch eq '{');
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "{" 2261 53917 56178
765 53917 ▶ return $self->_array() if($ch eq '[');
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "[" 26316 27601 53917
766 27601 ▶ return $self->_tag() if($ch eq '(');
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq "(" 1 27600 27601
767 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
2655941037
$self->{"PROPS"}[15] and $ch eq "'"
!ll&&!rl&&r
103902
MC/DC0%0/3
$ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'"
$ch eq "\"" $self->{"PROPS"}[15] $ch eq "'"
Truth table50%2/4
A or B and C
A= $ch eq "\""B= $self->{"PROPS"}[15]C= $ch eq "'"
ABCresult
1XX1
0111
00X0
0100
768 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
769 93 return $self->_word();
770 }
771  
772 sub _string {
773 30301 ▶ my $self = shift;
Subroutine _string: called CC=27 SCAR=33.3
774 30301 my $utf16;
775 my $is_utf8;
776  
777 30301 my $utf8_len = 0;
778  
779 30301 my $s = ''; # basically UTF8 flag on
780  
781 30301 my $ch = $self->{ch};
782 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
3029254
$self->{"PROPS"}[15] and $ch eq "'"
!ll&&!rl&&r
504
MC/DC0%0/3
$ch eq "\"" or $self->{"PROPS"}[15] and $ch eq "'"
$ch eq "\"" $self->{"PROPS"}[15] $ch eq "'"
Truth table50%2/4
A or B and C
A= $ch eq "\""B= $self->{"PROPS"}[15]C= $ch eq "'"
ABCresult
1XX1
0111
00X0
0100
783 30296 my $boundChar = $ch;
784  
785 30296 ▶ OUTER: while( defined($ch = $self->_next_chr()) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($ch = $self->_next_chr)) 10763465 1 10763466
786  
787 10763465 ▶ if($ch eq $boundChar){
Branch: 2 branches
BranchTrueFalseTotal
if ($ch eq $boundChar) { } 30280 10733185 10763465
elsif ($ch eq '\\') { } 5300299 5432886 10733185
788 30280 $self->_next_chr();
789  
790 30280 ▶ if ($utf16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($utf16) 1 30279 30280
791 1 $self->_decode_error("missing low surrogate character in surrogate pair");
792 }
793  
794 30279 ▶ utf8::decode($s) if($is_utf8);
Branch: 1 branch
BranchTrueFalseTotal
if $is_utf8 24800 5479 30279
795  
796 30279 return $s;
797 }
798 elsif($ch eq '\\'){
799 5300299 $ch = $self->_next_chr();
800 5300299 ▶ if(exists $escapes{$ch}){
Branch: 2 branches
BranchTrueFalseTotal
if (exists $escapes{$ch}) { } 152492 5147807 5300299
elsif ($ch eq 'u') { } 5147803 4 5147807
801 152492 $s .= $escapes{$ch};
802 }
803 elsif($ch eq 'u'){ # UNICODE handling
804 5147803 my $u = '';
805  
806 5147803 for(1..4){
807 20591212 $ch = $self->_next_chr();
808 20591212 ▶ last OUTER if($ch !~ /[0-9a-fA-F]/);
Branch: 1 branch
BranchTrueFalseTotal
unless $ch =~ /[0-9a-fA-F]/ 0 20591212 20591212
809 20591212 $u .= $ch;
810 }
811  
812 # U+D800 - U+DBFF
813 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
814 1127978 $utf16 = $u;
815 }
816 # U+DC00 - U+DFFF
817 elsif ($u =~ /^[dD][c-fC-F][0-9a-fA-F]{2}/) { # UTF-16 low surrogate?
818 1127977 ▶ unless (defined $utf16) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $utf16) 1 1127976 1127977
819 1 $self->_decode_error("missing high surrogate character in surrogate pair");
820 }
821 1127976 $is_utf8 = 1;
822 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
823 1127976 $utf16 = undef;
824 }
825 else {
826 2891848 ▶ if (defined $utf16) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $utf16) 1 2891847 2891848
827 1 $self->_decode_error("surrogate pair expected");
828 }
829  
830 2891847 my $hex = hex( $u );
831 2891847 ▶ if ( chr $u =~ /[[:^ascii:]]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (chr $u =~ /[[:^ascii:]]/) { } 2891847 0 2891847
832 2891847 $is_utf8 = 1;
833 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
834 }
835 else {
836 0 $s .= chr $hex;
837 }
838 }
839  
840 }
841 else{
842 4 ▶ unless ($self->{PROPS}[P_LOOSE]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"PROPS"}[12]) 4 0 4
843 4 $self->{at} -= 2;
844 4 $self->_decode_error('illegal backslash escape sequence in string');
845 }
846 0 $s .= $ch;
847 }
848 }
849 else{
850  
851 5432886 ▶ if ( $ch =~ /[[:^ascii:]]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /[[:^ascii:]]/) 3441000 1991886 5432886
852 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
853 5 $self->{at} -= 1;
854 5 $self->_decode_error("malformed UTF-8 character in JSON string");
855 }
856 else {
857 3440995 $self->{at} += $utf8_len - 1;
858 }
859  
860 3440995 $is_utf8 = 1;
861 }
862  
863 5432881 ▶ if (!$self->{PROPS}[P_LOOSE]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"PROPS"}[12]) 5432881 0 5432881
864 5432881 ▶ if ($ch =~ $invalid_char_re) { # '/' ok
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /$invalid_char_re/) 4 5432877 5432881
865 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
866 4 $self->{at}--;
867 4 $self->_decode_error(sprintf "invalid character 0x%X"
868 . " encountered while parsing JSON string",
869 ord $ch);
870 }
871 }
872 }
873  
874 5432877 $s .= $ch;
875 }
876 }
877 }
878  
879 6 $self->_decode_error("unexpected end of string while parsing JSON string");
880 }
881  
882  
883 sub _white {
884 171150 ▶ my $self = shift;
Subroutine _white: called CC=19 SCAR=46.5
885 171150 my $ch = $self->{ch};
886 171150 ▶ while( defined $ch ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 200701 25128 225829
887 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
888 54670 $ch = $self->_next_chr();
889 }
890 ▶ 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
891 0 $ch = $self->_next_chr();
892 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
893 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
894 }
895 ▶ 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
896 0 $ch = $self->_next_chr();
897 0 while(1){
898 0 ▶ if(defined $ch){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) { } 0 0 0
899 0 ▶ if($ch eq '*'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq '*') { } 0 0 0
900 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
901 0 $ch = $self->_next_chr();
902 0 last;
903 }
904 }
905 else{
906 0 $ch = $self->_next_chr();
907 }
908 }
909 else{
910 0 $self->_decode_error("Unterminated comment");
911 }
912 }
913 0 next;
914 }
915 else{
916 0 $self->{at}--;
917 0 $self->_decode_error("malformed JSON string, neither array, object, number, string or atom");
918 }
919 }
920 else{
921 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
922 9 pos($self->{text}) = $self->{at};
923 9 $self->{text} =~ /\G([^\n]*(?:\r\n|\r|\n|$))/g;
924 9 $self->{at} = pos($self->{text});
925 9 $ch = $self->_next_chr;
926 9 next;
927 }
928  
929 146022 last;
930 }
931 }
932 }
933  
934  
935 sub _array {
936 26316 ▶ my $self = shift;
Subroutine _array: called CC=13 SCAR=25.7
937 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
938  
939 $self->_decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)')
940 26316 ▶ if (++$self->{depth} > $self->{max_depth});
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"depth"} > $self->{"max_depth"} 3 26313 26316
941  
942 26313 $self->_next_chr();
943 26313 $self->_white();
944  
945 26313 my $ch = $self->{ch};
946 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
947 23 --$self->{depth};
948 23 $self->_next_chr();
949 23 return $a;
950 }
951 else {
952 26290 ▶ while(defined($ch)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 27114 0 27114
953 27114 push @$a, $self->_value();
954  
955 26547 $self->_white();
956  
957 26547 $ch = $self->{ch};
958 26547 ▶ if (!defined $ch) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ch) 3 26544 26547
959 3 last;
960 }
961  
962 26544 ▶ if($ch eq ']'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "]") 25715 829 26544
963 25715 --$self->{depth};
964 25715 $self->_next_chr();
965 25715 return $a;
966 }
967  
968 829 ▶ if($ch ne ','){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch ne ",") 3 826 829
969 3 last;
970 }
971  
972 826 $self->_next_chr();
973 826 $self->_white();
974  
975 826 $ch = $self->{ch};
976 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
977 2 --$self->{depth};
978 2 $self->_next_chr();
979 2 return $a;
980 }
981  
982 }
983 }
984  
985 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
986 6 $self->_decode_error(", or ] expected while parsing array");
987 }
988  
989 sub _tag {
990 1 ▶ my $self = shift;
Subroutine _tag: called CC=10 SCAR=26.6
991 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
992  
993 1 $self->_next_chr();
994 1 $self->_white();
995  
996 1 my $tag = $self->_value();
997 1 ▶ return unless defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 0 1 1
998 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
999  
1000 1 $self->_white();
1001  
1002 1 my $ch = $self->{ch};
1003 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
1004 0 $self->_decode_error(') expected after tag');
1005 }
1006  
1007 1 $self->_next_chr();
1008 1 $self->_white();
1009  
1010 1 my $val = $self->_value();
1011 1 ▶ return unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 1 1
1012 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
1013  
1014 1 ▶ if (!eval { $tag->can('THAW') }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { $tag->can("THAW") } }) 0 1 1
1015 0 ▶ $self->_decode_error('cannot decode perl-object (package does not exist)') if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
1016 0 $self->_decode_error('cannot decode perl-object (package does not have a THAW method)');
1017 }
1018 1 $tag->THAW('JSON', @$val);
1019 }
1020  
1021 sub _object {
1022 2261 ▶ my $self = shift;
Subroutine _object: called CC=21 SCAR=30.7
1023 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
1024 2261 my $k;
1025  
1026 $self->_decode_error('json text or perl structure exceeds maximum nesting level (max_depth set too low?)')
1027 2261 ▶ if (++$self->{depth} > $self->{max_depth});
Branch: 1 branch
BranchTrueFalseTotal
if ++$self->{"depth"} > $self->{"max_depth"} 0 2261 2261
1028 2261 $self->_next_chr();
1029 2261 $self->_white();
1030  
1031 2261 my $ch = $self->{ch};
1032 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
1033 9 --$self->{depth};
1034 9 $self->_next_chr();
1035 9 ▶ if ($self->{F_HOOK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"F_HOOK"}) 1 8 9
1036 1 return $self->__json_object_hook($o);
1037 }
1038 8 return $o;
1039 }
1040 else {
1041 2252 ▶ while (defined $ch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ch) 3742 1 3743
1042 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
1043 3737 $self->_white();
1044  
1045 3737 $ch = $self->{ch};
1046 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
1047 3 $self->{at}--;
1048 3 $self->_decode_error("':' expected");
1049 }
1050  
1051 3734 $self->_next_chr();
1052 3734 $o->{$k} = $self->_value();
1053 3217 $self->_white();
1054  
1055 3217 $ch = $self->{ch};
1056 3217 ▶ last if (!defined $ch);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ch 2 3215 3217
1057  
1058 3215 ▶ if($ch eq '}'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "}") 1718 1497 3215
1059 1718 --$self->{depth};
1060 1718 $self->_next_chr();
1061 1718 ▶ if ($self->{F_HOOK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"F_HOOK"}) 8 1710 1718
1062 8 return $self->__json_object_hook($o);
1063 }
1064 1710 return $o;
1065 }
1066  
1067 1497 ▶ if($ch ne ','){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch ne ",") 5 1492 1497
1068 5 last;
1069 }
1070  
1071 1492 $self->_next_chr();
1072 1492 $self->_white();
1073  
1074 1492 $ch = $self->{ch};
1075 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
1076 1 --$self->{depth};
1077 1 $self->_next_chr();
1078 1 ▶ if ($self->{F_HOOK}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"F_HOOK"}) 0 1 1
1079 0 return $self->__json_object_hook($o);
1080 }
1081 1 return $o;
1082 }
1083  
1084 }
1085  
1086 }
1087  
1088 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
1089 8 $self->_decode_error(", or } expected while parsing object/hash");
1090 }
1091  
1092  
1093 sub _bareKey { # doesn't strictly follow Standard ECMA-262 3rd Edition
1094 2 ▶ my $self = shift;
Subroutine _bareKey: called CC=2 SCAR=6.9
1095 2 my $key;
1096 2 my $ch = $self->{ch};
1097 2 ▶ while($ch =~ /[\$\w[:^ascii:]]/){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch =~ /[\$\w[:^ascii:]]/) 6 2 8
1098 6 $key .= $ch;
1099 6 $ch = $self->_next_chr();
1100 }
1101 2 return $key;
1102 }
1103  
1104  
1105 sub _word {
1106 93 ▶ my $self = shift;
Subroutine _word: called CC=10 SCAR=23.0
1107 93 my $word = substr($self->{text},$self->{at}-1,4);
1108  
1109 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
1110 14 $self->{at} += 3;
1111 14 $self->_next_chr;
1112 14 ▶ return defined $self->{true} ? $self->{true} : $JSON::PP::true;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'true'} ? : 3 11 14
1113 }
1114 elsif($word eq 'null'){
1115 44 $self->{at} += 3;
1116 44 $self->_next_chr;
1117 44 return undef;
1118 }
1119 elsif($word eq 'fals'){
1120 11 $self->{at} += 3;
1121 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
1122 11 $self->{at}++;
1123 11 $self->_next_chr;
1124 11 ▶ return defined $self->{false} ? $self->{false} : $JSON::PP::false;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'false'} ? : 3 8 11
1125 }
1126 }
1127  
1128 24 $self->{at}--; # for decode_error report
1129  
1130 24 ▶ $self->_decode_error("'null' expected") if ($word =~ /^n/);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^n/ 1 23 24
1131 23 ▶ $self->_decode_error("'true' expected") if ($word =~ /^t/);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^t/ 1 22 23
1132 22 ▶ $self->_decode_error("'false' expected") if ($word =~ /^f/);
Branch: 1 branch
BranchTrueFalseTotal
if $word =~ /^f/ 0 22 22
1133 22 $self->_decode_error("malformed JSON string, neither array, object, number, string or atom");
1134 }
1135  
1136  
1137 sub _number {
1138 946 ▶ my $self = shift;
Subroutine _number: called CC=32 SCAR=34.7
1139 946 my $n = '';
1140 946 my $v;
1141 my $is_dec;
1142 946 my $is_exp;
1143  
1144 946 my $ch = $self->{ch};
1145 946 ▶ if($ch eq '-'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "-") 41 905 946
1146 41 $n = '-';
1147 41 $ch = $self->_next_chr;
1148 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
1149 1 $self->_decode_error("malformed number (no digits after initial minus)");
1150 }
1151 }
1152  
1153 # According to RFC4627, hex or oct digits are invalid.
1154 945 ▶ if($ch eq '0'){
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq 0) 113 832 945
1155 113 my $peek = substr($self->{text},$self->{at},1);
1156 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
1157 5 $self->_decode_error("malformed number (leading zero must not be followed by another digit)");
1158 }
1159 108 $n .= $ch;
1160 108 $ch = $self->_next_chr;
1161 }
1162  
1163 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
1164 1038 $n .= $ch;
1165 1038 $ch = $self->_next_chr;
1166 }
1167  
1168 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
1169 49 $n .= '.';
1170 49 $is_dec = 1;
1171  
1172 49 $ch = $self->_next_chr;
1173 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
1174 1 $self->_decode_error("malformed number (no digits after decimal point)");
1175 }
1176 else {
1177 48 $n .= $ch;
1178 }
1179  
1180 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
1181 97 $n .= $ch;
1182 }
1183 }
1184  
1185 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
1089237
$ch eq "e" or $ch eq "E"
l!l&&r!l&&!r
3325871
MC/DC66%2/3
defined $ch and $ch eq "e" || $ch eq "E"
defined $ch $ch eq "e" $ch eq "E"
Truth table75%3/4
A and B or C
A= defined $chB= $ch eq "e"C= $ch eq "E"
ABCresult
0XX0
1000
11X1
1011
1186 58 $n .= $ch;
1187 58 $is_exp = 1;
1188 58 $ch = $self->_next_chr;
1189  
1190 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
1191 38 $n .= $ch;
1192 38 $ch = $self->_next_chr;
1193 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
1194 2 $self->_decode_error("malformed number (no digits after exp sign)");
1195 }
1196 36 $n .= $ch;
1197 }
1198 ▶ 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
1199 18 $n .= $ch;
1200 }
1201 else {
1202 2 $self->_decode_error("malformed number (no digits after exp sign)");
1203 }
1204  
1205 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
1206 33 $n .= $ch;
1207 }
1208  
1209 }
1210  
1211 935 $v .= $n;
1212  
1213 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
1214 70 ▶ if ($self->{PROPS}[P_ALLOW_BIGNUM]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"PROPS"}[13]) 1 69 70
1215 1 require Math::BigFloat;
1216 1 return Math::BigFloat->new($v);
1217 }
1218 } else {
1219 865 ▶ if (length $v > $max_intsize) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $v > $max_intsize) 1 864 865
1220 1 ▶ if ($self->{PROPS}[P_ALLOW_BIGNUM]) { # from Adam Sussman
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'PROPS'}[13]) { } 1 0 1
1221 1 require Math::BigInt;
1222 1 return Math::BigInt->new($v);
1223 }
1224 else {
1225 0 return "$v";
1226 }
1227 }
1228 }
1229  
1230 933 ▶ return $is_dec ? $v/1.0 : 0+$v;
Branch: 1 branch
BranchTrueFalseTotal
$is_dec ? : 47 886 933
1231 }
1232  
1233 # Compute how many bytes are in the longest legal official Unicode
1234 # character
1235 67 my $max_unicode_length = do {
1236 67 ▶ no warnings 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
1237 67 chr 0x10FFFF;
1238 };
1239 67 utf8::encode($max_unicode_length);
1240 67 $max_unicode_length = length $max_unicode_length;
1241  
1242 sub _is_valid_utf8 {
1243 3441000 ▶ my ($self, $ch, $utf8_len_r) = @_;
Subroutine _is_valid_utf8: called CC=4 SCAR=13.9
1244  
1245 # Returns undef (setting $utf8_len to 0) unless the next bytes in $text
1246 # comprise a well-formed UTF-8 encoded character, in which case,
1247 # return those bytes, setting $utf8_len to their count.
1248  
1249 3441000 my $start_point = substr($self->{text}, $self->{at} - 1);
1250  
1251 # Look no further than the maximum number of bytes in a single
1252 # character
1253 3441000 my $limit = $max_unicode_length;
1254 3441000 ▶ $limit = length($start_point) if $limit > length($start_point);
Branch: 1 branch
BranchTrueFalseTotal
if $limit > length $start_point 9 3440991 3441000
1255  
1256 # Find the number of bytes comprising the first character in $text
1257 # (without having to know the details of its internal representation).
1258 # This loop will iterate just once on well-formed input.
1259 3441000 ▶ while ($limit > 0) { # Until we succeed or exhaust the input
Branch: 1 branch
BranchTrueFalseTotal
if ($limit > 0) 4681125 5 4681130
1260 4681125 my $copy = substr($start_point, 0, $limit);
1261  
1262 # decode() will return true if all bytes are valid; false
1263 # if any aren't.
1264 4681125 ▶ if (utf8::decode($copy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (utf8::decode($copy)) 3440995 1240130 4681125
1265  
1266 # Is valid: get the first character, convert back to bytes,
1267 # and return those bytes.
1268 3440995 $copy = substr($copy, 0, 1);
1269 3440995 utf8::encode($copy);
1270 3440995 $$utf8_len_r = length $copy;
1271 3440995 return substr($start_point, 0, $$utf8_len_r);
1272 }
1273  
1274 # If it didn't work, it could be that there is a full legal character
1275 # followed by a partial or malformed one. Narrow the window and
1276 # try again.
1277 1240130 $limit--;
1278 }
1279  
1280 # Failed to find a legal UTF-8 character.
1281 5 $$utf8_len_r = 0;
1282 5 return;
1283 }
1284  
1285  
1286 sub _decode_error {
1287 101 ▶ my $self = shift;
Subroutine _decode_error: called CC=13 SCAR=26.0
1288 101 my $error = shift;
1289 101 my $no_rep = shift;
1290 101 ▶ my $str = defined $self->{text} ? substr($self->{text}, $self->{at}) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'text'} ? : 97 4 101
1291 101 my $mess = '';
1292 101 my $type = 'U*';
1293  
1294 101 for my $c ( unpack( $type, $str ) ) { # emulate pv_uni_display() ?
1295 411 my $chr_c = chr($c);
1296 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
1297 : $chr_c =~ /[[:print:]]/ ? $chr_c
1298 : $chr_c eq '\a' ? '\a'
1299 : $chr_c eq '\t' ? '\t'
1300 : $chr_c eq '\n' ? '\n'
1301 : $chr_c eq '\r' ? '\r'
1302 : $chr_c eq '\f' ? '\f'
1303 : sprintf('\x{%x}', $c)
1304 ;
1305 411 ▶ if ( length $mess >= 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $mess >= 20) 10 401 411
1306 10 $mess .= '...';
1307 10 last;
1308 }
1309 }
1310  
1311 101 ▶ unless ( length $mess ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $mess) 33 68 101
1312 33 $mess = '(end of string)';
1313 }
1314  
1315 Carp::croak (
1316 101 ▶ $no_rep ? "$error" : "$error, at character offset $self->{at} (before \"$mess\")"
Branch: 1 branch
BranchTrueFalseTotal
$no_rep ? : 6 95 101
1317 );
1318  
1319 }
1320  
1321  
1322 sub __json_object_hook {
1323 9 ▶ my $self = shift;
Subroutine __json_object_hook: called CC=10 SCAR=23.5
1324 9 my $o = $_[0];
1325 9 my @ks = keys %{$o};
1326  
1327 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
1328 4 my @val = $self->{cb_sk_object}{ $ks[0] }->( $o->{$ks[0]} );
1329 4 ▶ if (@val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@val == 0) { } 1 3 4
elsif (@val == 1) { } 3 0 3
1330 1 return $o;
1331 }
1332 elsif (@val == 1) {
1333 3 return $val[0];
1334 }
1335 else {
1336 0 Carp::croak("filter_json_single_key_object callbacks must not return more than one scalar");
1337 }
1338 }
1339  
1340 5 ▶ my @val = $self->{cb_object}->($o) if ($self->{cb_object});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"cb_object"} 4 1 5
1341 5 ▶ if (@val == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@val == 0) { } 3 2 5
elsif (@val == 1) { } 2 0 2
1342 3 return $o;
1343 }
1344 elsif (@val == 1) {
1345 2 return $val[0];
1346 }
1347 else {
1348 0 Carp::croak("filter_json_object callbacks must not return more than one scalar");
1349 }
1350 }
1351  
1352 } # PARSE
1353  
1354  
1355 67 sub _decode_surrogates { # from perlunicode
1356 1127976 ▶ my $uni = 0x10000 + (hex($_[0]) - 0xD800) * 0x400 + (hex($_[1]) - 0xDC00);
Subroutine _decode_surrogates: called CC=1 SCAR=0.0
1357 1127976 my $un = pack('U*', $uni);
1358 1127976 utf8::encode( $un );
1359 1127976 return $un;
1360 }
1361  
1362  
1363 sub _decode_unicode {
1364 2891847 ▶ my $un = pack('U', hex shift);
Subroutine _decode_unicode: called CC=1 SCAR=0.0
1365 2891847 utf8::encode( $un );
1366 2891847 return $un;
1367 }
1368  
1369 sub incr_parse {
1370 744 ▶ local $Carp::CarpLevel = 1;
Subroutine incr_parse: called CC=2 SCAR=7.1
Pod documented
1371 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
1372 }
1373  
1374  
1375 sub incr_skip {
1376 2 ▶ ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_skip;
Subroutine incr_skip: called CC=2 SCAR=9.2
Pod documented
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
1377 }
1378  
1379  
1380 sub incr_reset {
1381 0 ▶ ( $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new )->incr_reset;
Subroutine incr_reset: not called CC=2 SCAR=17.9
Pod documented
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
1382 }
1383  
1384 sub incr_text : lvalue {
1385 304 ▶ $_[0]->{_incr_parser} ||= JSON::PP::IncrParser->new;
Subroutine incr_text: called CC=3 SCAR=13.3
Pod documented
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
1386  
1387 304 ▶ if ( $_[0]->{_incr_parser}->{incr_pos} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"_incr_parser"}{"incr_pos"}) 0 304 304
1388 0 Carp::croak("incr_text cannot be called when the incremental parser already started parsing");
1389 }
1390 304 $_[0]->{_incr_parser}->{incr_text};
1391 }
1392  
1393  
1394 ###############################
1395 # Utilities
1396 #
1397  
1398 # shamelessly copied and modified from JSON::XS code.
1399  
1400 67 $JSON::PP::true = do { bless \(my $dummy = 1), "JSON::PP::Boolean" };
1401 67 $JSON::PP::false = do { bless \(my $dummy = 0), "JSON::PP::Boolean" };
1402  
1403 sub is_bool {
1404 11 ▶ if (blessed $_[0]) {
Subroutine is_bool: called CC=4 SCAR=15.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($_[0])) { } 2 9 11
1405 return (
1406 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
1407 or $_[0]->isa("Types::Serialiser::BooleanBase")
1408 or $_[0]->isa("JSON::XS::Boolean")
1409 );
1410 }
1411 elsif (CORE_BOOL) {
1412 67 ▶ BEGIN { CORE_BOOL and warnings->unimport('experimental::builtin') }
Subroutine BEGIN: called CC=1 SCAR=0.0
1413 9 return builtin::is_bool($_[0]);
1414 }
1415 0 return !!0;
1416 }
1417  
1418 3 ▶sub true { $JSON::PP::true }
Subroutine true: called CC=1 SCAR=0.0
Pod documented
1419 3 ▶sub false { $JSON::PP::false }
Subroutine false: called CC=1 SCAR=0.0
Pod documented
1420 0 ▶sub null { undef; }
Subroutine null: not called CC=1 SCAR=6.9
Pod documented
1421  
1422 ###############################
1423  
1424 package JSON::PP::IncrParser;
1425  
1426 67 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1427  
1428 67 ▶use constant INCR_M_WS => 0; # initial whitespace skipping
Subroutine BEGIN: called CC=1 SCAR=0.0
1429 67 ▶use constant INCR_M_STR => 1; # inside string
Subroutine BEGIN: called CC=1 SCAR=0.0
1430 67 ▶use constant INCR_M_BS => 2; # inside backslash
Subroutine BEGIN: called CC=1 SCAR=0.0
1431 67 ▶use constant INCR_M_JSON => 3; # outside anything, count nesting
Subroutine BEGIN: called CC=1 SCAR=0.0
1432 67 ▶use constant INCR_M_C0 => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
1433 67 ▶use constant INCR_M_C1 => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
1434 67 ▶use constant INCR_M_TFN => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
1435 67 ▶use constant INCR_M_NUM => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
1436  
1437 67 our $VERSION = '1.01';
1438  
1439 sub new {
1440 57 ▶ my ( $class ) = @_;
Subroutine new: called CC=1 SCAR=0.0
1441  
1442 57 bless {
1443 incr_nest => 0,
1444 incr_text => undef,
1445 incr_pos => 0,
1446 incr_mode => 0,
1447 }, $class;
1448 }
1449  
1450  
1451 sub incr_parse {
1452 744 ▶ my ( $self, $coder, $text ) = @_;
Subroutine incr_parse: called CC=18 SCAR=28.9
1453  
1454 744 ▶ $self->{incr_text} = '' unless ( defined $self->{incr_text} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"incr_text"} 57 687 744
1455  
1456 744 ▶ if ( defined $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text) 402 342 744
1457 402 $self->{incr_text} .= $text;
1458 }
1459  
1460 744 ▶ if ( defined wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 383 361 744
1461 383 my $max_size = $coder->get_max_size;
1462 383 my $p = $self->{incr_pos};
1463 383 my @ret;
1464 {
1465 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
1466 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
1467 393 $self->_incr_parse( $coder );
1468  
1469 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
1470 1 Carp::croak("attempted decode of JSON text of $self->{incr_pos} bytes size, but max_size is set to $max_size");
1471 }
1472 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
1473 # as an optimisation, do not accumulate white space in the incr buffer
1474 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
1475 7 $self->{incr_pos} = 0;
1476 7 $self->{incr_text} = '';
1477 }
1478 83 last;
1479 }
1480 }
1481  
1482 309 ▶ unless ( $coder->get_utf8 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($coder->get_utf8) 301 8 309
1483 301 utf8::decode( $self->{incr_text} );
1484 }
1485  
1486 309 my ($obj, $offset) = $coder->PP_decode_json( $self->{incr_text}, 0x00000001 );
1487 298 push @ret, $obj;
1488 67 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
1489 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
1490 298 $self->{incr_pos} = 0;
1491 298 $self->{incr_nest} = 0;
1492 298 $self->{incr_mode} = 0;
1493 298 ▶ last unless wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 287 11 298
1494 } while ( wantarray );
1495 }
1496  
1497 370 ▶ if ( wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 7 363 370
1498 7 return @ret;
1499 }
1500 else { # in scalar context
1501 363 ▶ return defined $ret[0] ? $ret[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ret[0] ? : 287 76 363
1502 }
1503 }
1504 }
1505  
1506  
1507 sub _incr_parse {
1508 393 ▶ my ($self, $coder) = @_;
Subroutine _incr_parse: called CC=54 SCAR=40.9
1509 393 my $text = $self->{incr_text};
1510 393 my $len = length $text;
1511 393 my $p = $self->{incr_pos};
1512  
1513 INCR_PARSE:
1514 393 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 363 80 443
1515 3084 my $s = substr( $text, $p, 1 );
1516 3084 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 3084 3084
1517 3084 my $mode = $self->{incr_mode};
1518  
1519 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
1520 335 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 594 7 601
1521 594 $s = substr( $text, $p, 1 );
1522 594 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 594 594
1523 594 ▶ if ( ord($s) > ord " " ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ord $s > 32) 328 266 594
1524 328 ▶ if ( $s eq '#' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq '#') { } 6 322 328
1525 6 $self->{incr_mode} = INCR_M_C0;
1526 6 redo INCR_PARSE;
1527 } else {
1528 322 $self->{incr_mode} = INCR_M_JSON;
1529 322 redo INCR_PARSE;
1530 }
1531 }
1532 266 $p++;
1533 }
1534 } elsif ( $mode == INCR_M_BS ) {
1535 0 $p++;
1536 0 $self->{incr_mode} = INCR_M_STR;
1537 0 redo INCR_PARSE;
1538 ▶ } 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
1539 9 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 45 0 45
1540 45 $s = substr( $text, $p, 1 );
1541 45 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 45 45
1542 45 ▶ if ( $s eq "\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "\n") 9 36 45
1543 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
1544 9 last;
1545 }
1546 36 $p++;
1547 }
1548 9 next;
1549 } elsif ( $mode == INCR_M_TFN ) {
1550 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
1551 35 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 140 0 140
1552 140 $s = substr( $text, $p++, 1 );
1553 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
1554 35 last;
1555 }
1556 35 $p--;
1557 35 $self->{incr_mode} = INCR_M_JSON;
1558  
1559 35 ▶ last INCR_PARSE unless $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incr_nest"} 0 35 35
1560 35 redo INCR_PARSE;
1561 } elsif ( $mode == INCR_M_NUM ) {
1562 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
1563 396 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 482 7 489
1564 482 $s = substr( $text, $p++, 1 );
1565 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
1566 389 last;
1567 }
1568 396 $p--;
1569 396 $self->{incr_mode} = INCR_M_JSON;
1570  
1571 396 ▶ last INCR_PARSE unless $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incr_nest"} 18 378 396
1572 378 redo INCR_PARSE;
1573 } elsif ( $mode == INCR_M_STR ) {
1574 805 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 84413 25 84438
1575 84413 $s = substr( $text, $p, 1 );
1576 84413 ▶ last INCR_PARSE unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 84413 84413
1577 84413 ▶ if ( $s eq '"' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s eq '"') { } 780 83633 84413
elsif ($s eq '\\') { } 508 83125 83633
1578 780 $p++;
1579 780 $self->{incr_mode} = INCR_M_JSON;
1580  
1581 780 ▶ last INCR_PARSE unless $self->{incr_nest};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"incr_nest"} 20 760 780
1582 760 redo INCR_PARSE;
1583 }
1584 elsif ( $s eq '\\' ) {
1585 508 $p++;
1586 508 ▶ if ( !defined substr($text, $p, 1) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined substr($text, $p, 1)) 0 508 508
1587 0 $self->{incr_mode} = INCR_M_BS;
1588 0 last INCR_PARSE;
1589 }
1590 }
1591 83633 $p++;
1592 }
1593 } elsif ( $mode == INCR_M_JSON ) {
1594 1500 ▶ while ( $len > $p ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $p) 3614 9 3623
1595 3614 $s = substr( $text, $p++, 1 );
1596 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
1597 0 $p--;
1598 0 last INCR_PARSE;
1599 } elsif ( $s =~ /^[\t\n\r ]$/) {
1600 724 ▶ if ( !$self->{incr_nest} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"incr_nest"}) 0 724 724
1601 0 $p--; # do not eat the whitespace, let the next round do it
1602 0 last INCR_PARSE;
1603 }
1604 724 next;
1605 ▶ } 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
1606 36 $self->{incr_mode} = INCR_M_TFN;
1607 36 redo INCR_PARSE;
1608 } elsif ( $s =~ /^[0-9\-]$/ ) {
1609 398 $self->{incr_mode} = INCR_M_NUM;
1610 398 redo INCR_PARSE;
1611 } elsif ( $s eq '"' ) {
1612 783 $self->{incr_mode} = INCR_M_STR;
1613 783 redo INCR_PARSE;
1614 ▶ } 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
1615 383 ▶ if ( ++$self->{incr_nest} > $coder->get_max_depth ) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$self->{"incr_nest"} > $coder->get_max_depth) 1 382 383
1616 1 Carp::croak('json text or perl structure exceeds maximum nesting level (max_depth set too low?)');
1617 }
1618 382 next;
1619 ▶ } 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
1620 369 ▶ if ( --$self->{incr_nest} <= 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$self->{"incr_nest"} <= 0) 270 99 369
1621 270 last INCR_PARSE;
1622 }
1623 } elsif ( $s eq '#' ) {
1624 3 $self->{incr_mode} = INCR_M_C1;
1625 3 redo INCR_PARSE;
1626 }
1627 }
1628 }
1629 }
1630  
1631 392 $self->{incr_pos} = $p;
1632 392 ▶ $self->{incr_parsing} = $p ? 1 : 0; # for backward compatibility
Branch: 1 branch
BranchTrueFalseTotal
$p ? : 351 41 392
1633 }
1634  
1635  
1636 sub incr_text {
1637 0 ▶ if ( $_[0]->{incr_pos} ) {
Subroutine incr_text: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0]{"incr_pos"}) 0 0 0
1638 0 Carp::croak("incr_text cannot be called when the incremental parser already started parsing");
1639 }
1640 0 $_[0]->{incr_text};
1641 }
1642  
1643  
1644 sub incr_skip {
1645 2 ▶ my $self = shift;
Subroutine incr_skip: called CC=1 SCAR=0.0
1646 2 $self->{incr_text} = substr( $self->{incr_text}, $self->{incr_pos} );
1647 2 $self->{incr_pos} = 0;
1648 2 $self->{incr_mode} = 0;
1649 2 $self->{incr_nest} = 0;
1650 }
1651  
1652  
1653 sub incr_reset {
1654 0 ▶ my $self = shift;
Subroutine incr_reset: not called CC=1 SCAR=6.9
1655 0 $self->{incr_text} = undef;
1656 0 $self->{incr_pos} = 0;
1657 0 $self->{incr_mode} = 0;
1658 0 $self->{incr_nest} = 0;
1659 }
1660  
1661 ###############################
1662  
1663  
1664 67 1;
1665 __END__
↑ Summary PP/Boolean.pm »