Relaxed/Parser.pm

filter: Statementstmt 76.8% 489 / 636 Branchbran 64.8% 192 / 296 Conditioncond 64.1% 93 / 145 MC/DCmcdc 38.7% 31 / 80 Subroutinesub 66.6% 48 / 72 Podpod 0.0% 0 / 37 totaltotal 67.3% 853 / 1266 CC 215 SCAR 31.6
CC
215
Cov
72%
resolve
110.0
__ANON__
65.9
__ANON__
35.1
CRAP 23.5
↑ Summary Relaxed/ErrorCodes.pm »
1 #! perl
2  
3 11 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 11 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 package JSON::Relaxed::Parser;
8  
9 11 our $VERSION = "0.098";
10  
11 class JSON::Relaxed::Parser;
12  
13 # Instance data.
14 6 ▶field $data :mutator; # RJSON string being parser
Subroutine data: called CC=1 SCAR=0.0
Pod undocumented
15 11 field @pretoks; # string in pre-tokens
16 11 field @tokens; # string as tokens
17  
18 # Instance properties.
19  
20 # Enforce strictness to official standard.
21 # Strict true -> RJSON conformant.
22 # Strict false (default) -> RRJSON. Everything goes :).
23 3 field $strict :mutator :param = 0;
24  
25 # Allow extra stuff after the JSON structure.
26 # Strict mode only.
27 0 ▶field $extra_tokens_ok :mutator :param = 0;
Subroutine strict: called CC=1 SCAR=0.4
Pod undocumented
28  
29 # Define the values to be used for true and false.
30 0 ▶field $booleans :mutator :param = 1;
Subroutine extra_tokens_ok: not called CC=1 SCAR=0.4
Pod undocumented
31  
32 # Signal error with exceptions.
33 20 ▶field $croak_on_error :mutator :param = 1;
Subroutine booleans: called CC=1 SCAR=0.0
Pod undocumented
34 1 ▶field $croak_on_error_internal;
Subroutine croak_on_error: called CC=1 SCAR=0.0
Pod undocumented
35  
36 # Some non-strict extensions can be controlled individually.
37 # This may disappear in some futer version, so do not use.
38 # Extension: a.b:c -> a:{b:c}
39 ## Non-strict only.
40 0 field $combined_keys :mutator :param = 1;
41  
42 # Extension: a:b -> {a:b} (if outer)
43 ## Non-strict only.
44 0 ▶field $implied_outer_hash :mutator :param = 1;
Subroutine combined_keys: not called CC=1 SCAR=2.6
Pod undocumented
45  
46 # Extension: = as :, and optional before {, off/on as false/true
47 ## Non-strict only.
48 0 ▶field $prp :mutator :param = 1;
Subroutine implied_outer_hash: not called CC=1 SCAR=0.4
Pod undocumented
49  
50 # Formatted output.
51 0 ▶field $pretty :mutator :param = 0;
Subroutine prp: called CC=1 SCAR=0.4
Pod undocumented
52  
53 # Retain key order. Warning: adds a key " key order " to each hash!
54 ## Non-strict only.
55 0 ▶field $key_order :mutator :param = 0;
Subroutine pretty: not called CC=1 SCAR=2.6
Pod undocumented
56  
57 # Error indicators.
58 0 ▶field $err_id :accessor;
Subroutine err_id: called CC=2 SCAR=7.4
Subroutine key_order: not called CC=1 SCAR=0.2
Pod undocumented
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $err_id = shift() 0 2 2
59 2 ▶field $err_msg :accessor;
Subroutine err_msg: called CC=2 SCAR=7.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $err_msg = shift() 0 2 2
60 0 ▶field $err_pos :accessor;
Subroutine err_pos: not called CC=2 SCAR=14.0
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ and $err_pos = shift() 0 0 0
61  
62 30 ▶method decode( $str ) {
Subroutine decode: called CC=1 SCAR=0.0
Pod undocumented
63 30 $croak_on_error_internal = $croak_on_error;
64 30 $self->_decode($str);
65 11 }
66  
67 # Legacy.
68 65 ▶method parse( $str ) {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
69 65 $croak_on_error_internal = 0;
70 65 $self->_decode($str);
71 11 }
72  
73 95 ▶method _decode( $str ) {
Subroutine _decode: called CC=5 SCAR=16.6
74  
75 95 $data = $str;
76 95 ▶ return $self->error('missing-input')
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data and length $data 0 95 95
Condition33%1/3
defined $data and length $data
!ll&&!rl&&r
0095
MC/DC0%0/2
defined $data and length $data
defined $data length $data
Truth table33%1/3
A and B
A= defined $dataB= length $data
ABresult
0X0
100
111
77 unless defined $data && length $data;
78  
79 95 undef $err_id;
80 95 $err_pos = -1;
81 95 undef $err_msg;
82  
83 95 $self->pretokenize;
84 95 ▶ return if $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_error 0 95 95
85  
86 95 $self->tokenize;
87 95 ▶ return $self->error('empty-input') unless @tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 95 95
88  
89 95 $self->structure( top => 1 );
90 11 }
91  
92 ################ Character classifiers ################
93  
94 # Reserved characters.
95 # '[' beginning of array
96 # ']' end of array
97 # '{' beginning of hash
98 # '}' end of hash
99 # ':' delimiter between name and value of hash element
100 # ',' separator between elements in hashes and arrays
101  
102 11 my $p_reserved = q<[,:{}\[\]]>;
103  
104 621 ▶method is_reserved ($c) {
Subroutine is_reserved: called CC=1 SCAR=0.0
Pod undocumented
105 621 $c =~ /^$p_reserved$/;
106 11 }
107  
108 # Newlines. CRLF (Windows), CR (MacOS) and newline (sane systems).
109  
110 11 my $p_newlines = q{(?:\r\n|\r|\n|\\\n)};
111  
112 0 ▶method is_newline ($c) {
Subroutine is_newline: not called CC=1 SCAR=6.9
Pod undocumented
113 0 $c =~ /^$p_newlines$/o;
114 11 }
115  
116 # Quotes. Single, double and backtick.
117  
118 11 my $p_quotes = q{["'`]};
119  
120 178 ▶method is_quote ($c) {
Subroutine is_quote: called CC=1 SCAR=0.0
Pod undocumented
121 178 $c =~ /^$p_quotes$/o;
122 11 }
123  
124 # Numbers. A special case of unquoted strings.
125 11 my $p_number = q{[+-]?\d*\.?\d+(?:[Ee][+-]?\d+)?};
126  
127 95 ▶method pretokenize {
Subroutine pretokenize: called CC=4 SCAR=13.9
Pod undocumented
128  
129 # \u escape (4 hexits)
130 95 my @p = ( qq<\\\\u[[:xdigit:]]{4}> );
131  
132 # Any escaped char (strict mode).
133 95 ▶ if ( $strict ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) { } 4 91 95
134 4 push( @p, qq<\\\\.> );
135 }
136  
137 # Otherwise, match \u{ ... } also.
138 else {
139 91 push( @p, qq<\\\\u\\{[[:xdigit:]]+\\}>, qq<\\\\[^u]> ); # escaped char
140 }
141  
142 95 ▶ if ( $prp && !$strict ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prp and not $strict) 91 4 95
Condition66%2/3
$prp and not $strict
!ll&&!rl&&r
0491
MC/DC50%1/2
$prp and not $strict
$prp not $strict
Truth table66%2/3
A and not(B)
A= $prpB= not $strict
ABresult
0X0
100
111
143 # Add = to the reserved characters
144 91 $p_reserved = q<[,=:{}\[\]]>;
145 # Massage # comments into // comments without affecting position.
146 91 $data =~ s/^(\s*)#.(.*)$/$1\/\/$2/gm;
147 91 $data =~ s/^(\s*)#$/$1 /gm;
148 }
149  
150 95 push( @p, $p_newlines,
151 qq< // [^\\n]* \\n >, # line comment
152 qq< /\\* .*? \\*/ >, # comment start
153 qq< /\\* >, # comment start
154 qq< $p_reserved >, # reserved chars
155 qq< "(?:\\\\.|.)*?" >, # "string"
156 qq< `(?:\\\\.|.)*?` >, # `string`
157 qq< '(?:\\\\.|.)*?' >, # 'string'
158 qq< $p_quotes >, # stringquote
159 qq< \\s+ > ); # whitespace
160  
161 95 my $p = join( "|", @p );
162  
163 95 @pretoks = split( m< ( $p ) >sox, $data );
164  
165 # Remove empty strings.
166 95 @pretoks = grep { length($_) } @pretoks;
167  
168 95 return;
169 11 }
170  
171 # Accessor for @pretoks.
172 0 ▶method pretoks() { \@pretoks }
Subroutine pretoks: not called CC=1 SCAR=4.1
Pod undocumented
173  
174 95 ▶method tokenize {
Subroutine tokenize: called CC=17 SCAR=28.5
Pod undocumented
175  
176 95 @tokens = ();
177 95 my $offset = 0; # token offset in input
178  
179 95 ▶ if ( $booleans ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($booleans) { } 95 0 95
180 95 ▶ if ( ref($booleans) ne 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $booleans ne "ARRAY") 13 82 95
181 13 $booleans = [ $JSON::Boolean::false, $JSON::Boolean::true ];
182 }
183 }
184 else {
185 0 $booleans = [ 0, 1 ];
186 }
187  
188 95 my $glue = 0; # can glue strings
189 95 my $uq_open = 0; # collecting pretokens for unquoted string
190  
191 # Loop through characters.
192 95 ▶ while ( @pretoks ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pretoks) 1337 95 1432
193 1337 my $pretok = shift(@pretoks);
194  
195 # White space: ignore.
196 1337 ▶ if ( $pretok !~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pretok =~ /\S/u) 474 863 1337
197 474 $offset += length($pretok);
198 474 $uq_open = 0;
199 474 next;
200 }
201  
202 863 ▶ if ( $pretok eq "\\\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretok eq "\\\n") 12 851 863
203 12 ▶ $glue++ if $glue;
Branch: 1 branch
BranchTrueFalseTotal
if $glue 11 1 12
204 12 $uq_open = 0;
205 12 $offset += length($pretok);
206 12 next;
207 }
208  
209 # Strings.
210 851 ▶ if ( $pretok =~ /^(["'`])(.*?)\1$/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretok =~ /^(["'`])(.*?)\1$/su) 201 650 851
211 201 my ( $quote, $content ) = ( $1, $2 );
212 201 ▶ if ( $glue > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($glue > 1) { } 11 190 201
213 11 $tokens[-1]->append($content);
214 }
215 else {
216 190 $self->addtok( $content, 'Q', $offset, $quote );
217 190 ▶ $glue = 1 unless $strict;
Branch: 1 branch
BranchTrueFalseTotal
unless $strict 185 5 190
218 }
219 201 $offset += length($pretok);
220 201 $uq_open = 0;
221 201 next;
222 }
223 650 $glue = 0;
224  
225 # // comment.
226 650 ▶ if ( $pretok =~ m<^//(.*)> ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($pretok =~ m[^//(.*)]u) { } 25 625 650
elsif ($pretok =~ m[^/\*.+]su) { } 4 621 625
elsif ($pretok eq '/*') { } 0 621 621
elsif ($self->is_reserved($pretok)) { } 421 200 621
elsif ($pretok =~ /^$p_number$/u) { } 22 178 200
elsif ($self->is_quote($pretok)) { } 0 178 178
227 # $self->addtok( $1, 'L', $offset );
228 25 $offset += length($pretok);
229 25 $uq_open = 0;
230 }
231  
232 # /* comment */
233 elsif ( $pretok =~ m<^/\*.+>s ) {
234 4 $offset += length($pretok);
235 4 $uq_open = 0;
236 }
237  
238 elsif ( $pretok eq '/*' ) {
239 0 return $self->error('unclosed-inline-comment');
240 }
241  
242 # Reserved characters.
243 elsif ( $self->is_reserved($pretok) ) {
244 421 $self->addtok( $pretok, 'C', $offset );
245 421 $offset += length($pretok);
246 421 $uq_open = 0;
247 }
248  
249  
250 # Numbers.
251 elsif ( $pretok =~ /^$p_number$/ ) {
252 22 $self->addtok( 0+$pretok, 'N', $offset );
253 22 $offset += length($pretok);
254 22 $uq_open = 0;
255 }
256  
257 # Quotes
258 # Can't happen -- should be an encosed string.
259 elsif ( $self->is_quote($pretok) ) {
260 0 $offset += length($pretok);
261 0 $self->addtok( $pretok, '?', $offset );
262 0 return $self->error('unclosed-quote', $tokens[-1] );
263 }
264  
265 # Else it's an unquoted string.
266 else {
267 178 ▶ if ( $uq_open ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uq_open) { } 14 164 178
268 14 $tokens[-1]->append($pretok);
269 }
270 else {
271 164 $self->addtok( $pretok, 'U', $offset );
272 164 $uq_open++;
273 }
274 178 $offset += length($pretok);
275 }
276 }
277 95 return;
278 11 }
279  
280 # Accessor for @tokens,
281 0 ▶method tokens() { \@tokens }
Subroutine tokens: not called CC=1 SCAR=4.1
Pod undocumented
282  
283 # Add a new token to @tokens.
284 807 ▶method addtok( $tok, $typ, $off, $quote=undef ) {
Subroutine addtok: called CC=5 SCAR=16.1
Pod undocumented
285  
286 807 ▶ push( @tokens,
Branch: 2 branches
BranchTrueFalseTotal
$typ eq 'U' || $typ eq 'N' ? : 186 621 807
$typ eq 'Q' ? : 190 431 621
Condition100%3/3
$typ eq "U" or $typ eq "N"
l!l&&r!l&&!r
16422621
MC/DC100%2/2
$typ eq "U" or $typ eq "N"
$typ eq "U" $typ eq "N"
Truth table100%3/3
A or B
A= $typ eq "U"B= $typ eq "N"
ABresult
1X1
011
000
287 $typ eq 'U' || $typ eq 'N'
288 ? JSON::Relaxed::String::Unquoted->new( token => $tok,
289 content => $tok,
290 type => $typ,
291 parent => $self,
292 offset => $off )
293 : $typ eq 'Q'
294 ? JSON::Relaxed::String::Quoted->new( token => $tok,
295 type => $typ,
296 content => $tok,
297 quote => $quote,
298 parent => $self,
299 offset => $off )
300 : JSON::Relaxed::Token->new( token => $tok,
301 parent => $self,
302 type => $typ,
303 offset => $off ) );
304 11 }
305  
306 # Build the result structure out of the tokens.
307 170 ▶method structure( %opts ) {
Subroutine structure: called CC=16 SCAR=28.1
Pod undocumented
308  
309 0 ▶ @tokens = @{$opts{tokens}} if $opts{tokens}; # for debugging
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"tokens"} 0 170 170
310  
311 170 ▶ if ( $implied_outer_hash && !$strict ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($implied_outer_hash and not $strict) 163 7 170
Condition100%3/3
$implied_outer_hash and not $strict
!ll&&!rl&&r
16163
MC/DC100%2/2
$implied_outer_hash and not $strict
$implied_outer_hash not $strict
Truth table100%3/3
A and not(B)
A= $implied_outer_hashB= not $strict
ABresult
0X0
100
111
312 # Note that = can only occur with $prp.
313 163 ▶ if ( @tokens > 2 && $tokens[0]->is_string
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens > 2 and $tokens[0]->is_string and $tokens[1]->token =~ /[:={]/u) 5 158 163
Condition83%5/6
@tokens > 2 and $tokens[0]->is_string and $tokens[1]->token =~ /[:={]/u
!ll&&!rl&&r
15805
@tokens > 2 and $tokens[0]->is_string
!ll&&!rl&&r
521065
MC/DC66%2/3
@tokens > 2 and $tokens[0]->is_string and $tokens[1]->token =~ /[:={]/u
@tokens > 2 $tokens[0]->is_string $tokens[1]->token =~ /[:={]/u
Truth table75%3/4
A and B and C
A= @tokens > 2B= $tokens[0]->is_stringC= $tokens[1]->token =~ /[:={]/u
ABCresult
0XX0
10X0
1100
1111
314 && $tokens[1]->token =~ /[:={]/ ) {
315 5 $self->addtok( '}', 'C', $tokens[-1]->offset );
316 5 $self->addtok( '{', 'C', $tokens[0]->offset );
317 5 unshift( @tokens, pop(@tokens ));
318 }
319 }
320  
321 170 ▶ my $this = shift(@tokens) // return;
Condition50%1/2
shift @tokens // (return)
l!l
1700
MC/DC0%0/1
shift @tokens // (return)
shift @tokens
Truth table50%1/2
A
A= shift @tokens
Aresult
11
00
322 170 my $rv;
323  
324 170 ▶ if ( $this->is_string ) { # (un)quoted string
Branch: 1 branch
BranchTrueFalseTotal
if ($this->is_string) { } 55 115 170
325 55 $rv = $this->as_perl;
326 }
327 else {
328 115 my $t = $this->token;
329 115 ▶ if ( $t eq '{' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t eq '{') { } 56 59 115
elsif ($t eq '[') { } 59 0 59
330 56 $rv = $self->build_hash;
331 }
332 elsif ( $t eq '[' ) {
333 59 $rv = $self->build_array;
334 }
335 else {
336 0 return $self->error( 'invalid-structure-opening-character',
337 $this );
338 }
339 }
340  
341 # If this is the outer structure, then no tokens should remain.
342 170 ▶ if ( $opts{top}
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"top"} and @tokens and $strict || !$extra_tokens_ok and not $self->is_error) 3 167 170
Condition83%10/12
$opts{"top"} and @tokens and $strict || !$extra_tokens_ok and not $self->is_error
!ll&&!rl&&r
16613
$opts{"top"} and @tokens and $strict || !$extra_tokens_ok
!ll&&!rl&&r
16604
$opts{"top"} and @tokens
!ll&&!rl&&r
75914
$strict or not $extra_tokens_ok
l!l&&r!l&&!r
310
MC/DC60%3/5
$opts{"top"} and @tokens and $strict || !$extra_tokens_ok and not $self->is_error
$opts{"top"} @tokens $strict not $extra_tokens_ok not $self->is_error
Truth table71%5/7
A and B and C or not(D) and not(E)
A= $opts{"top"}B= @tokensC= $strictD= not $extra_tokens_okE= not $self->is_error
ABCDEresult
0XXXX0
10XXX0
1100X0
111X00
110100
111X11
110111
343 && @tokens
344 && ( $strict || !$extra_tokens_ok )
345 && !$self->is_error
346 ) {
347 3 return $self->error( 'multiple-structures', $tokens[0] );
348 }
349  
350 167 return $rv;
351 11 }
352  
353  
354 4 ▶method error( $id, $aux = undef ) {
Subroutine error: called CC=4 SCAR=14.0
Pod undocumented
355 4 require JSON::Relaxed::ErrorCodes;
356 4 $err_id = $id;
357 4 ▶ $err_pos = $aux ? $aux->offset : -1;
Branch: 1 branch
BranchTrueFalseTotal
$aux ? : 4 0 4
358 4 $err_msg = JSON::Relaxed::ErrorCodes->message( $id, $aux );
359  
360 4 ▶ die( $err_msg, "\n" ) if $croak_on_error_internal;
Branch: 1 branch
BranchTrueFalseTotal
if $croak_on_error_internal 0 4 4
361 4 return; # undef
362 11 }
363  
364 198 ▶method is_error() {
Subroutine is_error: called CC=1 SCAR=0.0
Pod undocumented
365 198 $err_id;
366 11 }
367  
368 # For debugging.
369 0 ▶method dump_tokens() {
Subroutine dump_tokens: not called CC=3 SCAR=24.8
Pod undocumented
370 0 my $tokens = \@tokens;
371 0 ▶ return unless require DDP;
Branch: 1 branch
BranchTrueFalseTotal
unless require DDP 0 0 0
372 0 ▶ if ( -t STDERR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-t STDERR) { } 0 0 0
373 0 DDP::p($tokens);
374 }
375 else {
376 0 warn DDP::np($tokens), "\n";
377 }
378 11 }
379  
380 56 ▶method build_hash() {
Subroutine build_hash: called CC=20 SCAR=32.6
Pod undocumented
381  
382 56 my $rv = {};
383 56 my @ko; # order of keys
384  
385 56 ▶ while ( @tokens ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 147 0 147
386 147 my $this = shift(@tokens);
387 # What is allowed after opening brace:
388 # closing brace
389 # comma
390 # string
391  
392 # If closing brace, return.
393 147 my $t = $this->token;
394 147 ▶ if ( $t eq '}' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "}") 55 92 147
395 55 ▶ $rv->{" key order "} = \@ko
Branch: 1 branch
BranchTrueFalseTotal
if $key_order and not $strict and @ko > 1 2 53 55
Condition83%5/6
$key_order and not $strict and @ko > 1
!ll&&!rl&&r
5122
$key_order and not $strict
!ll&&!rl&&r
5104
MC/DC66%2/3
$key_order and not $strict and @ko > 1
$key_order not $strict @ko > 1
Truth table75%3/4
A and not(B) and C
A= $key_orderB= not $strictC= @ko > 1
ABCresult
0XX0
10X0
1100
1111
396 if $key_order && !$strict && @ko > 1;
397 55 return $rv;
398 }
399  
400 # If comma, do nothing.
401 92 ▶ next if $t eq ',';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "," 13 79 92
402  
403 # String
404 # If the token is a string then it is a key. The token after that
405 # should be a value.
406 79 ▶ if ( $this->is_string ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->is_string) { } 79 0 79
407 79 my ( $key, $value );
408  
409 # Set key using string.
410 79 $key = $this->as_perl( always_string => 1 );
411 79 $self->set_value( $rv, $key );
412 79 ▶ if ( $key_order ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_order) 6 73 79
413 6 ▶ if ( $combined_keys && !$strict ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($combined_keys and not $strict) { } 6 0 6
Condition33%1/3
$combined_keys and not $strict
!ll&&!rl&&r
006
MC/DC0%0/2
$combined_keys and not $strict
$combined_keys not $strict
Truth table33%1/3
A and not(B)
A= $combined_keysB= not $strict
ABresult
0X0
100
111
414 6 push( @ko, $key =~ s/\..*//r );
415 }
416 else {
417 0 push( @ko, $key );
418 }
419 }
420  
421 79 my $next = $tokens[0];
422 # If anything follows the string.
423 79 ▶ last unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 79 79
424  
425 # A comma or closing brace is acceptable after a string.
426 79 ▶ next if $next->token eq ',' || $next->token eq '}';
Branch: 1 branch
BranchTrueFalseTotal
if $next->token eq "," or $next->token eq "}" 0 79 79
Condition33%1/3
$next->token eq "," or $next->token eq "}"
l!l&&r!l&&!r
0079
MC/DC0%0/2
$next->token eq "," or $next->token eq "}"
$next->token eq "," $next->token eq "}"
Truth table33%1/3
A or B
A= $next->token eq ","B= $next->token eq "}"
ABresult
1X1
011
000
427  
428 # If next token is a colon or equals then it should be followed by a value.
429 # Note that = can only occur with $prp.
430 79 ▶ if ( $next->token =~ /^[:=]$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($next->token =~ /^[:=]$/u) { } 75 4 79
elsif ($prp and $next->token eq '{') { } 4 0 4
431 # Step past the colon.
432 75 shift(@tokens);
433  
434 # If at end of token array, exit loop.
435 75 ▶ last unless @tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 0 75 75
436  
437 # Get hash value.
438 75 $value = $self->get_value;
439  
440 # If there is a global error, return undef.
441 75 ▶ return undef if $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_error 1 74 75
442 }
443  
444 # Extension (prp): Implied colon.
445 ▶ elsif ( $prp && $next->token eq '{' ) {
Condition33%1/3
$prp and $next->token eq "{"
!ll&&!rl&&r
004
MC/DC0%0/2
$prp and $next->token eq "{"
$prp $next->token eq "{"
Truth table33%1/3
A and B
A= $prpB= $next->token eq "{"
ABresult
0X0
100
111
446 # Get hash value.
447 4 $value = $self->get_value;
448  
449 # If there is a global error, return undef.
450 4 ▶ return undef if $self->is_error;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_error 0 4 4
451 }
452  
453 # Anything else is an error.
454 else {
455 0 return $self->error('unknown-token-after-key', $next );
456 }
457  
458 # Set key and value in return hash.
459 78 $self->set_value( $rv, $key, $value );
460 }
461  
462 # Anything else is an error.
463 else {
464 0 return $self->error('unknown-token-for-hash-key', $this );
465 }
466 }
467  
468 # If we get this far then unclosed brace.
469 0 return $self->error('unclosed-hash-brace');
470  
471 11 }
472  
473 79 ▶method get_value() {
Subroutine get_value: called CC=3 SCAR=11.1
Pod undocumented
474  
475 # Get token.
476 79 my $this = shift(@tokens);
477  
478 # Token must be string, array, or hash.
479  
480 # String.
481 79 ▶ if ( $this->is_string ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($this->is_string) { } 56 23 79
elsif ($this->is_list_opener) { } 23 0 23
482 56 return $this->as_perl;
483 }
484  
485 # Token opens a hash or array.
486 elsif ( $this->is_list_opener ) {
487 23 unshift( @tokens, $this );
488 23 return $self->structure;
489 }
490  
491 # At this point it's an illegal token.
492 0 return $self->error('unexpected-token-after-colon', $this );
493 11 }
494  
495 157 ▶method set_value ( $rv, $key, $value = undef ) {
Subroutine set_value: called CC=7 SCAR=19.5
Pod undocumented
496 157 ▶ return $rv->{$key} = $value
Branch: 1 branch
BranchTrueFalseTotal
unless $combined_keys and not $strict and $key =~ /\./su 139 18 157
Condition100%6/6
$combined_keys and not $strict and $key =~ /\./su
!ll&&!rl&&r
513418
$combined_keys and not $strict
!ll&&!rl&&r
23152
MC/DC100%3/3
$combined_keys and not $strict and $key =~ /\./su
$combined_keys not $strict $key =~ /\./su
Truth table100%4/4
A and not(B) and C
A= $combined_keysB= not $strictC= $key =~ /\./su
ABCresult
0XX0
10X0
1100
1111
497 unless $combined_keys && !$strict && $key =~ /\./s;
498  
499 18 my @keys = split(/\./, $key, -1 );
500 18 my $c = \$rv;
501 18 for ( @keys ) {
502 36 ▶ if ( /^[+-]?\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^[+-]?\d+$/u) { } 0 36 36
503 0 $c = \( $$c->[$_] );
504 }
505 else {
506 36 $c = \( $$c->{$_} );
507 }
508 }
509 18 $$c = $value;
510 11 }
511  
512 59 ▶method build_array() {
Subroutine build_array: called CC=14 SCAR=27.5
Pod undocumented
513  
514 59 my $rv = [];
515  
516 # Build array. Work through tokens until closing brace.
517 59 ▶ while ( @tokens ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 357 0 357
518 357 my $this = shift(@tokens);
519  
520 357 my $t = $this->token;
521 # Closing brace: we're done building this array.
522 357 ▶ return $rv if $t eq ']';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "]" 58 299 357
523  
524 # Comma: if we get to a comma at this point, and we have
525 # content, do nothing with it in strict mode. Ignore otherwise.
526 299 ▶ if ( $t eq ',' && (!$strict || @$rv) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($t eq ',' and !$strict || @$rv) { } 88 211 299
elsif ($this->is_list_opener) { } 52 159 211
elsif ($this->is_string) { } 158 1 159
Condition100%6/6
$t eq "," and !$strict || @$rv
!ll&&!rl&&r
210188
not $strict or @$rv
l!l&&r!l&&!r
8531
MC/DC100%3/3
$t eq "," and !$strict || @$rv
$t eq "," not $strict @$rv
Truth table100%4/4
A and not(B) or C
A= $t eq ","B= not $strictC= @$rv
ABCresult
0XX0
1000
11X1
1011
527 }
528  
529 # Opening brace of hash or array.
530 elsif ( $this->is_list_opener ) {
531 52 unshift( @tokens, $this );
532 52 my $object = $self->structure;
533 52 ▶ defined($object) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $object or return undef 52 0 52
534 52 push( @$rv, $object );
535 }
536  
537 # if string, add it to the array
538 elsif ( $this->is_string ) {
539 # add the string to the array
540 158 push( @$rv, $this->as_perl );
541  
542 # Check following token.
543 158 ▶ if ( @tokens ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tokens) 158 0 158
544 158 ▶ my $next = $tokens[0] || '';
Condition50%1/2
$tokens[0] || ''
l!l
1580
MC/DC0%0/1
$tokens[0] || ''
$tokens[0]
Truth table50%1/2
A
A= $tokens[0]
Aresult
11
00
545 # Spec say: Commas are optional between objects pairs
546 # and array items.
547 # The next element must be a comma or the closing brace,
548 # or a string or list.
549 # Anything else is an error.
550 158 ▶ unless ( $next->token =~ /^[,\]]$/
Branch: 1 branch
BranchTrueFalseTotal
unless ($next->token =~ /^[,\]]$/u or $next->is_string or $next->is_list_opener) 0 158 158
Condition50%3/6
$next->token =~ /^[,\]]$/u or $next->is_string or $next->is_list_opener
l!l&&r!l&&!r
15800
$next->token =~ /^[,\]]$/u or $next->is_string
l!l&&r!l&&!r
112460
MC/DC0%0/3
$next->token =~ /^[,\]]$/u or $next->is_string or $next->is_list_opener
$next->token =~ /^[,\]]$/u $next->is_string $next->is_list_opener
Truth table50%2/4
A or B or C
A= $next->token =~ /^[,\]]$/uB= $next->is_stringC= $next->is_list_opener
ABCresult
1XX1
01X1
0011
0000
551 || $next->is_string
552 || $next->is_list_opener ) {
553 0 return $self->error( 'missing_comma-between-array-elements',
554 $next );
555 }
556 }
557 }
558  
559 # Else unkown object or character, so throw error.
560 else {
561 1 return $self->error( 'unknown-array-token', $this );
562 }
563 }
564  
565 # If we get this far then unclosed brace.
566 0 return $self->error('unclosed-array-brace');
567 11 }
568  
569 0 ▶method is_comment_opener( $pretok ) {
Subroutine is_comment_opener: not called CC=2 SCAR=17.9
Pod undocumented
570 0 ▶ $pretok eq '//' || $pretok eq '/*';
Branch: 1 branch
BranchTrueFalseTotal
$pretok eq "//" or $pretok eq "/*" 0 0 0
571 11 }
572  
573 11 ▶use List::Util qw( min max uniqstr );
Subroutine BEGIN: called CC=1 SCAR=0.0
574  
575 17 ▶method encode(%opts) {
Subroutine encode: called CC=19 SCAR=33.9
Pod undocumented
576 17 my $schema = $opts{schema};
577 17 ▶ my $level = $opts{level} // 0;
Condition100%2/2
$opts{"level"} // 0
l!l
125
MC/DC100%1/1
$opts{"level"} // 0
$opts{"level"}
Truth table100%2/2
A
A= $opts{"level"}
Aresult
11
00
578 17 my $rv = $opts{data}; # allow undef
579 17 ▶ my $indent = $opts{indent} // 2;
Condition50%1/2
$opts{"indent"} // 2
l!l
017
MC/DC0%0/1
$opts{"indent"} // 2
$opts{"indent"}
Truth table50%1/2
A
A= $opts{"indent"}
Aresult
11
00
580 17 ▶ my $impoh = $opts{implied_outer_hash} // $implied_outer_hash;
Condition33%1/3
$opts{"implied_outer_hash"} // $implied_outer_hash
l!l&&r!l&&!r
0170
MC/DC0%0/2
$opts{"implied_outer_hash"} // $implied_outer_hash
$opts{"implied_outer_hash"} $implied_outer_hash
Truth table33%1/3
A // B
A= $opts{"implied_outer_hash"}B= $implied_outer_hash
ABresult
1X1
011
000
581 17 ▶ my $ckeys = $opts{combined_keys} // $combined_keys;
Condition33%1/3
$opts{"combined_keys"} // $combined_keys
l!l&&r!l&&!r
0170
MC/DC0%0/2
$opts{"combined_keys"} // $combined_keys
$opts{"combined_keys"} $combined_keys
Truth table33%1/3
A // B
A= $opts{"combined_keys"}B= $combined_keys
ABresult
1X1
011
000
582 17 ▶ my $prpmode = $opts{prp} // $prp;
Condition33%1/3
$opts{"prp"} // $prp
l!l&&r!l&&!r
0170
MC/DC0%0/2
$opts{"prp"} // $prp
$opts{"prp"} $prp
Truth table33%1/3
A // B
A= $opts{"prp"}B= $prp
ABresult
1X1
011
000
583 17 ▶ my $pretty = $opts{pretty} // $pretty;
Condition66%2/3
$opts{"pretty"} // $pretty
l!l&&r!l&&!r
1430
MC/DC0%0/2
$opts{"pretty"} // $pretty
$opts{"pretty"} $pretty
Truth table66%2/3
A // B
A= $opts{"pretty"}B= $pretty
ABresult
1X1
011
000
584 17 ▶ my $strict = $opts{strict} // $strict;
Condition33%1/3
$opts{"strict"} // $strict
l!l&&r!l&&!r
0170
MC/DC0%0/2
$opts{"strict"} // $strict
$opts{"strict"} $strict
Truth table33%1/3
A // B
A= $opts{"strict"}B= $strict
ABresult
1X1
011
000
585 17 ▶ my $nouesc = $opts{nounicodeescapes} // 0;
Condition50%1/2
$opts{"nounicodeescapes"} // 0
l!l
017
MC/DC0%0/1
$opts{"nounicodeescapes"} // 0
$opts{"nounicodeescapes"}
Truth table50%1/2
A
A= $opts{"nounicodeescapes"}
Aresult
11
00
586  
587 17 ▶ if ( $strict ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($strict) 0 17 17
588 0 $ckeys = $prpmode = $impoh = 0;
589 }
590  
591 17 ▶ $schema = resolve( $schema, $schema ) if $schema;
Branch: 1 branch
BranchTrueFalseTotal
if $schema 0 17 17
592  
593 17 my $s = "";
594 17 my $i = 0;
595 17 my $props = $schema->{properties};
596 #warn("L$level - ", join(" ", sort keys(%$props)),"\n");
597  
598 # Add comments from schema, if any.
599 5 ▶ my $comments = sub( $p ) {
Subroutine __ANON__: called CC=5 SCAR=19.9
600 5 my $s = "";
601 5 my $did = 0;#$level;
602 5 for my $topic ( qw( title description ) ) {
603 10 ▶ next unless $p->{$topic};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{$topic} 10 0 10
604 0 ▶ $s .= "\n" unless $did++;
Branch: 1 branch
BranchTrueFalseTotal
unless $did++ 0 0 0
605 $s .= (" " x $i) . "// $_\n"
606 0 for split( /\s*<br\/?>|\\n|\n/, $p->{$topic} );
607 }
608 5 return $s;
609 17 };
610  
611 17 ▶ if ( !$level ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($level) 5 12 17
612 5 $s .= $comments->($schema);
613 }
614  
615 # Format a string value.
616 25 ▶ my $pr_string = sub ( $str, $force = 0 ) {
Subroutine __ANON__: called CC=18 SCAR=35.6
617  
618 # Reserved strings.
619 25 ▶ if ( !defined($str) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $str) 0 25 25
620 0 return "null";
621 }
622  
623 25 ▶ if ( UNIVERSAL::isa( $str, 'JSON::Boolean' )
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($str, "JSON::Boolean") or UNIVERSAL::isa($str, "JSON::PP::Boolean")) 1 24 25
Condition66%2/3
UNIVERSAL::isa($str, "JSON::Boolean") or UNIVERSAL::isa($str, "JSON::PP::Boolean")
l!l&&r!l&&!r
1024
MC/DC50%1/2
UNIVERSAL::isa($str, "JSON::Boolean") or UNIVERSAL::isa($str, "JSON::PP::Boolean")
UNIVERSAL::isa($str, "JSON::Boolean") UNIVERSAL::isa($str, "JSON::PP::Boolean")
Truth table66%2/3
A or B
A= UNIVERSAL::isa($str, "JSON::Boolean")B= UNIVERSAL::isa($str, "JSON::PP::Boolean")
ABresult
1X1
011
000
624 || UNIVERSAL::isa( $str, 'JSON::PP::Boolean' ) ) {
625 1 return (qw(false true))[$str]; # force string result
626 }
627  
628 24 my $v = $str;
629  
630 # Escapes.
631 24 $v =~ s/\\/\\\\/g;
632 24 $v =~ s/\n/\\n/g;
633 24 $v =~ s/\r/\\r/g;
634 24 $v =~ s/\f/\\f/g;
635 24 $v =~ s/\013/\\v/g;
636 24 $v =~ s/\010/\\b/g;
637 24 $v =~ s/\t/\\t/g;
638 0 ▶ $v =~ s/([^ -ÿ])/sprintf( ord($1) < 0xffff ? "\\u%04x" : "\\u{%x}", ord($1))/ge unless $nouesc;
Branch: 2 branches
BranchTrueFalseTotal
unless $nouesc 24 0 24
ord $1 < 65535 ? : 0 0 0
639  
640 # Force quotes unless the string can be represented as unquoted.
641 24 ▶ if ( # contains escapes
Branch: 1 branch
BranchTrueFalseTotal
if ($v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u or $v =~ /$p_quotes/u or $v =~ /\s/u or $v =~ /^(true|false|null)$/u or not length $v) 13 11 24
Condition66%14/21
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u or $v =~ /$p_quotes/u or $v =~ /\s/u or $v =~ /^(true|false|null)$/u or not length $v
l!l&&r!l&&!r
7611
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u or $v =~ /$p_quotes/u or $v =~ /\s/u or $v =~ /^(true|false|null)$/u
l!l&&r!l&&!r
6117
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u or $v =~ /$p_quotes/u or $v =~ /\s/u
l!l&&r!l&&!r
6018
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u or $v =~ /$p_quotes/u
l!l&&r!l&&!r
6018
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u
l!l&&r!l&&!r
0618
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v
l!l&&r!l&&!r
0024
$v =~ /^$p_number$/u and 0 + $v ne $v
!ll&&!rl&&r
2400
MC/DC37%3/8
$v ne $str or $v =~ /^$p_number$/u and 0 + $v ne $v or $v =~ /$p_reserved/u or $v =~ /$p_quotes/u or $v =~ /\s/u or $v =~ /^(true|false|null)$/u or not length $v
$v ne $str $v =~ /^$p_number$/u 0 + $v ne $v $v =~ /$p_reserved/u $v =~ /$p_quotes/u $v =~ /\s/u $v =~ /^(true|false|null)$/u not length $v
Truth table28%4/14
A or B and C or D or E or F or G or not(H)
A= $v ne $strB= $v =~ /^$p_number$/uC= 0 + $v ne $vD= $v =~ /$p_reserved/uE= $v =~ /$p_quotes/uF= $v =~ /\s/uG= $v =~ /^(true|false|null)$/uH= not length $v
ABCDEFGHresult
1XXXXXXX1
011XXXXX1
00X1XXXX1
0101XXXX1
00X01XXX1
01001XXX1
00X001XX1
010001XX1
00X0001X1
0100001X1
00X000011
010000011
00X000000
010000000
642 $v ne $str
643 # not value-formed numeric
644 || ( $v =~ /^$p_number$/ && 0+$v ne $v )
645 # contains reserved, quotes or spaces
646 || $v =~ $p_reserved
647 || $v =~ $p_quotes
648 || $v =~ /\s/
649 || $v =~ /^(true|false|null)$/
650 || !length($v)
651 ) {
652 13 ▶ if ( $v !~ /\"/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /\"/u) 13 0 13
653 13 return '"' . $v . '"';
654 }
655 0 ▶ if ( $v !~ /\'/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /\'/u) 0 0 0
656 0 return "'" . $v . "'";
657 }
658 0 ▶ if ( $v !~ /\`/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /\`/u) 0 0 0
659 0 return "`" . $v . "`";
660 }
661 0 return '"' . ($v =~ s/(["'`])/\\$1/rg) . '"';
662 }
663  
664 # Just a string.
665 11 return $v;
666 17 };
667  
668 # Format an array value.
669 4 ▶ my $pr_array = sub ( $rv, $level=0, $props = {} ) {
Subroutine __ANON__: called CC=8 SCAR=25.2
670 4 ▶ return "[]" unless @$rv;
Branch: 1 branch
BranchTrueFalseTotal
unless @$rv 0 4 4
671  
672 # Gather list of formatted values.
673 4 my @v = map { $self->encode( %opts,
674 data => $_,
675 level => $level+1,
676 schema => $props,
677 ) } @$rv;
678  
679 4 ▶ return "[".join(",",@v)."]" unless $pretty;
Branch: 1 branch
BranchTrueFalseTotal
unless $pretty 2 2 4
680  
681 # If sufficiently short, put it on one line.
682 2 ▶ if ( $i + length("@v") < 72
Branch: 1 branch
BranchTrueFalseTotal
if ($i + length(join $", @v) < 72 and not join("", @v) =~ /\s|$p_newlines/u) 2 0 2
Condition33%1/3
$i + length(join $", @v) < 72 and not join("", @v) =~ /\s|$p_newlines/u
!ll&&!rl&&r
002
MC/DC0%0/2
$i + length(join $", @v) < 72 and not join("", @v) =~ /\s|$p_newlines/u
$i + length(join $", @v) < 72 not join("", @v) =~ /\s|$p_newlines/u
Truth table33%1/3
A and not(B)
A= $i + length(join $", @v) < 72B= not join("", @v) =~ /\s|$p_newlines/u
ABresult
0X0
100
111
683 && join("",@v) !~ /\s|$p_newlines/ ) {
684 2 return "[ @v ]";
685 }
686  
687 # Put the values on separate lines.
688 0 my $s = "[\n";
689 0 $s .= s/^/(" " x ($i+$indent))/gemr . "\n" for @v;
690 0 $s .= (" " x $i) . "]";
691  
692 0 return $s;
693 17 };
694  
695 # Format a hash value.
696 17 ▶ my $pr_hash; $pr_hash = sub ( $rv, $level=0, $props = {} ) {
Subroutine __ANON__: called CC=36 SCAR=41.9
697 8 ▶ return "{}" unless keys(%$rv);
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$rv 0 8 8
698  
699 8 my $s = "";
700  
701 # Opening brace.
702 8 ▶ if ( $level || !$impoh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level or not $impoh) 3 5 8
Condition66%2/3
$level or not $impoh
l!l&&r!l&&!r
305
MC/DC50%1/2
$level or not $impoh
$level not $impoh
Truth table66%2/3
A or not(B)
A= $levelB= not $impoh
ABresult
1X1
011
000
703 3 ▶ $s .= $pretty ? "{\n" : "{";
Branch: 1 branch
BranchTrueFalseTotal
$pretty ? : 1 2 3
704 3 $i += $indent;
705 }
706  
707 # If we have a key order, use this and delete.
708 my @ko = $rv->{" key order "}
709 8 ▶ ? @{ delete($rv->{" key order "}) }
Branch: 1 branch
BranchTrueFalseTotal
$rv->{' key order '} ? : 2 6 8
710 : sort(keys(%$rv));
711  
712 # Dedup.
713 8 @ko = uniqstr(@ko);
714  
715 8 my $ll = 0;
716 8 for ( @ko ) {
717 # This may be wrong if \ escapes or combined keys are involved.
718 10 ▶ $ll = length($_) if length($_) > $ll;
Branch: 1 branch
BranchTrueFalseTotal
if length $_ > $ll 8 2 10
719 }
720  
721 8 for ( @ko ) {
722 10 my $k = $_;
723  
724 # Gather comments, if available.
725 10 my $comment;
726 10 ▶ if ( $props->{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($props->{$k}) 0 10 10
727 0 $comment = $comments->($props->{$k});
728 0 ▶ $s .= $comment if $comment;
Branch: 1 branch
BranchTrueFalseTotal
if $comment 0 0 0
729 }
730  
731 10 my $v = $rv->{$k};
732 10 my $key = $k; # final key
733 # Combine keys if allowed and possible.
734 10 ▶ while ( $ckeys && ref($v) eq 'HASH' && keys(%$v) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ckeys and ref $v eq "HASH" and keys %$v == 1) 6 10 16
Condition83%5/6
$ckeys and ref $v eq "HASH" and keys %$v == 1
!ll&&!rl&&r
826
$ckeys and ref $v eq "HASH"
!ll&&!rl&&r
088
MC/DC66%2/3
$ckeys and ref $v eq "HASH" and keys %$v == 1
$ckeys ref $v eq "HASH" keys %$v == 1
Truth table75%3/4
A and B and C
A= $ckeysB= ref $v eq "HASH"C= keys %$v == 1
ABCresult
0XX0
10X0
1100
1111
735 6 my $k = (keys(%$v))[0];
736 6 $key .= ".$k"; # append to final key
737 6 $v = $v->{$k}; # step to next
738 }
739  
740 10 ▶ $s .= (" " x $i) if $pretty;
Branch: 1 branch
BranchTrueFalseTotal
if $pretty 3 7 10
741  
742 # Format the key, try to align on length. NEEDS WORK
743 10 my $t = $pr_string->($key);
744 10 my $l = length($t);
745 10 $s .= $t;
746 10 ▶ my $in = $comment ? "" : " " x max( 0, $ll-length($t) );
Branch: 1 branch
BranchTrueFalseTotal
$comment ? : 0 10 10
747  
748 # Handle object serialisation.
749 10 ▶ my $r = UNIVERSAL::can( $v, "TO_JSON" ) // UNIVERSAL::can( $v, "FREEZE" );
Condition66%2/3
UNIVERSAL::can($v, "TO_JSON") // UNIVERSAL::can($v, "FREEZE")
l!l&&r!l&&!r
307
MC/DC50%1/2
UNIVERSAL::can($v, "TO_JSON") // UNIVERSAL::can($v, "FREEZE")
UNIVERSAL::can($v, "TO_JSON") UNIVERSAL::can($v, "FREEZE")
Truth table66%2/3
A // B
A= UNIVERSAL::can($v, "TO_JSON")B= UNIVERSAL::can($v, "FREEZE")
ABresult
1X1
011
000
750 10 ▶ $r = $r ? $v->$r : $v;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 3 7 10
751  
752 # Format the value.
753 10 ▶ if ( ref($r) eq 'HASH' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $r eq 'HASH') { } 3 7 10
elsif (ref $r eq 'ARRAY') { } 4 3 7
elsif ($pretty) { } 0 3 3
754 # Make up and recurse.
755 3 ▶ if ( $pretty ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pretty) { } 1 2 3
elsif (not $prpmode) { } 0 2 2
756 1 ▶ $s .= $prpmode ? " " : " : ";
Branch: 1 branch
BranchTrueFalseTotal
$prpmode ? : 1 0 1
757 }
758 elsif ( !$prpmode ) {
759 0 $s .= ":";
760 }
761  
762 3 $s .= $pr_hash->( $r, $level+1, $props->{$k}->{properties} );
763 }
764  
765 elsif ( ref($r) eq 'ARRAY' ) {
766 4 ▶ $s .= $pretty ? "$in : " : ":";
Branch: 1 branch
BranchTrueFalseTotal
$pretty ? : 2 2 4
767 4 $s .= $pr_array->( $r, $level+1, $props->{$k}->{items} );
768 }
769  
770 elsif ( $pretty ) {
771 0 my $t = $pr_string->($r);
772 0 $s .= "$in : ";
773  
774 # Break quoted strings that contain pseudo-newlines.
775 0 ▶ if ( $t =~ /^["'`].*\\n/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t =~ /^["'`].*\\n/u) { } 0 0 0
776 # Remove the quotes/
777 0 my $quote = substr( $t, 0, 1, '');
778 0 chop($t);
779  
780 # Determine current indent.
781 0 $s =~ /^(.*)\Z/m;
782 0 my $sep = " \\\n" . (" " x length($1));
783  
784 # Get string parts.
785 0 my @a = split( /\\n/, $t, -1 );
786 0 ▶ while ( @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 0 0 0
787 0 $s .= $quote.shift(@a);
788 0 ▶ $s .= "\\n" if @a;
Branch: 1 branch
BranchTrueFalseTotal
if @a 0 0 0
789 0 $s .= $quote;
790 0 ▶ $s .= $sep if @a;
Branch: 1 branch
BranchTrueFalseTotal
if @a 0 0 0
791 }
792 }
793  
794 # Just a string.
795 else {
796 0 $s .= $t;
797 }
798 }
799 else {
800 3 $s .= ":" . $pr_string->($r) . ",";
801 }
802 10 ▶ $s .= "\n" if $pretty;
Branch: 1 branch
BranchTrueFalseTotal
if $pretty 3 7 10
803 }
804  
805 # Strip final comma.
806 8 ▶ $s =~ s/,$// unless $pretty;
Branch: 1 branch
BranchTrueFalseTotal
unless $pretty 6 2 8
807  
808 # Closing brace,.
809 8 ▶ if ( $level || !$impoh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level or not $impoh) { } 3 5 8
Condition66%2/3
$level or not $impoh
l!l&&r!l&&!r
305
MC/DC50%1/2
$level or not $impoh
$level not $impoh
Truth table66%2/3
A or not(B)
A= $levelB= not $impoh
ABresult
1X1
011
000
810 3 $i -= $indent;
811 3 ▶ $s .= (" " x $i) if $pretty;
Branch: 1 branch
BranchTrueFalseTotal
if $pretty 1 2 3
812 3 $s .= "}";
813 }
814 else {
815 5 $s =~ s/\n+$//;
816 }
817  
818 8 return $s;
819 17 };
820  
821 # Handle object serialisation.
822 17 ▶ my $r = UNIVERSAL::can( $rv, "TO_JSON" ) // UNIVERSAL::can( $rv, "FREEZE" );
Condition33%1/3
UNIVERSAL::can($rv, "TO_JSON") // UNIVERSAL::can($rv, "FREEZE")
l!l&&r!l&&!r
0017
MC/DC0%0/2
UNIVERSAL::can($rv, "TO_JSON") // UNIVERSAL::can($rv, "FREEZE")
UNIVERSAL::can($rv, "TO_JSON") UNIVERSAL::can($rv, "FREEZE")
Truth table33%1/3
A // B
A= UNIVERSAL::can($rv, "TO_JSON")B= UNIVERSAL::can($rv, "FREEZE")
ABresult
1X1
011
000
823 17 ▶ $r = $r ? $rv->$r : $rv;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 17 17
824  
825 # From here it is straight forward.
826 17 ▶ if ( ref($r) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $r eq 'HASH') { } 5 12 17
elsif (ref $r eq 'ARRAY') { } 0 12 12
827 5 $s .= $pr_hash->( $r, $level, $props );
828 }
829 elsif ( ref($r) eq 'ARRAY' ) {
830 0 $s .= $pr_array->( $r, $level );
831 }
832 else {
833 12 $s .= $pr_string->($r);
834 }
835  
836 # Final make-up.
837 17 $s =~ s/^ +$//gm;
838 17 ▶ if ( $pretty && !$level ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pretty and not $level) 1 16 17
Condition100%3/3
$pretty and not $level
!ll&&!rl&&r
1061
MC/DC100%2/2
$pretty and not $level
$pretty not $level
Truth table100%3/3
A and not(B)
A= $prettyB= not $level
ABresult
0X0
100
111
839 1 $s =~ s/^\n*//s;
840 1 ▶ $s .= "\n" if $s !~ /\n$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\n$/u 1 0 1
841 }
842 17 return $s;
843 11 }
844  
845 ################ Subroutines ################
846  
847 # resolve processes $ref, allOf etc nodes.
848  
849 0 ▶sub resolve( $d, $schema ) {
Subroutine resolve: not called CC=10 SCAR=47.0
Pod undocumented
850  
851 0 ▶ if ( is_hash($d) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_hash($d)) { } 0 0 0
elsif (is_array($d)) { } 0 0 0
852 0 ▶ while ( my ($k,$v) = each %$d ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$d) 0 0 0
853 0 ▶ if ( $k eq 'allOf' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($k eq 'allOf') { } 0 0 0
elsif ($k eq 'oneOf' or $k eq 'anyOf') { } 0 0 0
elsif ($k eq '$ref') { } 0 0 0
854 0 delete $d->{$k}; # yes, safe to do
855 0 $d = merge( resolve( $_, $schema ), $d ) for @$v;
856 }
857 ▶ elsif ( $k eq 'oneOf' || $k eq 'anyOf' ) {
Condition0%0/3
$k eq "oneOf" or $k eq "anyOf"
l!l&&r!l&&!r
000
MC/DC0%0/2
$k eq "oneOf" or $k eq "anyOf"
$k eq "oneOf" $k eq "anyOf"
Truth table0%0/3
A or B
A= $k eq "oneOf"B= $k eq "anyOf"
ABresult
1X1
011
000
858 0 delete $d->{$k}; # yes, safe to do
859 0 $d = merge( resolve( $v->[0], $schema ), $d );
860 }
861 elsif ( $k eq '$ref' ) {
862 0 delete $d->{$k}; # yes, safe to do
863 0 ▶ if ( $v =~ m;^#/definitions/(.*); ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ m[^#/definitions/(.*)]u) { } 0 0 0
864 0 $d = merge( resolve( $schema->{definitions}->{$1}, $schema ), $d );
865 }
866 else {
867 0 die("Invalid \$ref: $v\n");
868 }
869 }
870 else {
871 0 $d->{$k} = resolve( $v, $schema );
872 }
873 }
874 }
875 elsif ( is_array($d) ) {
876 0 $d = [ map { resolve( $_, $schema ) } @$d ];
877 }
878 else {
879 }
880  
881 0 return $d;
882 }
883  
884 0 ▶sub is_hash($o) { UNIVERSAL::isa( $o, 'HASH' ) }
Subroutine is_hash: not called CC=1 SCAR=6.9
Pod undocumented
885 0 ▶sub is_array($o) { UNIVERSAL::isa( $o, 'ARRAY' ) }
Subroutine is_array: not called CC=1 SCAR=6.9
Pod undocumented
886  
887 0 ▶sub merge ( $left, $right ) {
Subroutine merge: not called CC=5 SCAR=34.0
Pod undocumented
888  
889 0 ▶ return $left unless $right;
Branch: 1 branch
BranchTrueFalseTotal
unless $right 0 0 0
890  
891 0 my %merged = %$left;
892  
893 0 for my $key ( keys %$right ) {
894  
895 0 my ($hr, $hl) = map { is_hash($_->{$key}) } $right, $left;
896  
897 0 ▶ if ( $hr and $hl ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hr and $hl) { } 0 0 0
Condition0%0/3
$hr and $hl
!ll&&!rl&&r
000
MC/DC0%0/2
$hr and $hl
$hr $hl
Truth table0%0/3
A and B
A= $hrB= $hl
ABresult
0X0
100
111
898 0 $merged{$key} = merge( $left->{$key}, $right->{$key} );
899 }
900 else {
901 0 $merged{$key} = $right->{$key};
902 }
903 }
904  
905 0 return \%merged;
906 }
907  
908 ################ Tokens ################
909  
910 class JSON::Relaxed::Token;
911  
912 123 ▶field $parent :accessor :param;
Subroutine parent: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
@_ and $parent = shift() 0 123 123
913 1023 ▶field $token :accessor :param;
Subroutine token: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
@_ and $token = shift() 0 1023 1023
914 0 ▶field $type :accessor :param;
Subroutine type: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
@_ and $type = shift() 0 0 0
915 18 ▶field $offset :accessor :param;
Subroutine offset: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
@_ and $offset = shift() 0 18 18
916  
917 648 ▶method is_string() {
Subroutine is_string: called CC=1 SCAR=0.0
918 648 $type =~ /[QUN]/
919 11 }
920  
921 234 ▶method is_list_opener() {
Subroutine is_list_opener: called CC=2 SCAR=6.9
922 234 ▶ $type eq 'C' && $token =~ /[{\[]/;
Branch: 1 branch
BranchTrueFalseTotal
$type eq "C" and $token =~ /[{\[]/u 76 158 234
923 11 }
924  
925 0 ▶method as_perl( %options ) { # for values
Subroutine as_perl: not called CC=1 SCAR=6.9
926 0 $token->as_perl(%options);
927 11 }
928  
929 0 ▶method _data_printer( $ddp ) { # for DDP
Subroutine _data_printer: not called CC=3 SCAR=24.8
930 0 my $res = "Token(";
931 0 ▶ if ( !defined $token ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $token) { } 0 0 0
elsif ($self->is_string) { } 0 0 0
932 0 $res .= "null";
933 }
934 elsif ( $self->is_string ) {
935 0 $res .= $token->_data_printer($ddp);
936 }
937 else {
938 0 $res .= "\"$token\"";
939 }
940 0 $res .= ", $type";
941 0 $res . ", $offset)";
942 11 }
943  
944 4 ▶method as_string { # for messages
Subroutine as_string: called CC=2 SCAR=6.9
945 4 my $res = "";
946 4 ▶ if ( $self->is_string ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_string) { } 1 3 4
947 1 $res = '"' . ($self->content =~ s/"/\\"/gr) . '"';
948 }
949 else {
950 3 $res .= "\"$token\"";
951 }
952 4 $res;
953 11 }
954  
955 =begin heavily_optimized_alternative
956  
957 package JSON::Relaxed::XXToken;
958 our @ISA = qw(JSON::Relaxed::Parser);
959  
960 sub new {
961 my ( $pkg, %opts ) = @_;
962 my $self = bless [] => $pkg;
963 push( @$self,
964 delete(%opts{parent}),
965 delete(%opts{token}),
966 delete(%opts{type}),
967 delete(%opts{offset}),
968 );
969 $self;
970 }
971  
972 sub parent { $_[0]->[0] }
973 sub token { $_[0]->[1] }
974 sub type { $_[0]->[2] }
975 sub offset { $_[0]->[3] }
976  
977 sub is_string { $_[0]->[2] =~ /[QUN]/ }
978 sub is_list_opener { $_[0]->[2] eq 'C' && $_[0]->[1] =~ /[{\[]/ }
979 sub as_perl { # for values
980 return shift->[1]->as_perl(@_);
981 }
982  
983 sub _data_printer { # for DDP
984 my ( $self, $ddp ) = @_;
985 my $res = "Token(";
986 if ( $self->is_string ) {
987 $res .= $self->[1]->_data_printer($ddp);
988 }
989 else {
990 $res .= "\"".$self->[1]."\"";
991 }
992 $res .= ", " . $self->[2];
993 $res . ", " . $self->[3] . ")";
994 }
995  
996 sub as_string { # for messages
997 if ( $_[0]->is_string ) {
998 return '"' . ($_[0]->[1]->content =~ s/"/\\"/gr) . '"';
999 }
1000 "\"" . $_[0]->[1] . "\"";
1001 }
1002  
1003 =cut
1004  
1005 ################ Strings ################
1006  
1007 class JSON::Relaxed::String :isa(JSON::Relaxed::Token);
1008  
1009 11 field $content :param = undef;
1010 11 field $quote :accessor :param = undef;
1011  
1012 # Quoted strings are assembled from complete substrings, so escape
1013 # processing is done on the substrings. This prevents ugly things
1014 # when unicode escapes are split across substrings.
1015 # Unquotes strings are collected token by token, so escape processing
1016 # can only be done on the complete string (on output).
1017  
1018 0 ▶ADJUST {
Subroutine quote: not called CC=2 SCAR=14.0
Branch: 1 branch
BranchTrueFalseTotal
@_ and $quote = shift() 0 0 0
1019 $content = $self->unescape($content) if defined($quote);
1020 11 };
1021  
1022 25 ▶method append ($str) {
Subroutine append: called CC=2 SCAR=6.9
1023 25 ▶ $str = $self->unescape($str) if defined $quote;
Branch: 1 branch
BranchTrueFalseTotal
if defined $quote 11 14 25
1024 25 $content .= $str;
1025 11 }
1026  
1027 349 ▶method content {
Subroutine content: called CC=2 SCAR=6.9
1028 349 ▶ defined($quote) ? $content : $self->unescape($content);
Branch: 1 branch
BranchTrueFalseTotal
defined $quote ? : 185 164 349
1029 11 }
1030  
1031 # One regexp to match them all...
1032 11 my $esc_quoted = qr/
1033 \\([tnrfb]) # $1 : one char
1034 | \\u\{([[:xdigit:]]+)\} # $2 : \u{XX...}
1035 | \\u([Dd][89abAB][[:xdigit:]]{2}) # $3 : \uDXXX hi
1036 \\u([Dd][c-fC-F][[:xdigit:]]{2}) # $4 : \uDXXX lo
1037 | \\u([[:xdigit:]]{4}) # $5 : \uXXXX
1038 | \\?(.) # $6
1039 /xs;
1040  
1041 # Special escapes (quoted strings only).
1042 11 my %esc = (
1043 'b' => "\b", # Backspace
1044 'f' => "\f", # Form feed
1045 'n' => "\n", # New line
1046 'r' => "\r", # Carriage return
1047 't' => "\t", # Tab
1048 'v' => chr(11), # Vertical tab
1049 );
1050  
1051 365 ▶method unescape ($str) {
Subroutine unescape: called CC=4 SCAR=14.0
1052 365 ▶ return $str unless $str =~ /\\/;
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ /\\/u 307 58 365
1053  
1054 560 ▶ my $convert = sub {
Subroutine __ANON__: called CC=7 SCAR=19.7
1055 # Specials. Only for quoted strings.
1056 560 ▶ if ( defined($1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $1) 3 557 560
1057 3 ▶ return defined($quote) ? $esc{$1} : $1;
Branch: 1 branch
BranchTrueFalseTotal
defined $quote ? : 3 0 3
1058 }
1059  
1060 # Extended \u{XXX} character.
1061 557 ▶ defined($2) and return chr(hex($2));
Branch: 1 branch
BranchTrueFalseTotal
defined $2 and return chr hex $2 7 550 557
1062  
1063 # Pair of surrogates.
1064 550 ▶ defined($3) and return pack( 'U*',
Branch: 1 branch
BranchTrueFalseTotal
defined $3 and return pack("U*", 65536 + (hex($3) - 55296) * 1024 + (hex($4) - 56320)) 8 542 550
1065 0x10000 + (hex($3) - 0xD800) * 0x400
1066 + (hex($4) - 0xDC00) );
1067  
1068 # Standard \uXXXX character.
1069 542 ▶ defined($5) and return chr(hex($5));
Branch: 1 branch
BranchTrueFalseTotal
defined $5 and return chr hex $5 14 528 542
1070  
1071 # Anything else.
1072 528 ▶ defined($6) and return $6;
Branch: 1 branch
BranchTrueFalseTotal
defined $6 and return $6 528 0 528
1073  
1074 0 return '';
1075 58 };
1076  
1077 58 ▶ while( $str =~ s/\G$esc_quoted/$convert->()/gxse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/\G$esc_quoted/&$convert();/egsux) 58 0 58
1078 58 ▶ last unless defined pos($str);
Branch: 1 branch
BranchTrueFalseTotal
unless defined pos $str 58 0 58
1079 }
1080  
1081 58 return $str;
1082 11 }
1083  
1084 ################ Quoted Strings ################
1085  
1086 class JSON::Relaxed::String::Quoted :isa(JSON::Relaxed::String);
1087  
1088 185 ▶method as_perl( %options ) {
Subroutine as_perl: called CC=1 SCAR=0.0
1089 185 $self->content;
1090 11 }
1091  
1092 0 ▶method _data_printer( $ddp ) {
Subroutine _data_printer: not called CC=1 SCAR=6.9
1093 0 "Token(" . $self->quote . $self->content . $self->quote . ", " .
1094 $self->type . ", " . $self->offset . ")";
1095 11 }
1096  
1097 ################ Unquoted Strings ################
1098  
1099 class JSON::Relaxed::String::Unquoted :isa(JSON::Relaxed::String);
1100  
1101 # If the option always_string is set, bypass the reserved strings.
1102 # This is used for hash keys.
1103 163 ▶method as_perl( %options ) {
Subroutine as_perl: called CC=8 SCAR=20.8
1104 163 my $content = $self->content;
1105  
1106 # If used as a key, always return a string.
1107 163 ▶ return $content if $options{always_string};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"always_string"} 50 113 163
1108  
1109 # Return boolean specials if appropriate.
1110 113 ▶ if ( $content =~ /^(?:true|false)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content =~ /^(?:true|false)$/u) 14 99 113
1111 14 ▶ return $self->parent->booleans->[ $content eq 'true' ? 1 : 0 ];
Branch: 1 branch
BranchTrueFalseTotal
$content eq 'true' ? : 9 5 14
1112 }
1113 99 ▶ if ( $self->parent->prp && $content =~ /^(?:on|off)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->parent->prp and $content =~ /^(?:on|off)$/u) { } 4 95 99
elsif ($content eq 'null') { } 4 91 95
Condition66%2/3
$self->parent->prp and $content =~ /^(?:on|off)$/u
!ll&&!rl&&r
0954
MC/DC50%1/2
$self->parent->prp and $content =~ /^(?:on|off)$/u
$self->parent->prp $content =~ /^(?:on|off)$/u
Truth table66%2/3
A and B
A= $self->parent->prpB= $content =~ /^(?:on|off)$/u
ABresult
0X0
100
111
1114 4 ▶ return $self->parent->booleans->[ $content eq 'on' ? 1 : 0 ];
Branch: 1 branch
BranchTrueFalseTotal
$content eq 'on' ? : 2 2 4
1115 }
1116  
1117 # null -> undef
1118 elsif ( $content eq "null" ) {
1119 4 return undef;
1120 }
1121  
1122 # Return as string.
1123 91 $content;
1124 11 }
1125  
1126 0 ▶method _data_printer( $ddp ) {
Subroutine _data_printer: not called CC=1 SCAR=6.9
1127 0 "Token(«" . $self->content . "», " .
1128 $self->type . ", " . $self->offset . ")";
1129 11 }
1130  
1131 ################ Booleans ################
1132  
1133 # This class distinguises booleans true and false from numeric 1 and 0.
1134  
1135 11 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
1136  
1137 11 package JSON::Boolean {
1138  
1139 0 ▶ sub as_perl( $self, %options ) { $self }
Subroutine as_perl: not called CC=1 SCAR=6.9
1140  
1141 0 ▶ sub _data_printer( $self, $ddp ) { "Bool($self)" }
Subroutine _data_printer: not called CC=1 SCAR=6.9
1142  
1143 8 ▶ use overload '""' => sub { ${$_[0]} ? "true" : "false" },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
${$_[0];} ? : 4 4 8
1144 1 ▶ "0+" => sub { ${$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
1145 4 ▶ "bool" => sub { !!${$_[0]} },
Subroutine __ANON__: called CC=1 SCAR=0.0
1146 11 fallback => 1;
1147  
1148 # For JSON::PP export.
1149 0 ▶ sub TO_JSON { ${$_[0]} ? $JSON::PP::true : $JSON::PP::false }
Subroutine TO_JSON: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
${$_[0];} ? : 0 0 0
1150  
1151 # Boolean values.
1152 11 our $true = do { bless \(my $dummy = 1) => __PACKAGE__ };
1153 11 our $false = do { bless \(my $dummy = 0) => __PACKAGE__ };
1154  
1155 }
1156  
1157 ################
1158  
1159 11 1;
↑ Summary Relaxed/ErrorCodes.pm »