blib/lib/JQ/Lite/Util/Parsing.pm

filter: Statementstmt 88.2% 623 / 706 Branchbran 72.6% 369 / 508 Conditioncond 58.0% 112 / 193 MC/DCmcdc 32.1% 37 / 115 Subroutinesub 89.7% 35 / 39 Podpod n/a totaltotal 75.3% 1176 / 1561 CC 324 SCAR 35.3
CC
324
Cov
78%
_apply_addition
88.3
_parse_if_expression
86.3
_evaluate_value_expression
48.2
CRAP 34.1
« blib/lib/JQ/Lite/Filters.pm ↑ Summary blib/lib/JQ/Lite/Util/Transform.pm »
1 package JQ::Lite::Util;
2  
3 182 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 182 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 182 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 182 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 182 ▶use Encode qw(encode is_utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 182 ▶use JQ::Lite::Expression ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 182 our $JSON_DECODER = _build_json_decoder();
12 182 our $FROMJSON_DECODER = _build_json_decoder();
13 182 our $TOJSON_ENCODER = JSON::PP->new->utf8->allow_nonref;
14  
15 364 ▶sub _build_json_decoder {
Subroutine _build_json_decoder: called CC=2 SCAR=7.0
16 364 my $decoder = JSON::PP->new->utf8->allow_nonref;
17  
18 364 ▶ if ($decoder->can('boolean_values')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoder->can("boolean_values")) 364 0 364
19 364 $decoder->boolean_values(JSON::PP::false, JSON::PP::true);
20 }
21  
22 364 return $decoder;
23 }
24  
25 245 ▶sub _encode_json {
Subroutine _encode_json: called CC=1 SCAR=0.0
26 245 my ($value) = @_;
27 245 return $TOJSON_ENCODER->encode($value);
28 }
29  
30 7113 ▶sub _decode_json {
Subroutine _decode_json: called CC=3 SCAR=11.0
31 7113 my ($text) = @_;
32  
33 7113 ▶ if (defined $text && is_utf8($text, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $text and &is_utf8($text, 1)) 2 7111 7113
Condition66%2/3
defined $text and &is_utf8($text, 1)
!ll&&!rl&&r
071112
MC/DC50%1/2
defined $text and &is_utf8($text, 1)
defined $text &is_utf8($text, 1)
Truth table66%2/3
A and B
A= defined $textB= &is_utf8($text, 1)
ABresult
0X0
100
111
34 2 $text = encode('UTF-8', $text);
35 }
36  
37 7113 return $JSON_DECODER->decode($text);
38 }
39  
40 45 ▶sub _are_brackets_balanced {
Subroutine _are_brackets_balanced: called CC=15 SCAR=28.6
41 45 my ($text) = @_;
42  
43 45 ▶ return 1 unless defined $text && length $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and length $text 0 45 45
Condition33%1/3
defined $text and length $text
!ll&&!rl&&r
0045
MC/DC0%0/2
defined $text and length $text
defined $text length $text
Truth table33%1/3
A and B
A= defined $textB= length $text
ABresult
0X0
100
111
44  
45 45 my %pairs = (
46 '(' => ')',
47 '[' => ']',
48 '{' => '}',
49 );
50 45 my %closing = reverse %pairs;
51  
52 45 my @stack;
53 my $string;
54 45 my $escape = 0;
55  
56 45 for my $char (split //, $text) {
57 460 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 27 433 460
58 27 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 0 27 27
59 0 $escape = 0;
60 0 next;
61 }
62  
63 27 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 0 27 27
64 0 $escape = 1;
65 0 next;
66 }
67  
68 27 ▶ if ($char eq $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $string) 6 21 27
69 6 undef $string;
70 }
71  
72 27 next;
73 }
74  
75 433 ▶ if ($char eq "'" || $char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"") 6 427 433
Condition66%2/3
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
06427
MC/DC50%1/2
$char eq "'" or $char eq "\""
$char eq "'" $char eq "\""
Truth table66%2/3
A or B
A= $char eq "'"B= $char eq "\""
ABresult
1X1
011
000
76 6 $string = $char;
77 6 next;
78 }
79  
80 427 ▶ if (exists $pairs{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pairs{$char}) 10 417 427
81 10 push @stack, $char;
82 10 next;
83 }
84  
85 417 ▶ if (exists $closing{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $closing{$char}) 24 393 417
86 24 ▶ return 0 unless @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 14 10 24
87 10 my $open = pop @stack;
88 10 ▶ return 0 unless $pairs{$open} eq $char;
Branch: 1 branch
BranchTrueFalseTotal
unless $pairs{$open} eq $char 0 10 10
89 10 next;
90 }
91 }
92  
93 31 ▶ return !@stack && !defined $string;
Condition33%1/3
@stack || defined $string
l!l&&r!l&&!r
0031
MC/DC0%0/2
@stack || defined $string
@stack defined $string
Truth table33%1/3
A || B
A= @stackB= defined $string
ABresult
1X1
011
000
94 }
95  
96 6667 ▶sub _strip_wrapping_parens {
Subroutine _strip_wrapping_parens: called CC=4 SCAR=13.9
97 6667 my ($text) = @_;
98  
99 6667 ▶ return '' unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 6667 6667
100  
101 6667 my $copy = $text;
102 6667 $copy =~ s/^\s+|\s+$//g;
103  
104 6667 ▶ while ($copy =~ /^\((.*)\)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copy =~ /^\((.*)\)$/s) 45 6653 6698
105 45 my $inner = $1;
106 45 ▶ last unless _are_brackets_balanced($inner);
Branch: 1 branch
BranchTrueFalseTotal
unless _are_brackets_balanced($inner) 14 31 45
107 31 $inner =~ s/^\s+|\s+$//g;
108 31 $copy = $inner;
109 }
110  
111 6667 return $copy;
112 }
113  
114 8 ▶sub _split_top_level_semicolons {
Subroutine _split_top_level_semicolons: called CC=16 SCAR=32.4
115 8 my ($text) = @_;
116  
117 8 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 8 8
118  
119 8 my %pairs = (
120 '(' => ')',
121 '[' => ']',
122 '{' => '}',
123 );
124 8 my %closing = reverse %pairs;
125  
126 8 my @stack;
127 my $string;
128 8 my $escape = 0;
129 8 my @parts;
130 8 my $start = 0;
131  
132 8 ▶ for (my $i = 0; $i < length $text; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 103 8 111
133 103 my $char = substr($text, $i, 1);
134  
135 103 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 1 102 103
136 1 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 0 1 1
137 0 $escape = 0;
138 0 next;
139 }
140  
141 1 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 0 1 1
142 0 $escape = 1;
143 0 next;
144 }
145  
146 1 ▶ if ($char eq $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $string) 1 0 1
147 1 undef $string;
148 }
149  
150 1 next;
151 }
152  
153 102 ▶ if ($char eq "'" || $char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"") 1 101 102
Condition66%2/3
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
01101
MC/DC50%1/2
$char eq "'" or $char eq "\""
$char eq "'" $char eq "\""
Truth table66%2/3
A or B
A= $char eq "'"B= $char eq "\""
ABresult
1X1
011
000
154 1 $string = $char;
155 1 next;
156 }
157  
158 101 ▶ if (exists $pairs{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pairs{$char}) 0 101 101
159 0 push @stack, $char;
160 0 next;
161 }
162  
163 101 ▶ if (exists $closing{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $closing{$char}) 0 101 101
164 0 ▶ return unless @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 0 0
165 0 my $open = pop @stack;
166 0 ▶ return unless $pairs{$open} eq $char;
Branch: 1 branch
BranchTrueFalseTotal
unless $pairs{$open} eq $char 0 0 0
167 0 next;
168 }
169  
170 101 ▶ next unless $char eq ';';
Branch: 1 branch
BranchTrueFalseTotal
unless $char eq ";" 92 9 101
171  
172 9 ▶ if (!@stack) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stack) 9 0 9
173 9 my $chunk = substr($text, $start, $i - $start);
174 9 push @parts, $chunk;
175 9 $start = $i + 1;
176 }
177 }
178  
179 8 ▶ push @parts, substr($text, $start) if $start <= length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $start <= length $text 8 0 8
180  
181 8 return @parts;
182 }
183  
184 3015 ▶sub _split_top_level_pipes {
Subroutine _split_top_level_pipes: called CC=26 SCAR=32.7
185 3015 my ($text) = @_;
186  
187 3015 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 3015 3015
188  
189 3015 my %pairs = (
190 '(' => ')',
191 '[' => ']',
192 '{' => '}',
193 );
194 3015 my %closing = reverse %pairs;
195  
196 3015 my @stack;
197 my $string;
198 3015 my $escape = 0;
199 3015 my @parts;
200 3015 my $start = 0;
201  
202 3015 my $length = length $text;
203 3015 my $in_try = 0;
204 3015 ▶ for (my $i = 0; $i < $length; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $length) 40546 3015 43561
205 40546 my $char = substr($text, $i, 1);
206  
207 40546 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 3163 37383 40546
208 3163 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 14 3149 3163
209 14 $escape = 0;
210 14 next;
211 }
212  
213 3149 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 14 3135 3149
214 14 $escape = 1;
215 14 next;
216 }
217  
218 3135 ▶ if ($char eq $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $string) 670 2465 3135
219 670 undef $string;
220 }
221  
222 3135 next;
223 }
224  
225 37383 ▶ if ($char eq "'" || $char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"") 670 36713 37383
Condition100%3/3
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
666436713
MC/DC100%2/2
$char eq "'" or $char eq "\""
$char eq "'" $char eq "\""
Truth table100%3/3
A or B
A= $char eq "'"B= $char eq "\""
ABresult
1X1
011
000
226 670 $string = $char;
227 670 next;
228 }
229  
230 36713 ▶ if (exists $pairs{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pairs{$char}) 1610 35103 36713
231 1610 push @stack, $char;
232 1610 next;
233 }
234  
235 35103 ▶ if (!$in_try && !@stack && !defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($in_try or @stack or defined $string) 28567 6536 35103
Condition83%5/6
$in_try or @stack or defined $string
l!l&&r!l&&!r
6536028567
$in_try or @stack
l!l&&r!l&&!r
372616428567
MC/DC66%2/3
$in_try or @stack or defined $string
$in_try @stack defined $string
Truth table75%3/4
A or B or C
A= $in_tryB= @stackC= defined $string
ABCresult
1XX1
01X1
0011
0000
236 28567 ▶ if (substr($text, $i) =~ /^try\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($text, $i) =~ /^try\b/) 28 28539 28567
237 28 $in_try = 1;
238 28 next;
239 }
240 }
241  
242 35075 ▶ if ($in_try && !@stack && !defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_try and not @stack and not defined $string) 202 34873 35075
Condition83%5/6
$in_try and not @stack and not defined $string
!ll&&!rl&&r
348730202
$in_try and not @stack
!ll&&!rl&&r
34703170202
MC/DC66%2/3
$in_try and not @stack and not defined $string
$in_try not @stack not defined $string
Truth table75%3/4
A and not(B) and not(C)
A= $in_tryB= not @stackC= not defined $string
ABCresult
0XX0
10X0
1100
1111
243 202 ▶ if (substr($text, $i) =~ /^catch\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($text, $i) =~ /^catch\b/) 20 182 202
244 20 $in_try = 0;
245 20 next;
246 }
247 }
248  
249 35055 ▶ if (exists $closing{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $closing{$char}) 1610 33445 35055
250 1610 ▶ return unless @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 1610 1610
251 1610 my $open = pop @stack;
252 1610 ▶ return unless $pairs{$open} eq $char;
Branch: 1 branch
BranchTrueFalseTotal
unless $pairs{$open} eq $char 0 1610 1610
253 1610 next;
254 }
255  
256 33445 ▶ next unless $char eq '|';
Branch: 1 branch
BranchTrueFalseTotal
unless $char eq "|" 32441 1004 33445
257 1004 ▶ next if $in_try;
Branch: 1 branch
BranchTrueFalseTotal
if $in_try 4 1000 1004
258 1000 ▶ if (substr($text, $i, 2) eq '||') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($text, $i, 2) eq "||") 0 1000 1000
259 0 $i++;
260 0 next;
261 }
262  
263 1000 ▶ if (!@stack) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stack) 984 16 1000
264 984 my $chunk = substr($text, $start, $i - $start);
265 984 push @parts, $chunk;
266 984 $start = $i + 1;
267 }
268 }
269  
270 3015 ▶ push @parts, substr($text, $start) if $start <= $length;
Branch: 1 branch
BranchTrueFalseTotal
if $start <= $length 3015 0 3015
271  
272 3015 return @parts;
273 }
274  
275 4688 ▶sub _split_top_level_commas {
Subroutine _split_top_level_commas: called CC=16 SCAR=27.8
276 4688 my ($text) = @_;
277  
278 4688 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 4688 4688
279  
280 4688 my %pairs = (
281 '(' => ')',
282 '[' => ']',
283 '{' => '}',
284 );
285 4688 my %closing = reverse %pairs;
286  
287 4688 my @stack;
288 my $string;
289 4688 my $escape = 0;
290 4688 my @parts;
291 4688 my $start = 0;
292  
293 4688 ▶ for (my $i = 0; $i < length $text; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 49708 4688 54396
294 49708 my $char = substr($text, $i, 1);
295  
296 49708 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 4788 44920 49708
297 4788 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 20 4768 4788
298 20 $escape = 0;
299 20 next;
300 }
301  
302 4768 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 20 4748 4768
303 20 $escape = 1;
304 20 next;
305 }
306  
307 4748 ▶ if ($char eq $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $string) 986 3762 4748
308 986 undef $string;
309 }
310  
311 4748 next;
312 }
313  
314 44920 ▶ if ($char eq "'" || $char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"") 986 43934 44920
Condition100%3/3
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
997743934
MC/DC100%2/2
$char eq "'" or $char eq "\""
$char eq "'" $char eq "\""
Truth table100%3/3
A or B
A= $char eq "'"B= $char eq "\""
ABresult
1X1
011
000
315 986 $string = $char;
316 986 next;
317 }
318  
319 43934 ▶ if (exists $pairs{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pairs{$char}) 2267 41667 43934
320 2267 push @stack, $char;
321 2267 next;
322 }
323  
324 41667 ▶ if (exists $closing{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $closing{$char}) 2267 39400 41667
325 2267 ▶ return unless @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 2267 2267
326 2267 my $open = pop @stack;
327 2267 ▶ return unless $pairs{$open} eq $char;
Branch: 1 branch
BranchTrueFalseTotal
unless $pairs{$open} eq $char 0 2267 2267
328 2267 next;
329 }
330  
331 39400 ▶ next unless $char eq ',';
Branch: 1 branch
BranchTrueFalseTotal
unless $char eq "," 39014 386 39400
332  
333 386 ▶ if (!@stack) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stack) 83 303 386
334 83 my $chunk = substr($text, $start, $i - $start);
335 83 push @parts, $chunk;
336 83 $start = $i + 1;
337 }
338 }
339  
340 4688 ▶ push @parts, substr($text, $start) if $start <= length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $start <= length $text 4688 0 4688
341  
342 4688 return @parts;
343 }
344  
345 2116 ▶sub _split_top_level_operator {
Subroutine _split_top_level_operator: called CC=24 SCAR=32.9
346 2116 my ($text, $operator) = @_;
347  
348 2116 ▶ return unless defined $text && defined $operator && length($operator) == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and defined $operator and length $operator == 1 0 2116 2116
Condition33%2/6
defined $text and defined $operator and length $operator == 1
!ll&&!rl&&r
002116
defined $text and defined $operator
!ll&&!rl&&r
002116
MC/DC0%0/3
defined $text and defined $operator and length $operator == 1
defined $text defined $operator length $operator == 1
Truth table25%1/4
A and B and C
A= defined $textB= defined $operatorC= length $operator == 1
ABCresult
0XX0
10X0
1100
1111
349  
350 2116 my %pairs = (
351 '(' => ')',
352 '[' => ']',
353 '{' => '}',
354 );
355 2116 my %closing = reverse %pairs;
356  
357 2116 my @stack;
358 my $string;
359 2116 my $escape = 0;
360  
361 2116 ▶ for (my $i = 0; $i < length $text; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 18332 2062 20394
362 18332 my $char = substr($text, $i, 1);
363  
364 18332 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 1574 16758 18332
365 1574 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 6 1568 1574
366 6 $escape = 0;
367 6 next;
368 }
369  
370 1568 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 6 1562 1568
371 6 $escape = 1;
372 6 next;
373 }
374  
375 1562 ▶ if ($char eq $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $string) 340 1222 1562
376 340 undef $string;
377 }
378  
379 1562 next;
380 }
381  
382 16758 ▶ if ($char eq "'" || $char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"") 340 16418 16758
Condition100%3/3
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
333716418
MC/DC100%2/2
$char eq "'" or $char eq "\""
$char eq "'" $char eq "\""
Truth table100%3/3
A or B
A= $char eq "'"B= $char eq "\""
ABresult
1X1
011
000
383 340 $string = $char;
384 340 next;
385 }
386  
387 16418 ▶ if (exists $pairs{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pairs{$char}) 781 15637 16418
388 781 push @stack, $char;
389 781 next;
390 }
391  
392 15637 ▶ if (exists $closing{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $closing{$char}) 781 14856 15637
393 781 ▶ return if !@stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 781 781
394 781 my $open = pop @stack;
395 781 ▶ return if $pairs{$open} ne $char;
Branch: 1 branch
BranchTrueFalseTotal
if $pairs{$open} ne $char 0 781 781
396 781 next;
397 }
398  
399 14856 ▶ next if $char ne $operator;
Branch: 1 branch
BranchTrueFalseTotal
if $char ne $operator 14782 74 14856
400  
401 74 ▶ if (!@stack) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stack) 56 18 74
402 56 ▶ if ($operator eq '+' || $operator eq '-') {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "+" or $operator eq "-") 56 0 56
Condition33%1/3
$operator eq "+" or $operator eq "-"
l!l&&r!l&&!r
5600
MC/DC0%0/2
$operator eq "+" or $operator eq "-"
$operator eq "+" $operator eq "-"
Truth table33%1/3
A or B
A= $operator eq "+"B= $operator eq "-"
ABresult
1X1
011
000
403 56 ▶ my $prev = $i > 0 ? substr($text, $i - 1, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 56 0 56
404 56 ▶ my $next = $i + 1 < length $text ? substr($text, $i + 1, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$i + 1 < length $text ? : 56 0 56
405 56 ▶ if ($prev =~ /[eE]/ && $next =~ /[0-9]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev =~ /[eE]/ and $next =~ /[0-9]/) 0 56 56
Condition33%1/3
$prev =~ /[eE]/ and $next =~ /[0-9]/
!ll&&!rl&&r
5600
MC/DC0%0/2
$prev =~ /[eE]/ and $next =~ /[0-9]/
$prev =~ /[eE]/ $next =~ /[0-9]/
Truth table33%1/3
A and B
A= $prev =~ /[eE]/B= $next =~ /[0-9]/
ABresult
0X0
100
111
406 0 next;
407 }
408 56 ▶ if ($next eq '=') {
Branch: 1 branch
BranchTrueFalseTotal
if ($next eq "=") 2 54 56
409 2 next;
410 }
411 }
412  
413 54 my $lhs = substr($text, 0, $i);
414 54 my $rhs = substr($text, $i + 1);
415 54 return ($lhs, $rhs);
416 }
417 }
418  
419 2062 return;
420 }
421  
422 1481 ▶sub _split_top_level_comparison {
Subroutine _split_top_level_comparison: called CC=19 SCAR=29.4
423 1481 my ($text) = @_;
424 1481 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 1481 1481
425  
426 1481 my %close = ('(' => ')', '[' => ']', '{' => '}');
427 1481 my %open = reverse %close;
428 1481 my (@stack, $quote, $escape, @comparison);
429  
430 1481 ▶ for (my $i = 0; $i < length($text); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 14723 1472 16195
431 14723 my $char = substr($text, $i, 1);
432 14723 ▶ if (defined $quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quote) 1466 13257 14723
433 1466 ▶ if ($escape) { $escape = 0; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 6 1460 1466
434 1460 ▶ if ($char eq '\\') { $escape = 1; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 6 1454 1460
435 1454 ▶ undef $quote if $char eq $quote;
Branch: 1 branch
BranchTrueFalseTotal
if $char eq $quote 304 1150 1454
436 1454 next;
437 }
438 13257 ▶ if ($char eq q{"} || $char eq q{'}) { $quote = $char; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\"" or $char eq "'") 304 12953 13257
Condition100%3/3
$char eq "\"" or $char eq "'"
l!l&&r!l&&!r
301312953
MC/DC100%2/2
$char eq "\"" or $char eq "'"
$char eq "\"" $char eq "'"
Truth table100%3/3
A or B
A= $char eq "\""B= $char eq "'"
ABresult
1X1
011
000
439 12953 ▶ if (exists $close{$char}) { push @stack, $char; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $close{$char}) 708 12245 12953
440 12245 ▶ if (exists $open{$char}) { pop @stack if @stack; next; }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $open{$char}) 708 11537 12245
if @stack 708 0 708
441 11537 ▶ next if @stack;
Branch: 1 branch
BranchTrueFalseTotal
if @stack 2124 9413 11537
442  
443 9413 my $tail = substr($text, $i);
444 9413 ▶ my $previous = $i > 0 ? substr($text, $i - 1, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 7969 1444 9413
445 9413 ▶ if (($i == 0 || $previous =~ /\s/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0 || $previous =~ /\s/ and $tail =~ /^(?:and|or)(?=\s|$)/) 9 9404 9413
Condition100%6/6
$i == 0 || $previous =~ /\s/ and $tail =~ /^(?:and|or)(?=\s|$)/
!ll&&!rl&&r
765017549
$i == 0 or $previous =~ /\s/
l!l&&r!l&&!r
14443197650
MC/DC66%2/3
$i == 0 || $previous =~ /\s/ and $tail =~ /^(?:and|or)(?=\s|$)/
$i == 0 $previous =~ /\s/ $tail =~ /^(?:and|or)(?=\s|$)/
Truth table80%4/5
A or B and C
A= $i == 0B= $previous =~ /\s/C= $tail =~ /^(?:and|or)(?=\s|$)/
ABCresult
00X0
1X00
0100
1X11
0111
446 && $tail =~ /^(?:and|or)(?=\s|$)/)
447 {
448 # Compound boolean expressions are handled by the condition
449 # evaluator, which applies jq's logical precedence. Splitting
450 # only their first comparison would make the rest an operand.
451 9 return;
452 }
453 9404 ▶ if (!@comparison && $tail =~ /^(==|!=|>=|<=|>|<)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @comparison and $tail =~ /^(==|!=|>=|<=|>|<)/) 48 9356 9404
Condition100%3/3
not @comparison and $tail =~ /^(==|!=|>=|<=|>|<)/
!ll&&!rl&&r
449890748
MC/DC100%2/2
not @comparison and $tail =~ /^(==|!=|>=|<=|>|<)/
not @comparison $tail =~ /^(==|!=|>=|<=|>|<)/
Truth table100%3/3
not(A) and B
A= not @comparisonB= $tail =~ /^(==|!=|>=|<=|>|<)/
ABresult
0X0
100
111
454 48 my $operator = $1;
455 48 @comparison = (substr($text, 0, $i), $operator, substr($text, $i + length($operator)));
456 }
457 }
458 1472 return @comparison;
459 }
460  
461 165 ▶sub _split_top_level_keyword {
Subroutine _split_top_level_keyword: called CC=22 SCAR=33.1
462 165 my ($text, $keyword) = @_;
463 165 ▶ return ($text) unless defined $text && defined $keyword && length $keyword;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text and defined $keyword and length $keyword 0 165 165
Condition33%2/6
defined $text and defined $keyword and length $keyword
!ll&&!rl&&r
00165
defined $text and defined $keyword
!ll&&!rl&&r
00165
MC/DC0%0/3
defined $text and defined $keyword and length $keyword
defined $text defined $keyword length $keyword
Truth table25%1/4
A and B and C
A= defined $textB= defined $keywordC= length $keyword
ABCresult
0XX0
10X0
1100
1111
464  
465 165 my %close = ('(' => ')', '[' => ']', '{' => '}');
466 165 my %open = reverse %close;
467 165 my (@stack, $quote, $escape, @parts);
468 165 my $start = 0;
469  
470 165 ▶ for (my $i = 0; $i < length($text); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 1988 165 2153
471 1988 my $char = substr($text, $i, 1);
472 1988 ▶ if (defined $quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $quote) 248 1740 1988
473 0 ▶ if ($escape) { $escape = 0; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 0 248 248
474 0 ▶ if ($char eq '\\') { $escape = 1; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 0 248 248
475 248 ▶ undef $quote if $char eq $quote;
Branch: 1 branch
BranchTrueFalseTotal
if $char eq $quote 54 194 248
476 248 next;
477 }
478 1740 ▶ if ($char eq q{"} || $char eq q{'}) { $quote = $char; next; }
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\"" or $char eq "'") 54 1686 1740
Condition66%2/3
$char eq "\"" or $char eq "'"
l!l&&r!l&&!r
5401686
MC/DC50%1/2
$char eq "\"" or $char eq "'"
$char eq "\"" $char eq "'"
Truth table66%2/3
A or B
A= $char eq "\""B= $char eq "'"
ABresult
1X1
011
000
479 1686 ▶ if (exists $close{$char}) { push @stack, $char; next; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $close{$char}) 22 1664 1686
480 1664 ▶ if (exists $open{$char}) { pop @stack if @stack; next; }
Branch: 2 branches
BranchTrueFalseTotal
if (exists $open{$char}) 22 1642 1664
if @stack 22 0 22
481 1642 ▶ next if @stack;
Branch: 1 branch
BranchTrueFalseTotal
if @stack 92 1550 1642
482  
483 1550 ▶ my $before = $i > 0 ? substr($text, $i - 1, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$i > 0 ? : 1390 160 1550
484 1550 my $after_pos = $i + length($keyword);
485 1550 ▶ my $after = $after_pos < length($text) ? substr($text, $after_pos, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$after_pos < length $text ? : 1298 252 1550
486 1550 ▶ next unless substr($text, $i, length($keyword)) eq $keyword;
Branch: 1 branch
BranchTrueFalseTotal
unless substr($text, $i, length $keyword) eq $keyword 1540 10 1550
487 10 ▶ next unless ($i == 0 || $before =~ /\s/);
Branch: 1 branch
BranchTrueFalseTotal
unless $i == 0 or $before =~ /\s/ 0 10 10
Condition33%1/3
$i == 0 or $before =~ /\s/
l!l&&r!l&&!r
0100
MC/DC0%0/2
$i == 0 or $before =~ /\s/
$i == 0 $before =~ /\s/
Truth table33%1/3
A or B
A= $i == 0B= $before =~ /\s/
ABresult
1X1
011
000
488 10 ▶ next unless ($after_pos == length($text) || $after =~ /\s/);
Branch: 1 branch
BranchTrueFalseTotal
unless $after_pos == length $text or $after =~ /\s/ 0 10 10
Condition33%1/3
$after_pos == length $text or $after =~ /\s/
l!l&&r!l&&!r
0100
MC/DC0%0/2
$after_pos == length $text or $after =~ /\s/
$after_pos == length $text $after =~ /\s/
Truth table33%1/3
A or B
A= $after_pos == length $textB= $after =~ /\s/
ABresult
1X1
011
000
489  
490 10 push @parts, substr($text, $start, $i - $start);
491 10 $start = $after_pos;
492 10 $i = $after_pos - 1;
493 }
494  
495 165 push @parts, substr($text, $start);
496 165 return @parts;
497 }
498  
499 58 ▶sub _split_top_level_colon {
Subroutine _split_top_level_colon: called CC=15 SCAR=31.3
500 58 my ($text) = @_;
501  
502 58 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 58 58
503  
504 58 my %pairs = (
505 '(' => ')',
506 '[' => ']',
507 '{' => '}',
508 );
509 58 my %closing = reverse %pairs;
510  
511 58 my @stack;
512 my $string;
513 58 my $escape = 0;
514  
515 58 ▶ for (my $i = 0; $i < length $text; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $text) 363 4 367
516 363 my $char = substr($text, $i, 1);
517  
518 363 ▶ if (defined $string) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $string) 151 212 363
519 151 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 0 151 151
520 0 $escape = 0;
521 0 next;
522 }
523  
524 151 ▶ if ($char eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\\") 0 151 151
525 0 $escape = 1;
526 0 next;
527 }
528  
529 151 ▶ if ($char eq $string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq $string) 29 122 151
530 29 undef $string;
531 }
532  
533 151 next;
534 }
535  
536 212 ▶ if ($char eq "'" || $char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'" or $char eq "\"") 29 183 212
Condition66%2/3
$char eq "'" or $char eq "\""
l!l&&r!l&&!r
029183
MC/DC50%1/2
$char eq "'" or $char eq "\""
$char eq "'" $char eq "\""
Truth table66%2/3
A or B
A= $char eq "'"B= $char eq "\""
ABresult
1X1
011
000
537 29 $string = $char;
538 29 next;
539 }
540  
541 183 ▶ if (exists $pairs{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pairs{$char}) 0 183 183
542 0 push @stack, $char;
543 0 next;
544 }
545  
546 183 ▶ if (exists $closing{$char}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $closing{$char}) 0 183 183
547 0 ▶ return unless @stack;
Branch: 1 branch
BranchTrueFalseTotal
unless @stack 0 0 0
548 0 my $open = pop @stack;
549 0 ▶ return unless $pairs{$open} eq $char;
Branch: 1 branch
BranchTrueFalseTotal
unless $pairs{$open} eq $char 0 0 0
550 0 next;
551 }
552  
553 183 ▶ next if $char ne ':';
Branch: 1 branch
BranchTrueFalseTotal
if $char ne ":" 129 54 183
554  
555 54 ▶ if (!@stack) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stack) 54 0 54
556 54 my $lhs = substr($text, 0, $i);
557 54 my $rhs = substr($text, $i + 1);
558 54 return ($lhs, $rhs);
559 }
560 }
561  
562 4 return;
563 }
564  
565 16 ▶sub _interpret_object_key {
Subroutine _interpret_object_key: called CC=6 SCAR=19.2
566 16 my ($raw) = @_;
567  
568 16 ▶ return unless defined $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw 0 16 16
569  
570 16 my $text = $raw;
571 16 $text =~ s/^\s+|\s+$//g;
572 16 ▶ return if $text eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $text eq "" 0 16 16
573  
574 16 my $decoded = eval { $FROMJSON_DECODER->decode($text) };
575 16 ▶ if (!$@ && !ref $decoded) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@ or ref $decoded) 3 13 16
Condition66%2/3
$@ or ref $decoded
l!l&&r!l&&!r
1303
MC/DC50%1/2
$@ or ref $decoded
$@ ref $decoded
Truth table66%2/3
A or B
A= $@B= ref $decoded
ABresult
1X1
011
000
576 3 return $decoded;
577 }
578  
579 13 ▶ if ($text =~ /^'(.*)'$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^'(.*)'$/s) 0 13 13
580 0 my $inner = $1;
581 0 $inner =~ s/\\'/'/g;
582 0 return $inner;
583 }
584  
585 13 return $text;
586 }
587  
588 0 ▶sub _split_top_level_semicolon {
Subroutine _split_top_level_semicolon: not called CC=2 SCAR=17.9
589 0 my ($text) = @_;
590  
591 0 my @parts = _split_top_level_semicolons($text);
592 0 ▶ return unless @parts == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 0 0 0
593  
594 0 return @parts;
595 }
596  
597 2202 ▶sub _matches_keyword {
Subroutine _matches_keyword: called CC=9 SCAR=22.3
598 2202 my ($text, $pos, $keyword) = @_;
599  
600 2202 ▶ return 0 unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 2202 2202
601 2202 ▶ return 0 if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 2202 2202
602  
603 2202 my $kw_len = length $keyword;
604 2202 ▶ return 0 if $pos + $kw_len > length $text;
Branch: 1 branch
BranchTrueFalseTotal
if $pos + $kw_len > length $text 30 2172 2202
605 2172 ▶ return 0 if substr($text, $pos, $kw_len) ne $keyword;
Branch: 1 branch
BranchTrueFalseTotal
if substr($text, $pos, $kw_len) ne $keyword 2123 49 2172
606  
607 49 ▶ my $before = $pos == 0 ? '' : substr($text, $pos - 1, 1);
Branch: 1 branch
BranchTrueFalseTotal
$pos == 0 ? : 10 39 49
608 49 ▶ my $after = ($pos + $kw_len) < length $text ? substr($text, $pos + $kw_len, 1) : '';
Branch: 1 branch
BranchTrueFalseTotal
$pos + $kw_len < length $text ? : 39 10 49
609  
610 49 ▶ return 0 if $before =~ /[A-Za-z0-9_]/;
Branch: 1 branch
BranchTrueFalseTotal
if $before =~ /[A-Za-z0-9_]/ 0 49 49
611 49 ▶ return 0 if $after =~ /[A-Za-z0-9_]/;
Branch: 1 branch
BranchTrueFalseTotal
if $after =~ /[A-Za-z0-9_]/ 0 49 49
612  
613 49 return 1;
614 }
615  
616 1362 ▶sub _parse_if_expression {
Subroutine _parse_if_expression: called CC=47 SCAR=44.6
617 1362 my ($expr) = @_;
618  
619 1362 ▶ return undef unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 1362 1362
620  
621 1362 my $copy = _strip_wrapping_parens($expr);
622 1362 $copy =~ s/^\s+|\s+$//g;
623 1362 ▶ return undef unless $copy =~ /^if\b/;
Branch: 1 branch
BranchTrueFalseTotal
unless $copy =~ /^if\b/ 1352 10 1362
624  
625 10 my $len = length $copy;
626 10 my $pos = 0;
627  
628 10 ▶ return undef unless _matches_keyword($copy, $pos, 'if');
Branch: 1 branch
BranchTrueFalseTotal
unless _matches_keyword($copy, $pos, "if") 0 10 10
629 10 $pos += 2;
630  
631 10 my $depth = 1;
632 10 my $state = 'condition';
633 10 my $current = '';
634 10 my $condition;
635 my @branches;
636 10 my $else_expr;
637  
638 10 my $in_single = 0;
639 10 my $in_double = 0;
640 10 my $escape = 0;
641  
642 10 ▶ while ($pos < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $len) 353 0 353
643 353 my $char = substr($copy, $pos, 1);
644  
645 353 ▶ if ($escape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($escape) 0 353 353
646 0 $current .= $char;
647 0 $escape = 0;
648 0 $pos++;
649 0 next;
650 }
651  
652 353 ▶ if ($in_single) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_single) 0 353 353
653 0 ▶ if ($char eq '\\') {
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq '\\') { } 0 0 0
elsif ($char eq q[']) { } 0 0 0
654 0 $escape = 1;
655 }
656 elsif ($char eq "'") {
657 0 $in_single = 0;
658 }
659 0 $current .= $char;
660 0 $pos++;
661 0 next;
662 }
663  
664 353 ▶ if ($in_double) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_double) 43 310 353
665 43 ▶ if ($char eq '\\') {
Branch: 2 branches
BranchTrueFalseTotal
if ($char eq '\\') { } 0 43 43
elsif ($char eq '"') { } 16 27 43
666 0 $escape = 1;
667 }
668 elsif ($char eq '"') {
669 16 $in_double = 0;
670 }
671 43 $current .= $char;
672 43 $pos++;
673 43 next;
674 }
675  
676 310 ▶ if ($char eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "'") 0 310 310
677 0 $in_single = 1;
678 0 $current .= $char;
679 0 $pos++;
680 0 next;
681 }
682  
683 310 ▶ if ($char eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if ($char eq "\"") 16 294 310
684 16 $in_double = 1;
685 16 $current .= $char;
686 16 $pos++;
687 16 next;
688 }
689  
690 294 ▶ if (_matches_keyword($copy, $pos, 'if')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "if")) 1 293 294
691 1 $depth++;
692 1 $current .= 'if';
693 1 $pos += 2;
694 1 next;
695 }
696  
697 293 ▶ if (_matches_keyword($copy, $pos, 'then') && $depth == 1 && $state eq 'condition') {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "then") and $depth == 1 and $state eq "condition") 12 281 293
Condition83%5/6
_matches_keyword($copy, $pos, "then") and $depth == 1 and $state eq "condition"
!ll&&!rl&&r
281012
_matches_keyword($copy, $pos, "then") and $depth == 1
!ll&&!rl&&r
280112
MC/DC66%2/3
_matches_keyword($copy, $pos, "then") and $depth == 1 and $state eq "condition"
_matches_keyword($copy, $pos, "then") $depth == 1 $state eq "condition"
Truth table75%3/4
A and B and C
A= _matches_keyword($copy, $pos, "then")B= $depth == 1C= $state eq "condition"
ABCresult
0XX0
10X0
1100
1111
698 12 $condition = $current;
699 12 $condition =~ s/^\s+|\s+$//g;
700 12 ▶ return undef unless defined $condition && length $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $condition and length $condition 0 12 12
Condition33%1/3
defined $condition and length $condition
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $condition and length $condition
defined $condition length $condition
Truth table33%1/3
A and B
A= defined $conditionB= length $condition
ABresult
0X0
100
111
701  
702 12 $current = '';
703 12 $state = 'then';
704 12 $pos += 4;
705 12 next;
706 }
707  
708 281 ▶ if (_matches_keyword($copy, $pos, 'elif') && $depth == 1 && $state eq 'then') {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "elif") and $depth == 1 and $state eq "then") 2 279 281
Condition66%4/6
_matches_keyword($copy, $pos, "elif") and $depth == 1 and $state eq "then"
!ll&&!rl&&r
27902
_matches_keyword($copy, $pos, "elif") and $depth == 1
!ll&&!rl&&r
27902
MC/DC33%1/3
_matches_keyword($copy, $pos, "elif") and $depth == 1 and $state eq "then"
_matches_keyword($copy, $pos, "elif") $depth == 1 $state eq "then"
Truth table50%2/4
A and B and C
A= _matches_keyword($copy, $pos, "elif")B= $depth == 1C= $state eq "then"
ABCresult
0XX0
10X0
1100
1111
709 2 my $then_expr = $current;
710 2 $then_expr =~ s/^\s+|\s+$//g;
711 2 ▶ $then_expr = '.' if !length $then_expr;
Branch: 1 branch
BranchTrueFalseTotal
unless length $then_expr 0 2 2
712  
713 2 ▶ return undef unless defined $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $condition 0 2 2
714 2 push @branches, { condition => $condition, then => $then_expr };
715  
716 2 $condition = undef;
717 2 $current = '';
718 2 $state = 'condition';
719 2 $pos += 4;
720 2 next;
721 }
722  
723 279 ▶ if (_matches_keyword($copy, $pos, 'else') && $depth == 1 && $state eq 'then') {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "else") and $depth == 1 and $state eq "then") 9 270 279
Condition83%5/6
_matches_keyword($copy, $pos, "else") and $depth == 1 and $state eq "then"
!ll&&!rl&&r
27009
_matches_keyword($copy, $pos, "else") and $depth == 1
!ll&&!rl&&r
26919
MC/DC66%2/3
_matches_keyword($copy, $pos, "else") and $depth == 1 and $state eq "then"
_matches_keyword($copy, $pos, "else") $depth == 1 $state eq "then"
Truth table75%3/4
A and B and C
A= _matches_keyword($copy, $pos, "else")B= $depth == 1C= $state eq "then"
ABCresult
0XX0
10X0
1100
1111
724 9 my $then_expr = $current;
725 9 $then_expr =~ s/^\s+|\s+$//g;
726 9 ▶ $then_expr = '.' if !length $then_expr;
Branch: 1 branch
BranchTrueFalseTotal
unless length $then_expr 0 9 9
727  
728 9 ▶ return undef unless defined $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $condition 0 9 9
729 9 push @branches, { condition => $condition, then => $then_expr };
730  
731 9 $condition = undef;
732 9 $current = '';
733 9 $state = 'else';
734 9 $pos += 4;
735 9 next;
736 }
737  
738 270 ▶ if (_matches_keyword($copy, $pos, 'end')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "end")) 11 259 270
739 11 ▶ if ($depth == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 1) { } 10 1 11
740 10 ▶ if ($state eq 'then') {
Branch: 3 branches
BranchTrueFalseTotal
if ($state eq 'then') { } 1 9 10
elsif ($state eq 'else') { } 9 0 9
elsif ($state eq 'condition') { } 0 0 0
741 1 my $then_expr = $current;
742 1 $then_expr =~ s/^\s+|\s+$//g;
743 1 ▶ $then_expr = '.' if !length $then_expr;
Branch: 1 branch
BranchTrueFalseTotal
unless length $then_expr 0 1 1
744  
745 1 ▶ return undef unless defined $condition;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $condition 0 1 1
746 1 push @branches, { condition => $condition, then => $then_expr };
747 }
748 elsif ($state eq 'else') {
749 9 my $else = $current;
750 9 $else =~ s/^\s+|\s+$//g;
751 9 ▶ $else_expr = length $else ? $else : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $else ? : 9 0 9
752 }
753 elsif ($state eq 'condition') {
754 0 return undef;
755 }
756  
757 10 $depth = 0;
758 10 $pos += 3;
759 10 $current = '';
760 10 $state = 'done';
761 10 last;
762 }
763 else {
764 1 $depth--;
765 1 $current .= 'end';
766 1 $pos += 3;
767 1 next;
768 }
769 }
770  
771 259 ▶ if (_matches_keyword($copy, $pos, 'then') && $depth > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "then") and $depth > 1) 1 258 259
Condition66%2/3
_matches_keyword($copy, $pos, "then") and $depth > 1
!ll&&!rl&&r
25801
MC/DC50%1/2
_matches_keyword($copy, $pos, "then") and $depth > 1
_matches_keyword($copy, $pos, "then") $depth > 1
Truth table66%2/3
A and B
A= _matches_keyword($copy, $pos, "then")B= $depth > 1
ABresult
0X0
100
111
772 1 $current .= 'then';
773 1 $pos += 4;
774 1 next;
775 }
776  
777 258 ▶ if (_matches_keyword($copy, $pos, 'elif') && $depth > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "elif") and $depth > 1) 0 258 258
Condition33%1/3
_matches_keyword($copy, $pos, "elif") and $depth > 1
!ll&&!rl&&r
25800
MC/DC0%0/2
_matches_keyword($copy, $pos, "elif") and $depth > 1
_matches_keyword($copy, $pos, "elif") $depth > 1
Truth table33%1/3
A and B
A= _matches_keyword($copy, $pos, "elif")B= $depth > 1
ABresult
0X0
100
111
778 0 $current .= 'elif';
779 0 $pos += 4;
780 0 next;
781 }
782  
783 258 ▶ if (_matches_keyword($copy, $pos, 'else') && $depth > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (_matches_keyword($copy, $pos, "else") and $depth > 1) 1 257 258
Condition66%2/3
_matches_keyword($copy, $pos, "else") and $depth > 1
!ll&&!rl&&r
25701
MC/DC50%1/2
_matches_keyword($copy, $pos, "else") and $depth > 1
_matches_keyword($copy, $pos, "else") $depth > 1
Truth table66%2/3
A and B
A= _matches_keyword($copy, $pos, "else")B= $depth > 1
ABresult
0X0
100
111
784 1 $current .= 'else';
785 1 $pos += 4;
786 1 next;
787 }
788  
789 257 $current .= $char;
790 257 $pos++;
791 }
792  
793 10 ▶ return undef unless @branches;
Branch: 1 branch
BranchTrueFalseTotal
unless @branches 0 10 10
794  
795 10 ▶ if ($pos < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < $len) 0 10 10
796 0 my $remaining = substr($copy, $pos);
797 0 $remaining =~ s/^\s+//;
798 0 ▶ return undef if $remaining =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
if $remaining =~ /\S/ 0 0 0
799 }
800  
801 return {
802 10 branches => \@branches,
803 else => $else_expr,
804 };
805 }
806  
807 1352 ▶sub _parse_reduce_expression {
Subroutine _parse_reduce_expression: called CC=4 SCAR=13.9
808 1352 my ($expr) = @_;
809  
810 1352 ▶ return undef unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 1352 1352
811  
812 1352 my $copy = _strip_wrapping_parens($expr);
813 1352 ▶ return undef unless $copy =~ /^reduce\s+(.+?)\s+as\s+\$(\w+)\s*\((.*)\)$/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $copy =~ /^reduce\s+(.+?)\s+as\s+\$(\w+)\s*\((.*)\)$/s 1348 4 1352
814  
815 4 my ($generator, $var_name, $body) = ($1, $2, $3);
816 4 my @parts = _split_top_level_semicolons($body);
817 4 ▶ return undef unless @parts == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 2 0 4 4
818 4 my ($init_expr, $update_expr) = @parts;
819  
820 4 $generator =~ s/^\s+|\s+$//g;
821 4 $init_expr =~ s/^\s+|\s+$//g;
822 4 $update_expr =~ s/^\s+|\s+$//g;
823  
824 return {
825 4 generator => $generator,
826 var_name => $var_name,
827 init_expr => $init_expr,
828 update_expr => $update_expr,
829 };
830 }
831  
832 1366 ▶sub _parse_foreach_expression {
Subroutine _parse_foreach_expression: called CC=8 SCAR=21.3
833 1366 my ($expr) = @_;
834  
835 1366 ▶ return undef unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 1366 1366
836  
837 1366 my $copy = _strip_wrapping_parens($expr);
838 1366 ▶ return undef unless $copy =~ /^foreach\s+(.+?)\s+as\s+\$(\w+)\s*\((.*)\)$/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $copy =~ /^foreach\s+(.+?)\s+as\s+\$(\w+)\s*\((.*)\)$/s 1362 4 1366
839  
840 4 my ($generator, $var_name, $body) = ($1, $2, $3);
841 4 my @parts = _split_top_level_semicolons($body);
842 4 ▶ return undef unless @parts >= 2 && @parts <= 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts >= 2 and @parts <= 3 0 4 4
Condition33%1/3
@parts >= 2 and @parts <= 3
!ll&&!rl&&r
004
MC/DC0%0/2
@parts >= 2 and @parts <= 3
@parts >= 2 @parts <= 3
Truth table33%1/3
A and B
A= @parts >= 2B= @parts <= 3
ABresult
0X0
100
111
843  
844 4 my ($init_expr, $update_expr, $extract_expr) = @parts;
845  
846 4 for ($generator, $init_expr, $update_expr) {
847 12 ▶ next unless defined $_;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ 0 12 12
848 12 s/^\s+|\s+$//g;
849 }
850  
851 4 ▶ if (defined $extract_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extract_expr) 1 3 4
852 1 $extract_expr =~ s/^\s+|\s+$//g;
853 }
854  
855 return {
856 4 generator => $generator,
857 var_name => $var_name,
858 init_expr => $init_expr,
859 update_expr => $update_expr,
860 extract_expr => $extract_expr,
861 };
862 }
863  
864 48 ▶sub _resolve_variable_reference {
Subroutine _resolve_variable_reference: called CC=7 SCAR=22.1
865 48 my ($self, $name) = @_;
866  
867 48 ▶ return (undef, 0) unless defined $self && ref($self) eq 'JQ::Lite';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self and ref $self eq "JQ::Lite" 0 48 48
Condition33%1/3
defined $self and ref $self eq "JQ::Lite"
!ll&&!rl&&r
0048
MC/DC0%0/2
defined $self and ref $self eq "JQ::Lite"
defined $self ref $self eq "JQ::Lite"
Truth table33%1/3
A and B
A= defined $selfB= ref $self eq "JQ::Lite"
ABresult
0X0
100
111
868 48 ▶ return (undef, 0) unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 48 48
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
0048
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
869  
870 48 ▶ my $vars = $self->{_vars} || {};
Condition50%1/2
$self->{'_vars'} || {}
l!l
480
MC/DC0%0/1
$self->{'_vars'} || {}
$self->{'_vars'}
Truth table50%1/2
A
A= $self->{'_vars'}
Aresult
11
00
871 48 ▶ return (undef, 0) unless exists $vars->{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $vars->{$name} 1 47 48
872  
873 47 return ($vars->{$name}, 1);
874 }
875  
876 48 ▶sub _evaluate_variable_reference {
Subroutine _evaluate_variable_reference: called CC=5 SCAR=16.2
877 48 my ($self, $name, $suffix) = @_;
878  
879 48 my ($value, $exists) = _resolve_variable_reference($self, $name);
880 48 ▶ return () unless $exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $exists 1 47 48
881  
882 47 ▶ return ($value) if !defined $suffix || $suffix !~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $suffix and $suffix =~ /\S/ 38 9 47
Condition66%2/3
defined $suffix and $suffix =~ /\S/
!ll&&!rl&&r
0389
MC/DC50%1/2
defined $suffix and $suffix =~ /\S/
defined $suffix $suffix =~ /\S/
Truth table66%2/3
A and B
A= defined $suffixB= $suffix =~ /\S/
ABresult
0X0
100
111
883  
884 9 my $expr = $suffix;
885 9 $expr =~ s/^\s+//;
886  
887 9 my ($values, $ok) = _evaluate_value_expression($self, $value, $expr);
888 9 ▶ return $ok ? @$values : ();
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 9 0 9
889 }
890  
891 901 ▶sub _evaluate_value_expression {
Subroutine _evaluate_value_expression: called CC=35 SCAR=38.8
892 901 my ($self, $context, $expr) = @_;
893  
894 901 ▶ return ([], 0) unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 901 901
895  
896 901 my $copy = _strip_wrapping_parens($expr);
897 901 $copy =~ s/^\s+|\s+$//g;
898 901 ▶ return ([], 0) if $copy eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $copy eq "" 0 901 901
899  
900 901 ▶ if (_looks_like_expression($copy)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_looks_like_expression($copy)) 66 835 901
901 my %builtins = (
902 0 ▶ floor => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
903 0 my ($value) = @_;
904 0 my $numeric = _coerce_number_strict($value, 'floor() argument');
905 0 return _floor($numeric);
906 },
907 0 ▶ ceil => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
908 0 my ($value) = @_;
909 0 my $numeric = _coerce_number_strict($value, 'ceil() argument');
910 0 return _ceil($numeric);
911 },
912 0 ▶ round => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
913 0 my ($value) = @_;
914 0 my $numeric = _coerce_number_strict($value, 'round() argument');
915 0 return _round($numeric);
916 },
917 1 ▶ tonumber => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
918 1 my ($value) = @_;
919 1 return _tonumber($value);
920 },
921 66 );
922  
923 my ($ok, $value) = JQ::Lite::Expression::evaluate(
924 expr => $copy,
925 context => $context,
926 18 ▶ resolve_path => sub {
Subroutine __ANON__: called CC=4 SCAR=15.6
927 18 my ($ctx, $path) = @_;
928 18 ▶ return $ctx if !defined $path || $path eq '';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $path or $path eq "" 0 18 18
Condition33%1/3
not defined $path or $path eq ""
l!l&&r!l&&!r
0018
MC/DC0%0/2
not defined $path or $path eq ""
not defined $path $path eq ""
Truth table33%1/3
not(A) or B
A= not defined $pathB= $path eq ""
ABresult
1X1
011
000
929 18 my @values = _traverse($ctx, $path);
930 18 ▶ return @values ? $values[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@values ? : 18 0 18
931 },
932 66 coerce_number => \&_coerce_number_strict,
933 builtins => \%builtins,
934 );
935  
936 58 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 9 49 58
937 9 return ([ $value ], 1);
938 }
939 }
940  
941 884 my @pipeline_parts = _split_top_level_pipes($copy);
942 884 ▶ if (@pipeline_parts > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pipeline_parts > 1) 7 877 884
943 7 ▶ if (defined $self && $self->can('run_query')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self and $self->can("run_query")) 7 0 7
Condition33%1/3
defined $self and $self->can("run_query")
!ll&&!rl&&r
007
MC/DC0%0/2
defined $self and $self->can("run_query")
defined $self $self->can("run_query")
Truth table33%1/3
A and B
A= defined $selfB= $self->can("run_query")
ABresult
0X0
100
111
944 7 my $json = _encode_json($context);
945 7 my @outputs = $self->run_query($json, $copy);
946 7 return ([ @outputs ], 1);
947 }
948 }
949  
950 877 ▶ if ($copy =~ /^\$(\w+)(.*)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copy =~ /^\$(\w+)(.*)$/s) 32 845 877
951 32 ▶ my ($var, $suffix) = ($1, $2 // '');
Condition50%1/2
$2 // ""
l!l
320
MC/DC0%0/1
$2 // ""
$2
Truth table50%1/2
A
A= $2
Aresult
11
00
952 32 my @values = _evaluate_variable_reference($self, $var, $suffix);
953 32 return (\@values, 1);
954 }
955  
956 845 ▶ if ($copy =~ /^\[(.*)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copy =~ /^\[(.*)$/s) 3 842 845
957 3 $copy = ".$copy";
958 }
959  
960 845 ▶ if ($copy eq '.') {
Branch: 1 branch
BranchTrueFalseTotal
if ($copy eq ".") 38 807 845
961 38 return ([ $context ], 1);
962 }
963  
964 807 ▶ if ($copy =~ /^\.(.*)$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copy =~ /^\.(.*)$/s) 155 652 807
965 155 my $path = $1;
966 155 $path =~ s/^\s+|\s+$//g;
967  
968 155 my $is_bracket_slice = $path =~ /\[[^\]]*:[^\]]*\]/;
969 155 ▶ if (($path !~ /\s/ || $is_bracket_slice) && $path !~ /[+\-*\/]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (!($path =~ /\s/) || $is_bracket_slice and not $path =~ m[[+\-*/]]) 100 55 155
Condition66%4/6
!($path =~ /\s/) || $is_bracket_slice and not $path =~ m[[+\-*/]]
!ll&&!rl&&r
550100
not $path =~ /\s/ or $is_bracket_slice
l!l&&r!l&&!r
100055
MC/DC33%1/3
!($path =~ /\s/) || $is_bracket_slice and not $path =~ m[[+\-*/]]
not $path =~ /\s/ $is_bracket_slice not $path =~ m[[+\-*/]]
Truth table40%2/5
not(A) or B and not(C)
A= not $path =~ /\s/B= $is_bracket_sliceC= not $path =~ m[[+\-*/]]
ABCresult
00X0
1X00
0100
1X11
0111
970 100 ▶ return ([], 1) unless defined $context;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $context 0 100 100
971 100 ▶ return ([], 1) if $path eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $path eq "" 0 100 100
972  
973 100 my @values = _traverse($context, $path);
974 100 return (\@values, 1);
975 }
976 }
977  
978 707 my ($lhs_expr, $rhs_expr) = _split_top_level_operator($copy, '+');
979 707 ▶ if (defined $lhs_expr && defined $rhs_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lhs_expr and defined $rhs_expr) 39 668 707
Condition66%2/3
defined $lhs_expr and defined $rhs_expr
!ll&&!rl&&r
668039
MC/DC50%1/2
defined $lhs_expr and defined $rhs_expr
defined $lhs_expr defined $rhs_expr
Truth table66%2/3
A and B
A= defined $lhs_exprB= defined $rhs_expr
ABresult
0X0
100
111
980 39 $lhs_expr =~ s/^\s+|\s+$//g;
981 39 $rhs_expr =~ s/^\s+|\s+$//g;
982  
983 39 ▶ if (length $lhs_expr && length $rhs_expr) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $lhs_expr and length $rhs_expr) 39 0 39
Condition33%1/3
length $lhs_expr and length $rhs_expr
!ll&&!rl&&r
0039
MC/DC0%0/2
length $lhs_expr and length $rhs_expr
length $lhs_expr length $rhs_expr
Truth table33%1/3
A and B
A= length $lhs_exprB= length $rhs_expr
ABresult
0X0
100
111
984 39 my ($lhs_values, $lhs_ok) = _evaluate_value_expression($self, $context, $lhs_expr);
985 39 my $lhs;
986 39 ▶ if ($lhs_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhs_ok) { } 37 2 39
987 37 ▶ $lhs = @$lhs_values ? $lhs_values->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$lhs_values ? : 37 0 37
988 }
989 else {
990 2 my @outputs = $self->run_query(_encode_json($context), $lhs_expr);
991 2 ▶ $lhs = @outputs ? $outputs[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@outputs ? : 1 1 2
992 }
993  
994 39 my ($rhs_values, $rhs_ok) = _evaluate_value_expression($self, $context, $rhs_expr);
995 39 my $rhs;
996 39 ▶ if ($rhs_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhs_ok) { } 38 1 39
997 38 ▶ $rhs = @$rhs_values ? $rhs_values->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$rhs_values ? : 38 0 38
998 }
999 else {
1000 1 my @outputs = $self->run_query(_encode_json($context), $rhs_expr);
1001 1 ▶ $rhs = @outputs ? $outputs[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
@outputs ? : 0 1 1
1002 }
1003  
1004 39 my $combined = _apply_addition($lhs, $rhs);
1005 37 return ([ $combined ], 1);
1006 }
1007 }
1008  
1009 668 my $decoded = eval { _decode_json($copy) };
1010 668 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 93 575 668
1011 93 return ([ $decoded ], 1);
1012 }
1013  
1014 575 ▶ if ($copy =~ /^'(.*)'$/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copy =~ /^'(.*)'$/s) 0 575 575
1015 0 my $text = $1;
1016 0 $text =~ s/\\'/'/g;
1017 0 return ([ $text ], 1);
1018 }
1019  
1020 575 ▶ if ($copy !~ /\bthen\b/i
Branch: 1 branch
BranchTrueFalseTotal
if (not $copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i and $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/) 11 564 575
Condition77%7/9
not $copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i and $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
!ll&&!rl&&r
1055411
$copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i
l!l&&r!l&&!r
100565
$copy =~ /\bthen\b/i or $copy =~ /\belse\b/i
l!l&&r!l&&!r
100565
MC/DC50%2/4
not $copy =~ /\bthen\b/i || $copy =~ /\belse\b/i || $copy =~ /\bend\b/i and $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
$copy =~ /\bthen\b/i $copy =~ /\belse\b/i $copy =~ /\bend\b/i $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
Truth table60%3/5
not(A or B || C) and D
A= $copy =~ /\bthen\b/iB= $copy =~ /\belse\b/iC= $copy =~ /\bend\b/iD= $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/
ABCDresult
1XXX0
01XX0
001X0
00000
00011
1021 && $copy !~ /\belse\b/i
1022 && $copy !~ /\bend\b/i
1023 && $copy =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b|\bcontains\b|\bhas\b|\bmatch\b)/)
1024 {
1025 11 my $bool = _evaluate_condition($context, $copy);
1026 11 ▶ my $json_bool = $bool ? JSON::PP::true : JSON::PP::false;
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 9 2 11
1027 11 return ([ $json_bool ], 1);
1028 }
1029  
1030 564 return ([], 0);
1031 }
1032  
1033 52 ▶sub _apply_addition {
Subroutine _apply_addition: called CC=27 SCAR=44.8
1034 52 my ($left, $right) = @_;
1035  
1036 52 ▶ return $right if !defined $left;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left 1 51 52
1037 51 ▶ return $left if !defined $right;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $right 0 51 51
1038  
1039 51 ▶ if (ref($left) eq 'JSON::PP::Boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "JSON::PP::Boolean") 1 50 51
1040 1 ▶ $left = $left ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$left ? : 1 0 1
1041 }
1042  
1043 51 ▶ if (ref($right) eq 'JSON::PP::Boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right eq "JSON::PP::Boolean") 0 51 51
1044 0 ▶ $right = $right ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$right ? : 0 0 0
1045 }
1046  
1047 51 ▶ if (!ref $left && !ref $right) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $left or ref $right) 50 1 51
Condition66%2/3
ref $left or ref $right
l!l&&r!l&&!r
1050
MC/DC50%1/2
ref $left or ref $right
ref $left ref $right
Truth table66%2/3
A or B
A= ref $leftB= ref $right
ABresult
1X1
011
000
1048 50 my $left_is_string = _is_string_scalar($left);
1049 50 my $right_is_string = _is_string_scalar($right);
1050  
1051 50 ▶ if ($left_is_string || $right_is_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left_is_string or $right_is_string) 13 37 50
Condition66%2/3
$left_is_string or $right_is_string
l!l&&r!l&&!r
13037
MC/DC50%1/2
$left_is_string or $right_is_string
$left_is_string $right_is_string
Truth table66%2/3
A or B
A= $left_is_stringB= $right_is_string
ABresult
1X1
011
000
1052 13 ▶ die 'addition operands must both be strings' if !$left_is_string || !$right_is_string;
Branch: 1 branch
BranchTrueFalseTotal
unless $left_is_string and $right_is_string 3 10 13
Condition66%2/3
$left_is_string and $right_is_string
!ll&&!rl&&r
0310
MC/DC50%1/2
$left_is_string and $right_is_string
$left_is_string $right_is_string
Truth table66%2/3
A and B
A= $left_is_stringB= $right_is_string
ABresult
0X0
100
111
1053 10 ▶ $left = '' unless defined $left;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $left 0 10 10
1054 10 ▶ $right = '' unless defined $right;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $right 0 10 10
1055 10 return "$left$right";
1056 }
1057  
1058 37 ▶ if (looks_like_number($left) && looks_like_number($right)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($left) and &looks_like_number($right)) 37 0 37
Condition33%1/3
&looks_like_number($left) and &looks_like_number($right)
!ll&&!rl&&r
0037
MC/DC0%0/2
&looks_like_number($left) and &looks_like_number($right)
&looks_like_number($left) &looks_like_number($right)
Truth table33%1/3
A and B
A= &looks_like_number($left)B= &looks_like_number($right)
ABresult
0X0
100
111
1059 37 return 0 + $left + $right;
1060 }
1061  
1062 0 die 'addition operands must both be numbers or both be strings';
1063 }
1064  
1065 1 ▶ if (ref $left eq 'ARRAY' && ref $right eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "ARRAY" and ref $right eq "ARRAY") 0 1 1
Condition33%1/3
ref $left eq "ARRAY" and ref $right eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
ref $left eq "ARRAY" and ref $right eq "ARRAY"
ref $left eq "ARRAY" ref $right eq "ARRAY"
Truth table33%1/3
A and B
A= ref $left eq "ARRAY"B= ref $right eq "ARRAY"
ABresult
0X0
100
111
1066 0 return [ @$left, @$right ];
1067 }
1068  
1069 1 ▶ if (ref $left eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "ARRAY") 0 1 1
1070 0 return [ @$left, $right ];
1071 }
1072  
1073 1 ▶ if (ref $right eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $right eq "ARRAY") 0 1 1
1074 0 return [ $left, @$right ];
1075 }
1076  
1077 1 ▶ if (ref $left eq 'HASH' && ref $right eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $left eq "HASH" and ref $right eq "HASH") 1 0 1
Condition33%1/3
ref $left eq "HASH" and ref $right eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $left eq "HASH" and ref $right eq "HASH"
ref $left eq "HASH" ref $right eq "HASH"
Truth table33%1/3
A and B
A= ref $left eq "HASH"B= ref $right eq "HASH"
ABresult
0X0
100
111
1078 1 return { %$left, %$right };
1079 }
1080  
1081 0 ▶ return $right if !ref $left && ref $right eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $left and ref $right eq "HASH" 0 0 0
Condition0%0/3
not ref $left and ref $right eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $left and ref $right eq "HASH"
not ref $left ref $right eq "HASH"
Truth table0%0/3
not(A) and B
A= not ref $leftB= ref $right eq "HASH"
ABresult
0X0
100
111
1082 0 ▶ return $left if ref $left eq 'HASH' && !ref $right;
Branch: 1 branch
BranchTrueFalseTotal
if ref $left eq "HASH" and not ref $right 0 0 0
Condition0%0/3
ref $left eq "HASH" and not ref $right
!ll&&!rl&&r
000
MC/DC0%0/2
ref $left eq "HASH" and not ref $right
ref $left eq "HASH" not ref $right
Truth table0%0/3
A and not(B)
A= ref $left eq "HASH"B= not ref $right
ABresult
0X0
100
111
1083  
1084 0 return undef;
1085 }
1086  
1087 34 ▶sub _coerce_number_strict {
Subroutine _coerce_number_strict: called CC=7 SCAR=23.2
1088 34 my ($value, $label) = @_;
1089  
1090 34 ▶ $label ||= 'value';
Condition50%1/2
$label ||= "value"
l!l
340
MC/DC0%0/1
$label ||= "value"
$label
Truth table50%1/2
A
A= $label
Aresult
11
00
1091  
1092 34 ▶ die "$label must be a number" unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 34 34
1093  
1094 34 ▶ if (ref($value) eq 'JSON::PP::Boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "JSON::PP::Boolean") 0 34 34
1095 0 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
1096 }
1097  
1098 34 ▶ die "$label must be a number" if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 34 34
1099 34 ▶ die "$label must be a number" unless looks_like_number($value);
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($value) 0 34 34
1100  
1101 34 return 0 + $value;
1102 }
1103  
1104 3 ▶sub _tonumber {
Subroutine _tonumber: called CC=7 SCAR=24.0
1105 3 my ($value) = @_;
1106  
1107 3 ▶ return undef unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 3 3
1108  
1109 3 ▶ if (ref($value) eq 'JSON::PP::Boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "JSON::PP::Boolean") 0 3 3
1110 0 ▶ return $value ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
1111 }
1112  
1113 3 ▶ if (ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) 0 3 3
1114 0 die 'tonumber(): argument must be a string or number';
1115 }
1116  
1117 3 my $text = "$value";
1118 3 $text =~ s/^\s+|\s+$//g;
1119  
1120 3 ▶ die 'tonumber(): not a numeric string' unless length $text && looks_like_number($text);
Branch: 1 branch
BranchTrueFalseTotal
unless length $text and &looks_like_number($text) 0 3 3
Condition33%1/3
length $text and &looks_like_number($text)
!ll&&!rl&&r
003
MC/DC0%0/2
length $text and &looks_like_number($text)
length $text &looks_like_number($text)
Truth table33%1/3
A and B
A= length $textB= &looks_like_number($text)
ABresult
0X0
100
111
1121  
1122 3 return 0 + $text;
1123 }
1124  
1125 2349 ▶sub _looks_like_expression {
Subroutine _looks_like_expression: called CC=7 SCAR=19.5
1126 2349 my ($expr) = @_;
1127  
1128 2349 ▶ return 0 unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 2349 2349
1129  
1130 2349 ▶ return 1 if $expr =~ /\b(?:floor|ceil|round|tonumber)\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /\b(?:floor|ceil|round|tonumber)\b/ 37 2312 2349
1131 2312 ▶ return 0 if $expr =~ /^\s*[\{\[]/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /^\s*[\{\[]/ 31 2281 2312
1132 2281 ▶ return 0 if $expr =~ /^[A-Za-z_]\w*\s*\(/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /^[A-Za-z_]\w*\s*\(/ 442 1839 2281
1133 1839 ▶ return 1 if $expr =~ /[\-*\/%]/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ m[[\-*/%]] 51 1788 1839
1134 1788 ▶ return 1 if $expr =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b)/i;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /(?:==|!=|>=|<=|>|<|\band\b|\bor\b)/i 40 1748 1788
1135  
1136 1748 return 0;
1137 }
1138  
1139 876 ▶sub _looks_like_assignment {
Subroutine _looks_like_assignment: called CC=4 SCAR=14.1
1140 876 my ($expr) = @_;
1141  
1142 876 ▶ return 0 unless defined $expr;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expr 0 876 876
1143 876 ▶ return 0 if $expr =~ /[()]/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /[()]/ 264 612 876
1144 612 ▶ return 0 if $expr =~ /(?:==|!=|>=|<=|=>|=<)/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /(?:==|!=|>=|<=|=>|=<)/ 0 612 612
1145 612 return ($expr =~ /=/);
1146 }
1147  
1148 18 ▶sub _parse_assignment_expression {
Subroutine _parse_assignment_expression: called CC=5 SCAR=16.6
1149 18 my ($expr) = @_;
1150  
1151 18 ▶ $expr //= '';
Condition50%1/2
$expr //= ""
l!l
180
MC/DC0%0/1
$expr //= ""
$expr
Truth table50%1/2
A
A= $expr
Aresult
11
00
1152  
1153 18 my ($lhs, $op, $rhs) = ($expr =~ /^(.*?)\s*([+\-*\/]?=)\s*(.*)$/);
1154  
1155 18 ▶ $lhs //= '';
Condition50%1/2
$lhs //= ""
l!l
180
MC/DC0%0/1
$lhs //= ""
$lhs
Truth table50%1/2
A
A= $lhs
Aresult
11
00
1156 18 ▶ $rhs //= '';
Condition50%1/2
$rhs //= ""
l!l
180
MC/DC0%0/1
$rhs //= ""
$rhs
Truth table50%1/2
A
A= $rhs
Aresult
11
00
1157 18 ▶ $op //= '=';
Condition50%1/2
$op //= "="
l!l
180
MC/DC0%0/1
$op //= "="
$op
Truth table50%1/2
A
A= $op
Aresult
11
00
1158  
1159 18 $lhs =~ s/^\s+|\s+$//g;
1160 18 $rhs =~ s/^\s+|\s+$//g;
1161  
1162 18 $lhs =~ s/^\.//;
1163  
1164 18 my $value_spec = _parse_assignment_value($rhs);
1165  
1166 18 return ($lhs, $value_spec, $op);
1167 }
1168  
1169 18 ▶sub _parse_assignment_value {
Subroutine _parse_assignment_value: called CC=5 SCAR=16.1
1170 18 my ($raw) = @_;
1171  
1172 18 ▶ $raw //= '';
Condition50%1/2
$raw //= ""
l!l
180
MC/DC0%0/1
$raw //= ""
$raw
Truth table50%1/2
A
A= $raw
Aresult
11
00
1173 18 $raw =~ s/^\s+|\s+$//g;
1174  
1175 18 ▶ if ($raw =~ /^\.(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /^\.(.+)$/) 1 17 18
1176 1 return { type => 'path', value => $1 };
1177 }
1178  
1179 17 my $decoded = eval { _decode_json($raw) };
1180 17 ▶ if (!$@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 12 5 17
1181 12 return { type => 'literal', value => $decoded };
1182 }
1183  
1184 5 ▶ if ($raw =~ /^'(.*)'$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /^'(.*)'$/) 2 3 5
1185 2 my $text = $1;
1186 2 $text =~ s/\\'/'/g;
1187 2 return { type => 'literal', value => $text };
1188 }
1189  
1190 3 return { type => 'expression', value => $raw };
1191 }
1192  
1193 182 1;
« blib/lib/JQ/Lite/Filters.pm ↑ Summary blib/lib/JQ/Lite/Util/Transform.pm »