/usr/local/lib/perl5/5.44.0/JSON/PP.pm

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