Path/Evaluator.pm

filter: Statementstmt 88.9% 369 / 415 Branchbran 77.2% 173 / 224 Conditioncond 54.2% 38 / 70 MC/DCmcdc 31.5% 12 / 38 Subroutinesub 94.8% 37 / 39 Podpod 100% 3 / 3 totaltotal 80.1% 632 / 789 CC 157 SCAR 30.2
CC
157
Cov
82%
_get_token
136.2
_compare
26.3
_evaluate
20.1
CRAP 20.5
↑ Summary Path/Tokenizer.pm »
1 package JSON::Path::Evaluator;
2 20 $JSON::Path::Evaluator::VERSION = '1.0.6';
3 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: A module that recursively evaluates JSONPath expressions with native support for Javascript-style filters
7  
8 20 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 20 ▶use Carp::Assert qw(assert);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 20 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 20 ▶use JSON::Path::Constants qw(:operators :symbols);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 20 ▶use JSON::Path::Tokenizer qw(tokenize);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 20 ▶use List::Util qw/pairs uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 20 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 20 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 20 ▶use Scalar::Util qw/looks_like_number blessed refaddr/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 20 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 20 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 # VERSION
21 20 ▶use Exporter::Shiny qw/evaluate_jsonpath/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 20 our $AUTHORITY = 'cpan:POPEFELIX';
23  
24 20 Readonly my $OPERATOR_IS_TRUE => 'IS_TRUE';
25 20 Readonly my $OPERATOR_TYPE_PATH => 1;
26 20 Readonly my $OPERATOR_TYPE_COMPARISON => 2;
27 20 Readonly my %OPERATORS => (
28 $TOKEN_ROOT => $OPERATOR_TYPE_PATH, # $
29 $TOKEN_CURRENT => $OPERATOR_TYPE_PATH, # @
30 $TOKEN_CHILD => $OPERATOR_TYPE_PATH, # . OR []
31 $TOKEN_RECURSIVE => $OPERATOR_TYPE_PATH, # ..
32 $TOKEN_ALL => $OPERATOR_TYPE_PATH, # *
33 $TOKEN_FILTER_OPEN => $OPERATOR_TYPE_PATH, # ?(
34 $TOKEN_SCRIPT_OPEN => $OPERATOR_TYPE_PATH, # (
35 $TOKEN_FILTER_SCRIPT_CLOSE => $OPERATOR_TYPE_PATH, # )
36 $TOKEN_SUBSCRIPT_OPEN => $OPERATOR_TYPE_PATH, # [
37 $TOKEN_SUBSCRIPT_CLOSE => $OPERATOR_TYPE_PATH, # ]
38 $TOKEN_UNION => $OPERATOR_TYPE_PATH, # ,
39 $TOKEN_ARRAY_SLICE => $OPERATOR_TYPE_PATH, # [ start:end:step ]
40 $TOKEN_SINGLE_EQUAL => $OPERATOR_TYPE_COMPARISON, # =
41 $TOKEN_DOUBLE_EQUAL => $OPERATOR_TYPE_COMPARISON, # ==
42 $TOKEN_TRIPLE_EQUAL => $OPERATOR_TYPE_COMPARISON, # ===
43 $TOKEN_GREATER_THAN => $OPERATOR_TYPE_COMPARISON, # >
44 $TOKEN_LESS_THAN => $OPERATOR_TYPE_COMPARISON, # <
45 $TOKEN_NOT_EQUAL => $OPERATOR_TYPE_COMPARISON, # !=
46 $TOKEN_GREATER_EQUAL => $OPERATOR_TYPE_COMPARISON, # >=
47 $TOKEN_LESS_EQUAL => $OPERATOR_TYPE_COMPARISON, # <=
48 $TOKEN_REGEX => $OPERATOR_TYPE_COMPARISON, # =~
49 );
50  
51 20 Readonly my $ASSERT_ENABLE => $ENV{ASSERT_ENABLE};
52  
53  
54 147 ▶sub new {
Subroutine new: called CC=9 SCAR=22.5
Pod documented
55 147 my $class = shift;
56 0 ▶ my %args = ref $_[0] eq 'HASH' ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 147 147
57 147 my $self = {};
58 147 for my $key (qw/root expression/) {
59 294 ▶ croak qq{Missing required argument '$key' in constructor} unless $args{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{$key} 0 294 294
60 294 $self->{$key} = $args{$key};
61 }
62 147 ▶ $self->{want_ref} = $args{want_ref} || 0;
Condition50%1/2
$args{'want_ref'} || 0
l!l
0147
MC/DC0%0/1
$args{'want_ref'} || 0
$args{'want_ref'}
Truth table50%1/2
A
A= $args{'want_ref'}
Aresult
11
00
63 147 ▶ $self->{_calling_context} = $args{_calling_context} || 0;
Condition50%1/2
$args{'_calling_context'} || 0
l!l
1470
MC/DC0%0/1
$args{'_calling_context'} || 0
$args{'_calling_context'}
Truth table50%1/2
A
A= $args{'_calling_context'}
Aresult
11
00
64  
65 my $script_engine =
66 147 ▶ $args{script_engine} ? $args{script_engine} : $self->{expression} =~ /\$_/ ? 'perl' : undef;
Branch: 2 branches
BranchTrueFalseTotal
$args{'script_engine'} ? : 27 120 147
$self->{'expression'} =~ /\$_/ ? : 5 115 120
67 147 ▶ $self->{script_engine} = $script_engine || 'PseudoJS';
Condition100%2/2
$script_engine || 'PseudoJS'
l!l
32115
MC/DC100%1/1
$script_engine || 'PseudoJS'
$script_engine
Truth table100%2/2
A
A= $script_engine
Aresult
11
00
68 147 bless $self, $class;
69 147 return $self;
70 }
71  
72  
73 147 ▶sub evaluate_jsonpath {
Subroutine evaluate_jsonpath: called CC=5 SCAR=16.1
Pod documented
74 147 my ( $json_object, $expression, %args ) = @_;
75 147 ▶ if ( !ref $json_object ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $json_object) 90 57 147
76 90 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
77 90 $json_object = decode_json($json_object);
78 }
79 0 ▶ catch {
Subroutine __ANON__: not called CC=1 SCAR=6.9
80 0 croak qq{Unable to decode $json_object as JSON: $_};
81 }
82 90 }
83  
84 147 ▶ my $want_ref = delete $args{want_ref} || 0;
Condition100%2/2
delete $args{'want_ref'} || 0
l!l
32115
MC/DC100%1/1
delete $args{'want_ref'} || 0
delete $args{'want_ref'}
Truth table100%2/2
A
A= delete $args{'want_ref'}
Aresult
11
00
85 147 ▶ my $want_path = delete $args{want_path} || 0;
Condition100%2/2
delete $args{'want_path'} || 0
l!l
12135
MC/DC100%1/1
delete $args{'want_path'} || 0
delete $args{'want_path'}
Truth table100%2/2
A
A= delete $args{'want_path'}
Aresult
11
00
86  
87 147 ▶ my $self = __PACKAGE__->new(
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 145 2 147
88 root => $json_object,
89 expression => $expression,
90 _calling_context => wantarray ? 'ARRAY' : 'SCALAR',
91 %args
92 );
93 147 return $self->evaluate( $expression, want_ref => $want_ref, want_path => $want_path );
94 }
95  
96  
97 147 ▶sub evaluate {
Subroutine evaluate: called CC=6 SCAR=17.9
Pod documented
98 147 my ( $self, $expression, %args ) = @_;
99  
100 147 my $json_object = $self->{root};
101  
102 147 my $token_stream = [ tokenize($expression) ];
103 #use Data::Dumper qw/Dumper/;
104 #print Dumper $token_stream;
105 147 ▶ shift @{$token_stream} if $token_stream->[0] eq $TOKEN_ROOT;
Branch: 1 branch
BranchTrueFalseTotal
if $token_stream->[0] eq $JSON::Path::Evaluator::TOKEN_ROOT 147 0 147
106 147 ▶ shift @{$token_stream} if $token_stream->[0] eq $TOKEN_CHILD;
Branch: 1 branch
BranchTrueFalseTotal
if $token_stream->[0] eq $JSON::Path::Evaluator::TOKEN_CHILD 128 19 147
107  
108 147 ▶ if ( $args{want_path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"want_path"}) 12 135 147
109 12 my %reftable = $self->_reftable_walker($json_object);
110 12 my @refs = $self->_evaluate( $json_object, dclone $token_stream, 1 );
111  
112 12 my @paths;
113 12 for my $ref (@refs) {
114 18 ▶ my $refaddr = ref ${$ref} ? refaddr ${$ref} : refaddr $ref;
Branch: 1 branch
BranchTrueFalseTotal
ref ${$ref;} ? : 10 8 18
115 18 push @paths, $reftable{$refaddr};
116 }
117 12 return @paths;
118 }
119  
120 135 my @ret = $self->_evaluate( $json_object, $token_stream, $args{want_ref} );
121 135 return @ret;
122 }
123  
124 82 ▶sub _reftable_walker {
Subroutine _reftable_walker: called CC=9 SCAR=22.2
125 82 my ( $self, $json_object, $base_path ) = @_;
126  
127 82 ▶ $base_path //= '$';
Condition100%2/2
$base_path //= "\$"
l!l
7012
MC/DC100%1/1
$base_path //= "\$"
$base_path
Truth table100%2/2
A
A= $base_path
Aresult
11
00
128 82 ▶ $json_object //= $self->root;
Condition33%1/3
$json_object //= $self->root
l!l&&r!l&&!r
8200
MC/DC0%0/2
$json_object //= $self->root
$json_object $self->root
Truth table33%1/3
A //= B
A= $json_objectB= $self->root
ABresult
1X1
011
000
129  
130 82 my @entries = ( refaddr $json_object => $base_path );
131  
132 82 ▶ if ( _arraylike($json_object) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (_arraylike($json_object)) { } 9 73 82
elsif (_hashlike($json_object)) { } 67 6 73
133 9 for ( 0 .. $#{$json_object} ) {
134 33 my $path = sprintf q{%s['%d']}, $base_path, $_;
135 33 ▶ if ( ref $json_object->[$_] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json_object->[$_]) { } 33 0 33
136 33 push @entries, $self->_reftable_walker( $json_object->[$_], $path );
137 }
138 else {
139 0 push @entries, refaddr \( $json_object->[$_] ) => $path;
140 }
141 }
142 }
143 elsif ( _hashlike($json_object) ) {
144 67 for my $index ( keys %{$json_object} ) {
145 241 my $path = sprintf q{%s['%s']}, $base_path, $index;
146 241 ▶ if ( ref $json_object->{$index} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $json_object->{$index}) { } 37 204 241
147 37 push @entries, $self->_reftable_walker( $json_object->{$index}, $path );
148 }
149 else {
150 204 push @entries, refaddr \( $json_object->{$index} ) => $path;
151 }
152 }
153 }
154 82 return @entries;
155 }
156  
157 868 ▶sub _evaluate { # This assumes that the token stream is syntactically valid
Subroutine _evaluate: called CC=20 SCAR=30.0
158 868 my ( $self, $obj, $token_stream, $want_ref ) = @_;
159  
160 868 ▶ return unless ref $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj 84 784 868
161  
162 784 ▶ $token_stream //= [];
Condition50%1/2
$token_stream //= []
l!l
7840
MC/DC0%0/1
$token_stream //= []
$token_stream
Truth table50%1/2
A
A= $token_stream
Aresult
11
00
163  
164 784 ▶ while ( defined( my $token = shift @{$token_stream} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$token_stream;})) 1539 0 1539
165 1539 ▶ next if $token eq $TOKEN_CURRENT;
Branch: 1 branch
BranchTrueFalseTotal
if $token eq $JSON::Path::Evaluator::TOKEN_CURRENT 284 1255 1539
166 1255 ▶ next if $token eq $TOKEN_CHILD;
Branch: 1 branch
BranchTrueFalseTotal
if $token eq $JSON::Path::Evaluator::TOKEN_CHILD 471 784 1255
167  
168 784 ▶ if ( $token eq $TOKEN_FILTER_OPEN ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($token eq $JSON::Path::Evaluator::TOKEN_FILTER_OPEN) { } 73 711 784
elsif ($token eq $JSON::Path::Evaluator::TOKEN_RECURSIVE) { } 16 695 711
169 73 my $filter_expression = shift @{$token_stream};
170  
171 73 my $closing_token = shift @{$token_stream};
172 73 ▶ assert( $closing_token eq $TOKEN_FILTER_SCRIPT_CLOSE, q{Closing token seen} ) if $ASSERT_ENABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ASSERT_ENABLE 0 73 73
173  
174 # Find all indices matching the filter expression. This modifies $token_stream
175 73 my @matching_indices = $self->_process_filter( $obj, $filter_expression );
176  
177 73 ▶ if ( !@{$token_stream} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$token_stream;}) { } 39 34 73
178 39 my @got = map { _get( $obj, $_ ) } @matching_indices;
179 39 ▶ return $want_ref ? @got : map { ${$_} } @got;
Branch: 1 branch
BranchTrueFalseTotal
$want_ref ? : 7 32 39
180 }
181 else {
182 34 return map { $self->_evaluate( _get( $obj, $_ ), dclone($token_stream), $want_ref ) } @matching_indices;
183 }
184 }
185 elsif ( $token eq $TOKEN_RECURSIVE )
186 { # Sweet Jesus, Pooh, that's not honey! You're eating Sweet Jesus, Pooh, that's not honey! You're eating...
187 16 my $index = shift @{$token_stream};
188 16 my @matched;
189 16 ▶ if ( $index eq $TOKEN_FILTER_OPEN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index eq $JSON::Path::Evaluator::TOKEN_FILTER_OPEN) 2 14 16
190 2 my $filter_expression = shift @{$token_stream};
191  
192 2 my $closing_token = shift @{$token_stream};
193 2 ▶ assert( $closing_token eq $TOKEN_FILTER_SCRIPT_CLOSE, q{Closing token seen} ) if $ASSERT_ENABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ASSERT_ENABLE 0 2 2
194  
195 2 return $self->_filter_recursive( $obj, $filter_expression, $want_ref );
196 }
197  
198 14 @matched = _match_recursive( $obj, $index, $want_ref );
199 14 ▶ if ( !@{$token_stream} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$token_stream;}) 6 8 14
200 6 return @matched;
201 }
202 8 return map { $self->_evaluate( $_, dclone($token_stream), $want_ref ) } @matched;
203 }
204 else {
205 695 my $index;
206 695 ▶ if ( $token eq $TOKEN_SUBSCRIPT_OPEN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq $JSON::Path::Evaluator::TOKEN_SUBSCRIPT_OPEN) { } 98 597 695
207 98 $index = shift @{$token_stream};
208 98 my $closing_token = shift @{$token_stream};
209 98 ▶ assert $closing_token eq $TOKEN_SUBSCRIPT_CLOSE if $ASSERT_ENABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ASSERT_ENABLE 0 98 98
210 }
211 else {
212 597 $index = $token;
213 }
214  
215 695 ▶ assert( !$OPERATORS{$index}, qq{"$index" is not an operator} ) if $index ne $TOKEN_ALL;
Branch: 1 branch
BranchTrueFalseTotal
if $index ne $JSON::Path::Evaluator::TOKEN_ALL 666 29 695
216 695 ▶ assert( !ref $index, q{Index is a scalar} ) if $ASSERT_ENABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ASSERT_ENABLE 0 695 695
217  
218 695 my (@got) = _get( $obj, $index, create_key => $want_ref ); # This always returns a ref
219 695 ▶ if ( !@{$token_stream} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$token_stream;}) { } 419 276 695
220 419 ▶ return $want_ref ? @got : map { ${$_} } @got;
Branch: 1 branch
BranchTrueFalseTotal
$want_ref ? : 44 375 419
221 }
222 else {
223 276 return map { $self->_evaluate( ${$_}, dclone($token_stream), $want_ref ) } @got;
224 }
225 }
226 }
227 }
228  
229 113 ▶sub _process_filter {
Subroutine _process_filter: called CC=3 SCAR=11.2
230 113 my ( $self, $obj, $filter_expression ) = @_;
231  
232 113 my @matching_indices;
233 113 ▶ if ( $self->{script_engine} eq 'PseudoJS' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'script_engine'} eq 'PseudoJS') { } 106 7 113
elsif ($self->{'script_engine'} eq 'perl') { } 7 0 7
234 106 @matching_indices = $self->_process_pseudo_js( $obj, $filter_expression );
235 }
236 elsif ( $self->{script_engine} eq 'perl' ) {
237 7 @matching_indices = $self->_process_perl( $obj, $filter_expression );
238 }
239 else {
240 0 croak qq{Unsupported script engine "$self->{script_engine}"};
241 }
242 113 return @matching_indices;
243 }
244  
245 # This _always_ has to return a ref so that when it's called from evaluate( ... , want_ref => 1)
246 # So that we can return a ref into the object (e.g. for use as an lvalue), even when the path points
247 # to a scalar (which will of course be copied).
248 #
249 # I.E.: for { foo => 'bar' }, we always want \( foo->{bar} ) so that
250 # JSON::Path->new('$.foo')->value($obj) = 'baz' works like it oughtta.
251 897 ▶sub _get {
Subroutine _get: called CC=16 SCAR=27.9
252 897 my ( $object, $index, %args ) = @_;
253  
254 897 ▶ assert( _hashlike($object) || _arraylike($object), 'Object is a hashref or an arrayref' ) if $ASSERT_ENABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ASSERT_ENABLE 0 897 897
Condition0%0/3
_hashlike($object) || _arraylike($object)
l!l&&r!l&&!r
000
MC/DC0%0/2
_hashlike($object) || _arraylike($object)
_hashlike($object) _arraylike($object)
Truth table0%0/3
A || B
A= _hashlike($object)B= _arraylike($object)
ABresult
1X1
011
000
255  
256 897 my $create_key = $args{create_key};
257  
258 # When want_ref is passed to _evaluate(), it will return a reference to whatever was matched.
259 # If what was matched is itself a ref (e.g. an arrayref), _evaluate() will return a ref of
260 # type 'REF'.
261 897 ▶ if ( ref $object eq 'REF' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object eq "REF") 32 865 897
262 32 $object = ${$object};
263 }
264  
265 897 ▶ if ( $index eq $TOKEN_ALL ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index eq $JSON::Path::Evaluator::TOKEN_ALL) { } 29 868 897
266 29 ▶ if ( _hashlike($object) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_hashlike($object)) { } 3 26 29
267 3 return map { \($_) } values %{$object};
268 }
269 else {
270 26 return map { \($_) } @{$object};
271 }
272 }
273 else {
274 868 my @indices;
275 868 ▶ if ( $index =~ /$TOKEN_ARRAY_SLICE/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index =~ /$JSON::Path::Evaluator::TOKEN_ARRAY_SLICE/) { } 9 859 868
elsif ($index =~ /$JSON::Path::Evaluator::TOKEN_UNION/) { } 5 854 859
276 0 ▶ my $length = _hashlike($object) ? scalar values %{$object} : scalar @{$object};
Branch: 1 branch
BranchTrueFalseTotal
_hashlike($object) ? : 0 9 9
277 9 @indices = _slice( $index, $length );
278 }
279 elsif ( $index =~ /$TOKEN_UNION/ ) {
280 5 @indices = split /$TOKEN_UNION/, $index;
281 }
282 else {
283 854 @indices = ($index);
284 }
285  
286 868 ▶ if ( _hashlike($object) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_hashlike($object)) { } 689 179 868
287 689 ▶ if ($create_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($create_key) { } 85 604 689
288 85 return map { \( $object->{$_} ) } @indices;
289 }
290 else {
291 604 my @ret;
292 604 for my $index (@indices) {
293 605 ▶ push @ret, \( $object->{$index} ) if exists $object->{$index};
Branch: 1 branch
BranchTrueFalseTotal
if exists $object->{$index} 568 37 605
294 }
295 604 return @ret;
296 }
297 }
298 else {
299 179 my @numeric_indices = grep { looks_like_number($_) } @indices;
300 179 ▶ if ($create_key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($create_key) { } 18 161 179
301 18 return map { \( $object->[$_] ) } @numeric_indices;
302 }
303 else {
304 161 my @ret;
305 161 for my $index (@numeric_indices) {
306 152 ▶ push @ret, \( $object->[$index] ) if exists $object->[$index];
Branch: 1 branch
BranchTrueFalseTotal
if exists $object->[$index] 152 0 152
307 }
308 161 return @ret;
309 }
310 }
311 }
312 }
313  
314 40 ▶sub _indices {
Subroutine _indices: called CC=3 SCAR=11.0
315 40 my $object = shift;
316 return
317 27 ▶ _hashlike($object) ? keys %{$object}
Branch: 1 branch
BranchTrueFalseTotal
_arraylike($object) ? : 11 2 13
318 40 ▶ : _arraylike($object) ? ( 0 .. $#{$object} )
Branch: 1 branch
BranchTrueFalseTotal
_hashlike($object) ? : 27 13 40
319 : ();
320 }
321  
322 1366 ▶sub _hashlike {
Subroutine _hashlike: called CC=4 SCAR=15.6
323 1366 my $object = shift;
324 1366 ▶ return ( ref $object eq 'HASH' || ( blessed $object && $object->can('typeof') && $object->typeof eq 'HASH' ) );
Condition55%5/9
ref $object eq 'HASH' || builtin::blessed($object) && $object->can('typeof') && $object->typeof eq 'HASH'
l!l&&r!l&&!r
10340332
builtin::blessed($object) and $object->can("typeof") and $object->typeof eq "HASH"
!ll&&!rl&&r
33200
builtin::blessed($object) and $object->can("typeof")
!ll&&!rl&&r
312200
MC/DC25%1/4
ref $object eq 'HASH' || builtin::blessed($object) && $object->can('typeof') && $object->typeof eq 'HASH'
ref $object eq 'HASH' builtin::blessed($object) $object->can("typeof") $object->typeof eq "HASH"
Truth table60%3/5
A || B and C and D
A= ref $object eq 'HASH'B= builtin::blessed($object)C= $object->can("typeof")D= $object->typeof eq "HASH"
ABCDresult
1XXX1
01111
00XX0
010X0
01100
325 }
326  
327 462 ▶sub _arraylike {
Subroutine _arraylike: called CC=4 SCAR=15.6
328 462 my $object = shift;
329 462 ▶ return ( ref $object eq 'ARRAY' || ( blessed $object && $object->can('typeof') && $object->typeof eq 'ARRAY' ) );
Condition55%5/9
ref $object eq 'ARRAY' || builtin::blessed($object) && $object->can('typeof') && $object->typeof eq 'ARRAY'
l!l&&r!l&&!r
1860276
builtin::blessed($object) and $object->can("typeof") and $object->typeof eq "ARRAY"
!ll&&!rl&&r
27600
builtin::blessed($object) and $object->can("typeof")
!ll&&!rl&&r
258180
MC/DC25%1/4
ref $object eq 'ARRAY' || builtin::blessed($object) && $object->can('typeof') && $object->typeof eq 'ARRAY'
ref $object eq 'ARRAY' builtin::blessed($object) $object->can("typeof") $object->typeof eq "ARRAY"
Truth table60%3/5
A || B and C and D
A= ref $object eq 'ARRAY'B= builtin::blessed($object)C= $object->can("typeof")D= $object->typeof eq "ARRAY"
ABCDresult
1XXX1
01111
00XX0
010X0
01100
330 }
331  
332 0 ▶sub _get_token {
Subroutine _get_token: not called CC=13 SCAR=49.1
333 0 my $token_stream = shift;
334 0 my $token = shift @{$token_stream};
335 0 ▶ return unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 0 0
336  
337 0 ▶ if ( $token eq $TOKEN_SUBSCRIPT_OPEN ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq $JSON::Path::Evaluator::TOKEN_SUBSCRIPT_OPEN) 0 0 0
338 0 my @substream;
339 my $close_seen;
340 0 ▶ while ( defined( my $token = shift @{$token_stream} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = shift @{$token_stream;})) 0 0 0
341 0 ▶ if ( $token eq $TOKEN_SUBSCRIPT_CLOSE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq $JSON::Path::Evaluator::TOKEN_SUBSCRIPT_CLOSE) 0 0 0
342 0 $close_seen = 1;
343 0 last;
344 }
345 0 push @substream, $token;
346 }
347  
348 0 ▶ assert($close_seen) if $ASSERT_ENABLE;
Branch: 1 branch
BranchTrueFalseTotal
if $ASSERT_ENABLE 0 0 0
349  
350 0 ▶ if ( grep { $_ eq $TOKEN_ARRAY_SLICE } @substream ) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_ eq $JSON::Path::Evaluator::TOKEN_ARRAY_SLICE;} @substream) { } 0 0 0
elsif (grep {$_ eq $JSON::Path::Evaluator::TOKEN_UNION;} @substream) { } 0 0 0
351  
352 # There are five valid cases:
353 #
354 # n:m -> n:m:1
355 # n:m:s -> n:m:s
356 # :m -> 0:m:1
357 # ::s -> 0:-1:s
358 # n: -> n:-1:1
359 0 ▶ if ( $substream[0] eq $TOKEN_ARRAY_SLICE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($substream[0] eq $JSON::Path::Evaluator::TOKEN_ARRAY_SLICE) 0 0 0
360 0 unshift @substream, undef;
361 }
362  
363 20 ▶ no warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
364 0 ▶ if ( $substream[2] eq $TOKEN_ARRAY_SLICE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($substream[2] eq $JSON::Path::Evaluator::TOKEN_ARRAY_SLICE) 0 0 0
365 0 @substream = ( @substream[ ( 0, 1 ) ], undef, @substream[ ( 2 .. $#substream ) ] );
366 }
367 20 ▶ use warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
368  
369 0 my ( $start, $end, $step );
370 0 ▶ $start = $substream[0] // 0;
Condition0%0/2
$substream[0] // 0
l!l
00
MC/DC0%0/1
$substream[0] // 0
$substream[0]
Truth table0%0/2
A
A= $substream[0]
Aresult
11
00
371 0 ▶ $end = $substream[2] // -1;
Condition0%0/2
$substream[2] // -1
l!l
00
MC/DC0%0/1
$substream[2] // -1
$substream[2]
Truth table0%0/2
A
A= $substream[2]
Aresult
11
00
372 0 ▶ $step = $substream[4] // 1;
Condition0%0/2
$substream[4] // 1
l!l
00
MC/DC0%0/1
$substream[4] // 1
$substream[4]
Truth table0%0/2
A
A= $substream[4]
Aresult
11
00
373 0 return { slice => [ $start, $end, $step ] };
374 }
375 0 elsif ( grep { $_ eq $TOKEN_UNION } @substream ) {
376 0 my @union = grep { $_ ne $TOKEN_UNION } @substream;
377 0 return { union => \@union };
378 }
379  
380 0 return $substream[0];
381 }
382 0 return $token;
383 }
384  
385 # See http://wiki.ecmascript.org/doku.php?id=proposals:slice_syntax
386 #
387 # in particular, for the slice [n:m], m is *one greater* than the last index to slice.
388 # This means that the slice [3:5] will return indices 3 and 4, but *not* 5.
389 9 ▶sub _slice {
Subroutine _slice: called CC=10 SCAR=25.2
390 9 my ( $index, $length ) = @_;
391  
392 9 my ( $start, $end, $step ) = split /$TOKEN_ARRAY_SLICE/, $index, 3;
393  
394 9 ▶ if ( !defined($start) || $start eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $start or $start eq "") 0 9 9
Condition33%1/3
not defined $start or $start eq ""
l!l&&r!l&&!r
009
MC/DC0%0/2
not defined $start or $start eq ""
not defined $start $start eq ""
Truth table33%1/3
not(A) or B
A= not defined $startB= $start eq ""
ABresult
1X1
011
000
395 0 $start = 0;
396 }
397 9 ▶ if ( !defined($end) || $end eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $end or $end eq "") 6 3 9
Condition66%2/3
not defined $end or $end eq ""
l!l&&r!l&&!r
063
MC/DC50%1/2
not defined $end or $end eq ""
not defined $end $end eq ""
Truth table66%2/3
not(A) or B
A= not defined $endB= $end eq ""
ABresult
1X1
011
000
398 6 $end = -1;
399 }
400 9 ▶ if ( !defined($step) || $step eq '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $step or $step eq "") 9 0 9
Condition33%1/3
not defined $step or $step eq ""
l!l&&r!l&&!r
900
MC/DC0%0/2
not defined $step or $step eq ""
not defined $step $step eq ""
Truth table33%1/3
not(A) or B
A= not defined $stepB= $step eq ""
ABresult
1X1
011
000
401 9 $step = 1;
402 }
403  
404 9 ▶ $start = ( $length - 1 ) if $start == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $start == -1 6 3 9
405 9 ▶ $end = $length if $end == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $end == -1 6 3 9
406  
407 9 my @indices;
408 9 ▶ if ( $step < 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($step < 0) { } 0 9 9
409 0 @indices = grep { %_ % -$step == 0 } reverse( $start .. ( $end - 1 ) );
410 }
411 else {
412 9 @indices = grep { $_ % $step == 0 } ( $start .. ( $end - 1 ) );
413 }
414 9 return @indices;
415 }
416  
417 281 ▶sub _match_recursive {
Subroutine _match_recursive: called CC=13 SCAR=26.1
418 281 my ( $obj, $index, $want_ref ) = @_;
419  
420 281 my @match;
421  
422 # Fix for RT #122529.
423 #
424 # Consider the expression "$..foo..bar", evaluated with respect to the JSON "{"foo":{"bar":"baz"}}".
425 #
426 # The first term to be evaluated in the expression is "$..foo". If want_ref is passed to evaluate(),
427 # this will return a REF reference. In that case we must first dereference it to get the object that
428 # we will evaluate "..bar" with respect to.
429 281 ▶ if ( ref $obj eq 'REF' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj eq "REF") 2 279 281
430 2 $obj = ${$obj};
431 }
432  
433 281 ▶ if ( _arraylike($obj) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (_arraylike($obj)) { } 82 199 281
elsif (_hashlike($obj)) { } 191 8 199
434 82 ▶ if ( looks_like_number($index) && exists $obj->[$index] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($index) and exists $obj->[$index]) 0 82 82
Condition33%1/3
&looks_like_number($index) and exists $obj->[$index]
!ll&&!rl&&r
8200
MC/DC0%0/2
&looks_like_number($index) and exists $obj->[$index]
&looks_like_number($index) exists $obj->[$index]
Truth table33%1/3
A and B
A= &looks_like_number($index)B= exists $obj->[$index]
ABresult
0X0
100
111
435 0 ▶ push @match, $want_ref ? \( $obj->[$index] ) : $obj->[$index];
Branch: 1 branch
BranchTrueFalseTotal
$want_ref ? : 0 0 0
436 }
437 82 for ( 0 .. $#{$obj} ) {
438 251 ▶ next unless ref $obj->[$_];
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj->[$_] 136 115 251
439 115 push @match, _match_recursive( $obj->[$_], $index, $want_ref );
440 }
441 }
442 elsif ( _hashlike($obj) ) {
443 191 ▶ if ( exists $obj->{$index} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $obj->{$index}) 16 175 191
444 16 ▶ push @match, $want_ref ? \( $obj->{$index} ) : $obj->{$index};
Branch: 1 branch
BranchTrueFalseTotal
$want_ref ? : 8 8 16
445 }
446 191 for my $val ( values %{$obj} ) {
447 591 ▶ next unless ref $val;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val 439 152 591
448 152 push @match, _match_recursive( $val, $index, $want_ref );
449 }
450 }
451 281 return @match;
452 }
453  
454 40 ▶sub _filter_recursive {
Subroutine _filter_recursive: called CC=5 SCAR=16.1
455 40 my ( $self, $obj, $expression, $want_ref ) = @_;
456  
457 40 my @ret;
458  
459 # Evaluate the filter expression for the current object
460 40 my @matching_indices = $self->_process_filter( $obj, $expression );
461 40 for my $index (@matching_indices) {
462 4 my ($got) = _get( $obj, $index );
463 4 ▶ push @ret, $want_ref ? $got : ${$got};
Branch: 1 branch
BranchTrueFalseTotal
$want_ref ? : 2 2 4
464 }
465  
466 # Evaluate the filter expression for any subordinate objects
467 40 for my $index ( _indices($obj) ) {
468 122 my ($got) = _get( $obj, $index );
469 122 $got = ${$got}; # _get will always return a reference. We want the value, so dereference it
470 122 ▶ next unless ref $got;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $got 84 38 122
471 38 push @ret, $self->_filter_recursive( $got, $expression, $want_ref );
472 }
473  
474 40 return @ret;
475 }
476  
477 106 ▶sub _process_pseudo_js {
Subroutine _process_pseudo_js: called CC=12 SCAR=24.8
478 106 my ( $self, $object, $expressions ) = @_;
479  
480 106 my @expressions_or = split /\Q||\E/, $expressions;
481 106 my @matching_or;
482  
483 106 foreach my $expression (@expressions_or) {
484 117 my @expressions_and = split /\Q&&\E/, $expression;
485 117 my %matching_and;
486  
487 117 foreach my $expression (@expressions_and) {
488  
489 141 my ( $lhs, $operator, $rhs ) = _parse_psuedojs_expression($expression);
490 141 $lhs =~ s/^\s+|\s+$//g;
491  
492 141 my (@token_stream) = tokenize($lhs);
493  
494 141 ▶ if ( _hashlike($object) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (_hashlike($object)) { } 55 86 141
elsif (_arraylike($object)) { } 84 2 86
495 55 ▶ while (my ($k, $v) = each(%$object)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$object) 158 55 213
496 158 my @got = $self->_evaluate( $v, [@token_stream] );
497 158 foreach my $got (@got) {
498 56 ▶ $matching_and{$k}++ if _compare( $operator, $got, $rhs );
Branch: 1 branch
BranchTrueFalseTotal
if _compare($operator, $got, $rhs) 22 34 56
499 }
500 }
501 }
502 elsif ( _arraylike($object) ) {
503 84 my $idx = 0;
504 84 for my $value ( @{$object} ) {
505 210 my ($got) = $self->_evaluate( $value, [@token_stream] );
506 210 ▶ $matching_and{$idx}++ if _compare( $operator, $got, $rhs );
Branch: 1 branch
BranchTrueFalseTotal
if _compare($operator, $got, $rhs) 91 119 210
507 210 $idx++;
508 }
509 }
510 }
511 117 ▶ while (my ($idx, $val) = each(%matching_and)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %matching_and) 96 117 213
512 96 ▶ push @matching_or, $idx if ($val == @expressions_and);
Branch: 1 branch
BranchTrueFalseTotal
if $val == @expressions_and 71 25 96
513 }
514 }
515  
516 106 return sort(uniq(@matching_or));
517 }
518  
519 141 ▶sub _parse_psuedojs_expression {
Subroutine _parse_psuedojs_expression: called CC=13 SCAR=25.8
520 141 my $expression = shift;
521 141 my @parts;
522  
523 141 my ( $lhs, $operator, $rhs );
524  
525 # The operator could be '=', '!=', '==', '===', '<=', '>=' or '=~'
526 141 ▶ if ( $expression =~ /$EQUAL_SIGN/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expression =~ /$JSON::Path::Evaluator::EQUAL_SIGN/) { } 58 83 141
527 58 my $position = index( $expression, '=' );
528 58 ▶ if ( substr( $expression, $position + 1, 1 ) eq $EQUAL_SIGN ) { # could be '==' or '==='
Branch: 2 branches
BranchTrueFalseTotal
if (substr($expression, $position + 1, 1) eq $JSON::Path::Evaluator::EQUAL_SIGN) { } 27 31 58
elsif (substr($expression, $position + 1, 1) eq $JSON::Path::Evaluator::TILDE_SIGN) { } 18 13 31
529 27 ▶ if ( substr( $expression, $position + 2, 1 ) eq $EQUAL_SIGN ) { # ===
Branch: 1 branch
BranchTrueFalseTotal
if (substr($expression, $position + 2, 1) eq $JSON::Path::Evaluator::EQUAL_SIGN) { } 0 27 27
530 0 $operator = $TOKEN_TRIPLE_EQUAL;
531 }
532 else {
533 27 $operator = $TOKEN_DOUBLE_EQUAL;
534 }
535 }
536 elsif ( substr( $expression, $position + 1, 1 ) eq $TILDE_SIGN ) {
537 18 $operator = $TOKEN_REGEX;
538 }
539 else {
540 13 my $preceding_char = substr( $expression, $position - 1, 1 );
541 13 ▶ if ( $preceding_char eq $GREATER_THAN_SIGN ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($preceding_char eq $JSON::Path::Evaluator::GREATER_THAN_SIGN) { } 11 2 13
elsif ($preceding_char eq $JSON::Path::Evaluator::LESS_THAN_SIGN) { } 0 2 2
elsif ($preceding_char eq $JSON::Path::Evaluator::EXCLAMATION_MARK) { } 0 2 2
542 11 $operator = $TOKEN_GREATER_EQUAL;
543 }
544 elsif ( $preceding_char eq $LESS_THAN_SIGN ) {
545 0 $operator = $TOKEN_LESS_EQUAL;
546 }
547 elsif ( $preceding_char eq $EXCLAMATION_MARK ) {
548 0 $operator = $TOKEN_NOT_EQUAL;
549 }
550 else {
551 2 $operator = $TOKEN_SINGLE_EQUAL;
552 }
553 }
554 58 ( $lhs, $rhs ) = split /$operator/, $expression, 2;
555 }
556 else {
557 83 for ( grep { $OPERATORS{$_} eq $OPERATOR_TYPE_COMPARISON } keys %OPERATORS ) {
558 470 ▶ next if /$EQUAL_SIGN/;
Branch: 1 branch
BranchTrueFalseTotal
if /$JSON::Path::Evaluator::EQUAL_SIGN/ 321 149 470
559 149 ▶ if ( $expression =~ /$_/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expression =~ /$_/) 75 74 149
560 75 ( $lhs, $rhs ) = split /$_/, $expression, 2;
561 75 $operator = $_;
562 75 last;
563 }
564 }
565 }
566  
567 # FIXME: RHS is assumed to be a single value. This isn't necessarily a safe assumption.
568 141 ▶ if ($operator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator) { } 133 8 141
569 133 ▶ $rhs = _normalize( $rhs || '' );
Condition100%2/2
$rhs || ''
l!l
1294
MC/DC100%1/1
$rhs || ''
$rhs
Truth table100%2/2
A
A= $rhs
Aresult
11
00
570 133 $lhs = _normalize($lhs);
571 }
572 else {
573 8 $operator = $OPERATOR_IS_TRUE;
574 8 $lhs = $expression;
575 }
576 141 return ( $lhs, $operator, $rhs );
577 }
578  
579 266 ▶sub _normalize {
Subroutine _normalize: called CC=1 SCAR=0.0
580 266 my $string = shift;
581  
582 # NB: Stripping spaces *before* stripping quotes allows the caller to quote spaces in an index.
583 # So an index of 'foo ' will be correctly normalized as 'foo', but '"foo "' will normalize to 'foo '.
584 266 $string =~ s/\s+$//; # trim trailing spaces
585 266 $string =~ s/^\s+//; # trim leading spaces
586 266 $string =~ s/^['"](.+)['"]$/$1/; # Strip quotes from index
587 266 return $string;
588 }
589  
590 7 ▶sub _process_perl {
Subroutine _process_perl: called CC=8 SCAR=20.8
591 7 my ( $self, $object, $code ) = @_;
592  
593 7 my $cpt = Safe->new;
594 7 $cpt->permit_only( ':base_core', qw/padsv padav padhv padany rv2gv/ );
595 7 ${ $cpt->varglob('root') } = dclone( $self->{root} );
596  
597 7 my @matching;
598 7 ▶ if ( _hashlike($object) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_hashlike($object)) { } 2 5 7
599 2 for my $index ( keys %{$object} ) {
600 10 local $_ = $object->{$index};
601 10 my $ret = $cpt->reval($code);
602 10 ▶ croak qq{Error in filter: $@} if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
603 10 ▶ push @matching, $index if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 2 8 10
604 }
605 }
606 else {
607 5 for my $index ( 0 .. $#{$object} ) {
608 18 local $_ = $object->[$index];
609 18 my $ret = $cpt->reval($code);
610 18 ▶ croak qq{Error in filter: $@} if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 18 18
611 18 ▶ push @matching, $index if $ret;
Branch: 1 branch
BranchTrueFalseTotal
if $ret 8 10 18
612 }
613 }
614 7 return @matching;
615 }
616  
617 266 ▶sub _compare {
Subroutine _compare: called CC=21 SCAR=32.7
618 266 my ( $operator, $lhs, $rhs ) = @_;
619  
620 20 ▶ no warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
621 266 ▶ if ( $operator eq $OPERATOR_IS_TRUE ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq $OPERATOR_IS_TRUE) 15 251 266
622 15 ▶ return $lhs ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$lhs ? : 11 4 15
623 }
624  
625 251 ▶ my $use_numeric = looks_like_number($lhs) && looks_like_number($rhs);
Condition100%3/3
&looks_like_number($lhs) && &looks_like_number($rhs)
!ll&&!rl&&r
1388105
MC/DC100%2/2
&looks_like_number($lhs) && &looks_like_number($rhs)
&looks_like_number($lhs) &looks_like_number($rhs)
Truth table100%3/3
A && B
A= &looks_like_number($lhs)B= &looks_like_number($rhs)
ABresult
0X0
100
111
626  
627 251 ▶ if ( $operator eq '=' || $operator eq '==' || $operator eq '===' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "=" or $operator eq "==" or $operator eq "===") 66 185 251
Condition83%5/6
$operator eq "=" or $operator eq "==" or $operator eq "==="
l!l&&r!l&&!r
660185
$operator eq "=" or $operator eq "=="
l!l&&r!l&&!r
462185
MC/DC66%2/3
$operator eq "=" or $operator eq "==" or $operator eq "==="
$operator eq "=" $operator eq "==" $operator eq "==="
Truth table75%3/4
A or B or C
A= $operator eq "="B= $operator eq "=="C= $operator eq "==="
ABCresult
1XX1
01X1
0011
0000
628 66 ▶ return $use_numeric ? ( $lhs == $rhs ) : $lhs eq $rhs;
Branch: 1 branch
BranchTrueFalseTotal
$use_numeric ? : 8 58 66
629 }
630 185 ▶ if ( $operator eq '<' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "<") 26 159 185
631 26 ▶ return $use_numeric ? ( $lhs < $rhs ) : $lhs lt $rhs;
Branch: 1 branch
BranchTrueFalseTotal
$use_numeric ? : 26 0 26
632 }
633 159 ▶ if ( $operator eq '>' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq ">") 83 76 159
634 83 ▶ return $use_numeric ? ( $lhs > $rhs ) : $lhs gt $rhs;
Branch: 1 branch
BranchTrueFalseTotal
$use_numeric ? : 55 28 83
635 }
636 76 ▶ if ( $operator eq '<=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "<=") 0 76 76
637 0 ▶ return $use_numeric ? ( $lhs <= $rhs ) : $lhs le $rhs;
Branch: 1 branch
BranchTrueFalseTotal
$use_numeric ? : 0 0 0
638 }
639 76 ▶ if ( $operator eq '>=' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq ">=") 22 54 76
640 22 ▶ return $use_numeric ? ( $lhs >= $rhs ) : $lhs ge $rhs;
Branch: 1 branch
BranchTrueFalseTotal
$use_numeric ? : 16 6 22
641 }
642 54 ▶ if ( $operator eq '!=' || $operator eq '!==' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "!=" or $operator eq "!==") 0 54 54
Condition33%1/3
$operator eq "!=" or $operator eq "!=="
l!l&&r!l&&!r
0054
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
643 0 ▶ return $use_numeric ? ( $lhs != $rhs ) : $lhs ne $rhs;
Branch: 1 branch
BranchTrueFalseTotal
$use_numeric ? : 0 0 0
644 }
645  
646 54 ▶ if ( $operator eq '=~' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "=~") 54 0 54
647 54 ▶ if ( $rhs =~ m@^/(.*)/([msian]*)$@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rhs =~ m[^/(.*)/([msian]*)$]) { } 54 0 54
648 54 my $regex = $1;
649 54 my $modifiers = $2;
650 54 return $lhs =~ qr/(?$modifiers)$regex/;
651 }
652 else {
653 0 warn("Regexp need to be sorrounded by //. Allowed modifiers: msian");
654 0 return 1;
655 }
656 }
657 20 ▶ use warnings qw/uninitialized/;
Subroutine BEGIN: called CC=1 SCAR=0.0
658 }
659  
660 20 1;
661  
662 __END__
↑ Summary Path/Tokenizer.pm »