XPathEngine.pm

filter: Statementstmt 92.2% 382 / 414 Branchbran 73.2% 145 / 198 Conditioncond 74.1% 23 / 31 MC/DCmcdc 42.8% 6 / 14 Subroutinesub 98.0% 49 / 50 Podpod 100% 9 / 9 totaltotal 85.7% 614 / 716 CC 111 SCAR 21.0
CC
111
Cov
86%
_step
26.8
_is_step
11.7
_tokenize
10.1
CRAP 8.2
« XPathEngine/Expr.pm ↑ Summary XPathEngine/Step.pm »
1 #$Id: /tree-xpathengine/trunk/lib/Tree/XPathEngine.pm 25 2006-02-15T15:34:11.453583Z mrodrigu $
2 package Tree::XPathEngine;
3  
4 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶use vars qw($VERSION $AUTOLOAD $revision);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 $VERSION = '0.05';
10 6 $Tree::XPathEngine::DEBUG = 0;
11  
12 6 ▶use vars qw/
Subroutine BEGIN: called CC=1 SCAR=0.0
13 $WILD
14 $NUMBER_RE
15 $NODE_TYPE
16 $AXIS_NAME
17 %AXES
18 $LITERAL
19 $REGEXP_RE
20 $REGEXP_MOD_RE
21 6 %CACHE/;
22  
23 6 ▶use Tree::XPathEngine::Step;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use Tree::XPathEngine::Expr;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶use Tree::XPathEngine::Function;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 ▶use Tree::XPathEngine::LocationPath;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 6 ▶use Tree::XPathEngine::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 6 ▶use Tree::XPathEngine::Literal;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 6 ▶use Tree::XPathEngine::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 6 ▶use Tree::XPathEngine::NodeSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 6 ▶use Tree::XPathEngine::Root;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 # Axis name to principal node type mapping
34 6 %AXES = (
35 'ancestor' => 'element',
36 'ancestor-or-self' => 'element',
37 'attribute' => 'attribute',
38 'child' => 'element',
39 'descendant' => 'element',
40 'descendant-or-self' => 'element',
41 'following' => 'element',
42 'following-sibling' => 'element',
43 'parent' => 'element',
44 'preceding' => 'element',
45 'preceding-sibling' => 'element',
46 'self' => 'element',
47 );
48  
49 6 $WILD = qr{\*};
50 6 $NODE_TYPE = qr{(?:(text|node)\(\))};
51 6 $AXIS_NAME = '(?:' . join('|', keys %AXES) . ')::';
52 6 $NUMBER_RE = qr{(?:\d+(?:\.\d*)?|\.\d+)};
53 6 $REGEXP_RE = qr{(?:m?/(?:\\.|[^/])*/)};
54 6 $REGEXP_MOD_RE = qr{(?:[imsx]+)};
55 6 $LITERAL = qr{(?:"[^"]*"|'[^']*')};
56  
57 5 ▶sub new {
Subroutine new: called CC=3 SCAR=11.0
Pod documented
58 5 my $class = shift;
59 5 my( %option)= @_;
60
61 5 my $self = bless {}, $class;
62  
63 5 ▶ $self->{NAME}= $option{xpath_name_re} || qr/(?:[A-Za-z_][\w.-]*)/;
Condition100%2/2
$option{'xpath_name_re'} || qr/(?:[A-Za-z_][\w.-]*)/
l!l
23
MC/DC100%1/1
$option{'xpath_name_re'} || qr/(?:[A-Za-z_][\w.-]*)/
$option{'xpath_name_re'}
Truth table100%2/2
A
A= $option{'xpath_name_re'}
Aresult
11
00
64 5 $self->{NAME}= qr/(?:$self->{NAME})/; # add parens just to make sure we have them
65
66 5 ▶ _debug("New Parser being created.\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 5 5
67 5 $self->{context_set} = Tree::XPathEngine::NodeSet->new();
68 5 $self->{context_pos} = undef; # 1 based position in array context
69 5 $self->{context_size} = 0; # total size of context
70 5 $self->{vars} = {};
71 5 $self->{direction} = 'forward';
72 5 $self->{cache} = {};
73
74 5 return $self;
75 }
76  
77 148 ▶sub find {
Subroutine find: called CC=1 SCAR=0.0
Pod documented
78 148 my $self = shift;
79 148 my( $path, $context) = @_;
80 148 my $parsed_path= $self->_parse( $path);
81 143 return $parsed_path->evaluate( $context);
82 }
83  
84  
85 3 ▶sub matches {
Subroutine matches: called CC=2 SCAR=6.9
Pod documented
86 3 my $self = shift;
87 3 my ($node, $path, $context) = @_;
88  
89 3 my @nodes = $self->findnodes( $path, $context);
90  
91 3 ▶ if (grep { "$node" eq "$_" } @nodes) { return 1; }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {"$node" eq "$_";} @nodes) 2 1 3
92 1 return;
93 }
94  
95 21 ▶sub findnodes {
Subroutine findnodes: called CC=2 SCAR=6.9
Pod documented
96 21 my $self = shift;
97 21 my ($path, $context) = @_;
98
99 21 my $results = $self->find( $path, $context);
100
101 13 ▶ if ($results->isa('Tree::XPathEngine::NodeSet'))
Branch: 1 branch
BranchTrueFalseTotal
if ($results->isa('Tree::XPathEngine::NodeSet')) { } 12 1 13
102 12 { return $results->get_nodelist; }
103 else
104 1 { return (); }
105 }
106  
107  
108 3 ▶sub findnodes_as_string {
Subroutine findnodes_as_string: called CC=3 SCAR=11.1
Pod documented
109 3 my $self = shift;
110 3 my ($path, $context) = @_;
111
112 3 my $results = $self->find( $path, $context);
113
114 3 ▶ if ($results->isa('Tree::XPathEngine::NodeSet')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($results->isa('Tree::XPathEngine::NodeSet')) { } 1 2 3
elsif ($results->isa('Tree::XPathEngine::Node')) { } 0 2 2
115 1 return join('', map { $_->to_string } $results->get_nodelist);
116 }
117 elsif ($results->isa('Tree::XPathEngine::Node')) {
118 0 return $results->to_string;
119 }
120 else {
121 2 return $results->value; # CHECK
122 }
123 }
124  
125 124 ▶sub findvalue {
Subroutine findvalue: called CC=2 SCAR=6.9
Pod documented
126 124 my $self = shift;
127 124 my ($path, $context) = @_;
128 124 my $results = $self->find( $path, $context);
129 124 ▶ return $results ? $results->xpath_to_literal : '';
Branch: 1 branch
BranchTrueFalseTotal
$results ? : 102 22 124
130 }
131  
132 sub exists
133 2 ▶ { my $self = shift;
Subroutine exists: called CC=2 SCAR=6.9
Pod documented
134 2 my ($path, $context) = @_;
135 2 my @nodeset = $self->findnodes( $path, $context);
136 2 ▶ return scalar( @nodeset ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
scalar @nodeset ? : 1 1 2
137 }
138  
139 1 ▶sub get_var {
Subroutine get_var: called CC=1 SCAR=0.0
Pod documented
140 1 my $self = shift;
141 1 my $var = shift;
142 1 $self->{vars}->{$var};
143 }
144  
145 1 ▶sub set_var {
Subroutine set_var: called CC=1 SCAR=0.0
Pod documented
146 1 my $self = shift;
147 1 my $var = shift;
148 1 my $val = shift;
149 1 $self->{vars}->{$var} = $val;
150 }
151  
152 #sub _get_context_set { $_[0]->{context_set}; }
153 2309 ▶sub _set_context_set { $_[0]->{context_set} = $_[1]; }
Subroutine _set_context_set: called CC=1 SCAR=0.0
154 3 ▶sub _get_context_pos { $_[0]->{context_pos}; }
Subroutine _get_context_pos: called CC=1 SCAR=0.0
155 2821 ▶sub _set_context_pos { $_[0]->{context_pos} = $_[1]; }
Subroutine _set_context_pos: called CC=1 SCAR=0.0
156 2 ▶sub _get_context_size { $_[0]->{context_set}->size; }
Subroutine _get_context_size: called CC=1 SCAR=0.0
157 #sub _get_context_node { $_[0]->{context_set}->get_node($_[0]->{context_pos}); }
158  
159 148 ▶sub _parse {
Subroutine _parse: called CC=4 SCAR=13.9
160 148 my $self = shift;
161 148 my $path = shift;
162 148 ▶ if ($CACHE{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Tree::XPathEngine::CACHE{$path}) 18 130 148
163 18 return $CACHE{$path};
164 }
165 130 my $tokens = $self->_tokenize($path);
166  
167 129 $self->{_tokpos} = 0;
168 129 my $tree = $self->_analyze($tokens);
169
170 126 ▶ if ($self->{_tokpos} < scalar(@$tokens)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_tokpos"} < scalar @$tokens) 1 125 126
171 # didn't manage to parse entire expression - throw an exception
172 1 die "Parse of expression $path failed - junk after end of expression: $tokens->[$self->{_tokpos}]";
173 }
174
175 125 $CACHE{$path} = $tree;
176
177 125 ▶ _debug("PARSED Expr to:\n", $tree->as_string, "\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 125 125
178
179 125 return $tree;
180 }
181  
182 130 ▶sub _tokenize {
Subroutine _tokenize: called CC=10 SCAR=23.1
183 130 my $self = shift;
184 130 my $path = shift;
185 130 study $path;
186
187 130 my @tokens;
188
189 130 ▶ _debug("Parsing: $path\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 130 130
190
191 # Bug: We don't allow "'@' NodeType" which is in the grammar, but I think is just plain stupid.
192  
193 130 my $expected=''; # used to desambiguate conflicts (for REs)
194  
195 130 ▶ while( length($path))
Branch: 1 branch
BranchTrueFalseTotal
if (length $path) 1318 0 1318
196 1318 { my $token='';
197 1318 ▶ if( $expected eq 'RE' && ($path=~ m{\G\s*($REGEXP_RE $REGEXP_MOD_RE?)\s*}gcxs))
Branch: 2 branches
BranchTrueFalseTotal
if ($expected eq 'RE' and $path =~ /\G\s*($Tree::XPathEngine::REGEXP_RE $Tree::XPathEngine::REGEXP_MOD_RE?)\s*/cgsx) { } 9 1309 1318
elsif ($path =~ m{\G \s* # ignore all whitespace ( # tokens $Tree::XPathEngine::LITERAL| # literal string $Tree::XPathEngine::NUMBER_RE| # digits \.\.| # parent \.| # current ($Tree::XPathEngine::AXIS_NAME)?$Tree::XPathEngine::NODE_TYPE| # node type test (probably useless in this context) \@($self->{'NAME'}|$Tree::XPathEngine::WILD)| # attribute \$$self->{'NAME'}| # variable reference ($Tree::XPathEngine::AXIS_NAME)?($self->{'NAME'}|$Tree::XPathEngine::WILD)| # NAME,NodeType,Axis::Test \!=|<=|\-|>=|//|and|or|mod|div| # multi-char seps =~|\!~| # regexp matching (not in the XPath spec) [,\+=\|<>/\(\[\]\)]| # single char seps (?<!(\@|\(|\[))\*| # multiply operator rules (see xpath spec) (?<!::)\*| $ # match end of query ) \s* # ignore all whitespace }cgsx) { } 1179 130 1309
Condition66%2/3
$expected eq "RE" and $path =~ /\G\s*($Tree::XPathEngine::REGEXP_RE $Tree::XPathEngine::REGEXP_MOD_RE?)\s*/cgsx
!ll&&!rl&&r
130909
MC/DC50%1/2
$expected eq "RE" and $path =~ /\G\s*($Tree::XPathEngine::REGEXP_RE $Tree::XPathEngine::REGEXP_MOD_RE?)\s*/cgsx
$expected eq "RE" $path =~ /\G\s*($Tree::XPathEngine::REGEXP_RE $Tree::XPathEngine::REGEXP_MOD_RE?)\s*/cgsx
Truth table66%2/3
A and B
A= $expected eq "RE"B= $path =~ /\G\s*($Tree::XPathEngine::REGEXP_RE $Tree::XPathEngine::REGEXP_MOD_RE?)\s*/cgsx
ABresult
0X0
100
111
198 9 { $token= $1; $expected=''; }
199 elsif($path =~ m/\G
200 \s* # ignore all whitespace
201 ( # tokens
202 $LITERAL| # literal string
203 $NUMBER_RE| # digits
204 \.\.| # parent
205 \.| # current
206 ($AXIS_NAME)?$NODE_TYPE| # node type test (probably useless in this context)
207 \@($self->{NAME}|$WILD)| # attribute
208 \$$self->{NAME}| # variable reference
209 ($AXIS_NAME)?($self->{NAME}|$WILD)| # NAME,NodeType,Axis::Test
210 \!=|<=|\-|>=|\/\/|and|or|mod|div| # multi-char seps
211 =~|\!~| # regexp matching (not in the XPath spec)
212 [,\+=\|<>\/\(\[\]\)]| # single char seps
213 (?<!(\@|\(|\[))\*| # multiply operator rules (see xpath spec)
214 (?<!::)\*|
215 $ # match end of query
216 )
217 \s* # ignore all whitespace
218 /gcxs)
219 {
220 1179 $token = $1;
221 1179 ▶ $expected= ($token=~ m{^[=!]~$}) ? 'RE' : '';
Branch: 1 branch
BranchTrueFalseTotal
$token =~ /^[=!]~$/ ? : 9 1170 1179
222 }
223 else
224 130 { $token=''; last; }
225  
226 1188 ▶ if (length($token))
Branch: 1 branch
BranchTrueFalseTotal
if (length $token) 1059 129 1188
227 {
228 1059 ▶ _debug("TOKEN: $token\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 1059 1059
229 1059 push @tokens, $token;
230 }
231 }
232
233 130 ▶ if (pos($path) < length($path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (pos $path < length $path) 1 129 130
234 1 my $marker = ("." x (pos($path)-1));
235 1 $path = substr($path, 0, pos($path) + 8) . "...";
236 1 $path =~ s/\n/ /g;
237 1 $path =~ s/\t/ /g;
238 1 die "Query:\n",
239 "$path\n",
240 $marker, "^^^\n",
241 "Invalid query somewhere around here (I think)\n";
242 }
243
244 129 return \@tokens;
245 }
246  
247 129 ▶sub _analyze {
Subroutine _analyze: called CC=1 SCAR=0.0
248 129 my $self = shift;
249 129 my $tokens = shift;
250 # lexical analysis
251
252 129 return _expr($self, $tokens);
253 }
254  
255 6073 ▶sub _match {
Subroutine _match: called CC=4 SCAR=13.9
256 6073 my ($self, $tokens, $match, $fatal) = @_;
257
258 6073 $self->{_curr_match} = '';
259 6073 ▶ return 0 unless $self->{_tokpos} < @$tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_tokpos"} < @$tokens 1250 4823 6073
260  
261 4823 local $^W;
262
263 # _debug ("match: $match\n") if( $Tree::XPathEngine::DEBUG);
264
265 4823 ▶ if ($tokens->[$self->{_tokpos}] =~ /^$match$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$self->{'_tokpos'}] =~ /^$match$/) { } 876 3947 4823
266 876 $self->{_curr_match} = $tokens->[$self->{_tokpos}];
267 876 $self->{_tokpos}++;
268 876 return 1;
269 }
270 else {
271 3947 ▶ if ($fatal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fatal) { } 1 3946 3947
272 1 die "Invalid token: ", $tokens->[$self->{_tokpos}], "\n";
273 }
274 else {
275 3946 return 0;
276 }
277 }
278 }
279  
280 301 ▶sub _expr {
Subroutine _expr: called CC=2 SCAR=7.1
281 301 my ($self, $tokens) = @_;
282
283 301 ▶ _debug( "in _exprexpr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 301 301
284
285 301 return _or_expr($self, $tokens);
286 }
287  
288 301 ▶sub _or_expr {
Subroutine _or_expr: called CC=3 SCAR=11.0
289 301 my ($self, $tokens) = @_;
290
291 301 ▶ _debug( "in _or_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 301 301
292
293 301 my $expr = _and_expr($self, $tokens);
294 297 ▶ while (_match($self, $tokens, 'or')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "or")) 1 297 298
295 1 my $or_expr = Tree::XPathEngine::Expr->new($self);
296 1 $or_expr->set_lhs($expr);
297 1 $or_expr->set_op('or');
298  
299 1 my $rhs = _and_expr($self, $tokens);
300  
301 1 $or_expr->set_rhs($rhs);
302 1 $expr = $or_expr;
303 }
304
305 297 return $expr;
306 }
307  
308 302 ▶sub _and_expr {
Subroutine _and_expr: called CC=3 SCAR=11.0
309 302 my ($self, $tokens) = @_;
310
311 302 ▶ _debug( "in _and_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 302 302
312
313 302 my $expr = _match_expr($self, $tokens);
314 298 ▶ while (_match($self, $tokens, 'and')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "and")) 2 298 300
315 2 my $and_expr = Tree::XPathEngine::Expr->new($self);
316 2 $and_expr->set_lhs($expr);
317 2 $and_expr->set_op('and');
318
319 2 my $rhs = _match_expr($self, $tokens);
320
321 2 $and_expr->set_rhs($rhs);
322 2 $expr = $and_expr;
323 }
324
325 298 return $expr;
326 }
327  
328 304 ▶sub _match_expr {
Subroutine _match_expr: called CC=3 SCAR=11.0
329 304 my ($self, $tokens) = @_;
330
331 304 ▶ _debug( "in _match_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 304 304
332
333 304 my $expr = _equality_expr($self, $tokens);
334  
335 300 ▶ while (_match($self, $tokens, '[=!]~')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "[=!]~")) 9 300 309
336 9 my $match_expr = Tree::XPathEngine::Expr->new($self);
337 9 $match_expr->set_lhs($expr);
338 9 $match_expr->set_op($self->{_curr_match});
339
340 9 my $rhs = _equality_expr($self, $tokens);
341
342 9 $match_expr->set_rhs($rhs);
343 9 $expr = $match_expr;
344 }
345
346 300 return $expr;
347 }
348  
349 313 ▶sub _equality_expr {
Subroutine _equality_expr: called CC=3 SCAR=11.0
350 313 my ($self, $tokens) = @_;
351
352 313 ▶ _debug( "in _equality_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 313 313
353
354 313 my $expr = _relational_expr($self, $tokens);
355 309 ▶ while (_match($self, $tokens, '!?=')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "!?=")) 71 309 380
356 71 my $eq_expr = Tree::XPathEngine::Expr->new($self);
357 71 $eq_expr->set_lhs($expr);
358 71 $eq_expr->set_op($self->{_curr_match});
359
360 71 my $rhs = _relational_expr($self, $tokens);
361
362 71 $eq_expr->set_rhs($rhs);
363 71 $expr = $eq_expr;
364 }
365
366 309 return $expr;
367 }
368  
369 384 ▶sub _relational_expr {
Subroutine _relational_expr: called CC=3 SCAR=11.0
370 384 my ($self, $tokens) = @_;
371
372 384 ▶ _debug( "in _relational_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 384 384
373
374 384 my $expr = _additive_expr($self, $tokens);
375 380 ▶ while (_match($self, $tokens, '(<|>|<=|>=)')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "(<|>|<=|>=)")) 18 380 398
376 18 my $rel_expr = Tree::XPathEngine::Expr->new($self);
377 18 $rel_expr->set_lhs($expr);
378 18 $rel_expr->set_op($self->{_curr_match});
379
380 18 my $rhs = _additive_expr($self, $tokens);
381
382 18 $rel_expr->set_rhs($rhs);
383 18 $expr = $rel_expr;
384 }
385
386 380 return $expr;
387 }
388  
389 402 ▶sub _additive_expr {
Subroutine _additive_expr: called CC=3 SCAR=11.0
390 402 my ($self, $tokens) = @_;
391
392 402 ▶ _debug( "in _additive_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 402 402
393
394 402 my $expr = _multiplicative_expr($self, $tokens);
395 398 ▶ while (_match($self, $tokens, '[\\+\\-]')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "[\\+\\-]")) 12 398 410
396 12 my $add_expr = Tree::XPathEngine::Expr->new($self);
397 12 $add_expr->set_lhs($expr);
398 12 $add_expr->set_op($self->{_curr_match});
399
400 12 my $rhs = _multiplicative_expr($self, $tokens);
401
402 12 $add_expr->set_rhs($rhs);
403 12 $expr = $add_expr;
404 }
405
406 398 return $expr;
407 }
408  
409 414 ▶sub _multiplicative_expr {
Subroutine _multiplicative_expr: called CC=3 SCAR=11.0
410 414 my ($self, $tokens) = @_;
411
412 414 ▶ _debug( "in _multiplicative_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 414 414
413
414 414 my $expr = _unary_expr($self, $tokens);
415 410 ▶ while (_match($self, $tokens, '(\\*|div|mod)')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "(\\*|div|mod)")) 4 410 414
416 4 my $mult_expr = Tree::XPathEngine::Expr->new($self);
417 4 $mult_expr->set_lhs($expr);
418 4 $mult_expr->set_op($self->{_curr_match});
419
420 4 my $rhs = _unary_expr($self, $tokens);
421
422 4 $mult_expr->set_rhs($rhs);
423 4 $expr = $mult_expr;
424 }
425
426 410 return $expr;
427 }
428  
429 420 ▶sub _unary_expr {
Subroutine _unary_expr: called CC=3 SCAR=11.0
430 420 my ($self, $tokens) = @_;
431
432 420 ▶ _debug( "in _unary_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 420 420
433
434 420 ▶ if (_match($self, $tokens, '-')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, '-')) { } 2 418 420
435 2 my $expr = Tree::XPathEngine::Expr->new($self);
436 2 $expr->set_lhs(Tree::XPathEngine::Number->new(0));
437 2 $expr->set_op('-');
438 2 $expr->set_rhs(_unary_expr($self, $tokens));
439 2 return $expr;
440 }
441 else {
442 418 return _union_expr($self, $tokens);
443 }
444 }
445  
446 418 ▶sub _union_expr {
Subroutine _union_expr: called CC=3 SCAR=11.0
447 418 my ($self, $tokens) = @_;
448
449 418 ▶ _debug( "in _union_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 418 418
450
451 418 my $expr = _path_expr($self, $tokens);
452 414 ▶ while (_match($self, $tokens, '\\|')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "\\|")) 2 414 416
453 2 my $un_expr = Tree::XPathEngine::Expr->new($self);
454 2 $un_expr->set_lhs($expr);
455 2 $un_expr->set_op('|');
456
457 2 my $rhs = _path_expr($self, $tokens);
458
459 2 $un_expr->set_rhs($rhs);
460 2 $expr = $un_expr;
461 }
462
463 414 return $expr;
464 }
465  
466 420 ▶sub _path_expr {
Subroutine _path_expr: called CC=6 SCAR=21.8
467 420 my ($self, $tokens) = @_;
468  
469 420 ▶ _debug( "in _path_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 420 420
470
471 # _path_expr is _location_path | _filter_expr | _filter_expr '//?' _relative_location_path
472
473 # Since we are being predictive we need to find out which function to call next, then.
474
475 # LocationPath either starts with "/", "//", ".", ".." or a proper Step.
476
477 420 my $expr = Tree::XPathEngine::Expr->new($self);
478
479 420 my $test = $tokens->[$self->{_tokpos}];
480
481 # Test for AbsoluteLocationPath and AbbreviatedRelativeLocationPath
482 420 ▶ if ($test =~ /^(\/\/?|\.\.?)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($test =~ m[^(//?|\.\.?)$]) { } 113 307 420
elsif (_is_step($self, $tokens)) { } 42 265 307
483 # LocationPath
484 113 $expr->set_lhs(_location_path($self, $tokens));
485 }
486 # Test for AxisName::...
487 elsif (_is_step($self, $tokens)) {
488 42 $expr->set_lhs(_location_path($self, $tokens));
489 }
490 else {
491 # Not a LocationPath
492 # Use _filter_expr instead:
493
494 265 $expr = _filter_expr($self, $tokens);
495 264 ▶ if (_match($self, $tokens, '//?')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "//?")) 0 264 264
496 0 my $loc_path = Tree::XPathEngine::LocationPath->new();
497 0 push @$loc_path, $expr;
498 0 ▶ if ($self->{_curr_match} eq '//') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_curr_match"} eq "//") 0 0 0
499 0 push @$loc_path, Tree::XPathEngine::Step->new($self, 'descendant-or-self',
500 Tree::XPathEngine::Step::test_nt_node() );
501 }
502 0 push @$loc_path, _relative_location_path($self, $tokens);
503 0 my $new_expr = Tree::XPathEngine::Expr->new($self);
504 0 $new_expr->set_lhs($loc_path);
505 0 return $new_expr;
506 }
507 }
508
509 416 return $expr;
510 }
511  
512 265 ▶sub _filter_expr {
Subroutine _filter_expr: called CC=3 SCAR=12.3
513 265 my ($self, $tokens) = @_;
514
515 265 ▶ _debug( "in _filter_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 265 265
516
517 265 my $expr = _primary_expr($self, $tokens);
518 264 ▶ while (_match($self, $tokens, '\\[')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "\\[")) 0 264 264
519 # really PredicateExpr...
520 0 $expr->push_predicate(_expr($self, $tokens));
521 0 _match($self, $tokens, '\\]', 1);
522 }
523
524 264 return $expr;
525 }
526  
527 265 ▶sub _primary_expr {
Subroutine _primary_expr: called CC=9 SCAR=22.3
528 265 my ($self, $tokens) = @_;
529  
530 265 ▶ _debug( "in _primary_expr\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 265 265
531
532 265 my $expr = Tree::XPathEngine::Expr->new($self);
533
534 265 ▶ if (_match($self, $tokens, $LITERAL)) {
Branch: 6 branches
BranchTrueFalseTotal
if (_match($self, $tokens, $Tree::XPathEngine::LITERAL)) { } 81 184 265
elsif (_match($self, $tokens, "$Tree::XPathEngine::REGEXP_RE$Tree::XPathEngine::REGEXP_MOD_RE?")) { } 9 175 184
elsif (_match($self, $tokens, $Tree::XPathEngine::NUMBER_RE)) { } 103 72 175
elsif (_match($self, $tokens, '\\(')) { } 25 47 72
elsif (_match($self, $tokens, "\\\$$self->{'NAME'}")) { } 0 47 47
elsif (_match($self, $tokens, $self->{'NAME'})) { } 46 1 47
535 # new Literal with $self->{_curr_match}...
536 81 $self->{_curr_match} =~ m/^(["'])(.*)\1$/;
537 81 $expr->set_lhs(Tree::XPathEngine::Literal->new($2));
538 }
539 elsif (_match($self, $tokens, "$REGEXP_RE$REGEXP_MOD_RE?")) {
540 # new Literal with $self->{_curr_match} turned into a regexp...
541 9 my( $regexp, $mod)= $self->{_curr_match} =~ m{($REGEXP_RE)($REGEXP_MOD_RE?)};
542 9 $regexp=~ s{^m?s*/}{};
543 9 $regexp=~ s{/$}{};
544 0 ▶ if( $mod) { $regexp=~ "(?$mod:$regexp)"; } # move the mods inside the regexp
Branch: 1 branch
BranchTrueFalseTotal
if ($mod) 0 9 9
545 9 $expr->set_lhs(Tree::XPathEngine::Literal->new($regexp));
546 }
547 elsif (_match($self, $tokens, $NUMBER_RE)) {
548 # new Number with $self->{_curr_match}...
549 103 $expr->set_lhs(Tree::XPathEngine::Number->new($self->{_curr_match}));
550 }
551 elsif (_match($self, $tokens, '\\(')) {
552 25 $expr->set_lhs(_expr($self, $tokens));
553 25 _match($self, $tokens, '\\)', 1);
554 }
555 elsif (_match($self, $tokens, "\\\$$self->{NAME}")) {
556 # new Variable with $self->{_curr_match}...
557 0 $self->{_curr_match} =~ /^\$(.*)$/;
558 0 $expr->set_lhs(Tree::XPathEngine::Variable->new($self, $1));
559 }
560 elsif (_match($self, $tokens, $self->{NAME})) {
561 # check match not Node_Type - done in lexer...
562 # new Function
563 46 my $func_name = $self->{_curr_match};
564 46 _match($self, $tokens, '\\(', 1);
565 46 $expr->set_lhs(
566 Tree::XPathEngine::Function->new(
567 $self,
568 $func_name,
569 _arguments($self, $tokens)
570 )
571 );
572 46 _match($self, $tokens, '\\)', 1);
573 }
574 else {
575 1 die "Not a _primary_expr at ", $tokens->[$self->{_tokpos}], "\n";
576 }
577
578 264 return $expr;
579 }
580  
581 46 ▶sub _arguments {
Subroutine _arguments: called CC=4 SCAR=13.9
582 46 my ($self, $tokens) = @_;
583
584 46 ▶ _debug( "in _arguments\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 46 46
585
586 46 my @args;
587
588 46 ▶ if($tokens->[$self->{_tokpos}] eq ')') {
Branch: 1 branch
BranchTrueFalseTotal
if ($$tokens[$self->{"_tokpos"}] eq ")") 13 33 46
589 13 return \@args;
590 }
591
592 33 push @args, _expr($self, $tokens);
593 33 ▶ while (_match($self, $tokens, ',')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, ",")) 19 33 52
594 19 push @args, _expr($self, $tokens);
595 }
596
597 33 return \@args;
598 }
599  
600 155 ▶sub _location_path {
Subroutine _location_path: called CC=8 SCAR=21.0
601 155 my ($self, $tokens) = @_;
602  
603 155 ▶ _debug( "in _location_path\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 155 155
604
605 155 my $loc_path = Tree::XPathEngine::LocationPath->new();
606
607 155 ▶ if (_match($self, $tokens, '/')) {
Branch: 2 branches
BranchTrueFalseTotal
if (_match($self, $tokens, '/')) { } 18 137 155
elsif (_match($self, $tokens, '//')) { } 69 68 137
608 # root
609 18 ▶ _debug("h: Matched root\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 18 18
610 18 push @$loc_path, Tree::XPathEngine::Root->new();
611 18 ▶ if (_is_step($self, $tokens)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_step($self, $tokens)) 18 0 18
612 18 ▶ _debug("Next is step\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 18 18
613 18 push @$loc_path, _relative_location_path($self, $tokens);
614 }
615 }
616 elsif (_match($self, $tokens, '//')) {
617 # root
618 69 push @$loc_path, Tree::XPathEngine::Root->new();
619 69 my $optimised = _optimise_descendant_or_self($self, $tokens);
620 69 ▶ if (!$optimised) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $optimised) { } 62 7 69
621 62 push @$loc_path, Tree::XPathEngine::Step->new($self, 'descendant-or-self',
622 Tree::XPathEngine::Step::test_nt_node);
623 62 push @$loc_path, _relative_location_path($self, $tokens);
624 }
625 else {
626 7 push @$loc_path, $optimised, _relative_location_path($self, $tokens);
627 }
628 }
629 else {
630 68 push @$loc_path, _relative_location_path($self, $tokens);
631 }
632
633 152 return $loc_path;
634 }
635  
636 72 ▶sub _optimise_descendant_or_self {
Subroutine _optimise_descendant_or_self: called CC=7 SCAR=19.6
637 72 my ($self, $tokens) = @_;
638
639 72 ▶ _debug( "in _optimise_descendant_or_self\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 72 72
640
641 72 my $tokpos = $self->{_tokpos};
642
643 # // must be followed by a Step.
644 72 ▶ if ($tokens->[$tokpos+1] && $tokens->[$tokpos+1] eq '[') {
Branch: 2 branches
BranchTrueFalseTotal
if ($$tokens[$tokpos + 1] and $$tokens[$tokpos + 1] eq '[') { } 61 11 72
elsif ($tokens->[$tokpos] =~ /^\.\.?$/) { } 0 11 11
Condition100%3/3
$$tokens[$tokpos + 1] and $$tokens[$tokpos + 1] eq "["
!ll&&!rl&&r
2961
MC/DC100%2/2
$$tokens[$tokpos + 1] and $$tokens[$tokpos + 1] eq "["
$$tokens[$tokpos + 1] $$tokens[$tokpos + 1] eq "["
Truth table100%3/3
A and B
A= $$tokens[$tokpos + 1]B= $$tokens[$tokpos + 1] eq "["
ABresult
0X0
100
111
645 # next token is a predicate
646 61 return;
647 }
648 elsif ($tokens->[$tokpos] =~ /^\.\.?$/) {
649 # abbreviatedStep - can't optimise.
650 0 return;
651 }
652 else {
653 11 ▶ _debug("Trying to optimise //\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 11 11
654 11 my $step = _step($self, $tokens);
655 11 ▶ if ($step->{axis} ne 'child') {
Branch: 1 branch
BranchTrueFalseTotal
if ($step->{"axis"} ne "child") 4 7 11
656 # can't optimise axes other than child for now...
657 4 $self->{_tokpos} = $tokpos;
658 4 return;
659 }
660 7 $step->{axis} = 'descendant';
661 7 $step->{axis_method} = 'axis_descendant';
662 7 $self->{_tokpos}--;
663 7 $tokens->[$self->{_tokpos}] = '.';
664 7 return $step;
665 }
666 }
667  
668 155 ▶sub _relative_location_path {
Subroutine _relative_location_path: called CC=8 SCAR=22.8
669 155 my ($self, $tokens) = @_;
670
671 155 ▶ _debug( "in _relative_location_path\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 155 155
672
673 155 my @steps;
674
675 155 push @steps,_step($self, $tokens);
676 153 ▶ while (_match($self, $tokens, '//?')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "//?")) 45 152 197
677 45 ▶ if ($self->{_curr_match} eq '//') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_curr_match"} eq "//") 3 42 45
678 3 my $optimised = _optimise_descendant_or_self($self, $tokens);
679 3 ▶ if (!$optimised) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $optimised) { } 3 0 3
680 3 push @steps, Tree::XPathEngine::Step->new($self, 'descendant-or-self',
681 Tree::XPathEngine::Step::test_nt_node);
682 }
683 else {
684 0 push @steps, $optimised;
685 }
686 }
687 45 push @steps, _step($self, $tokens);
688 44 ▶ if (@steps > 1 &&
Branch: 1 branch
BranchTrueFalseTotal
if (@steps > 1 and $steps[-1]{"axis"} eq "self" and $steps[-1]{"test"} == 5) 0 44 44
Condition33%2/6
@steps > 1 and $steps[-1]{"axis"} eq "self" and $steps[-1]{"test"} == 5
!ll&&!rl&&r
4400
@steps > 1 and $steps[-1]{"axis"} eq "self"
!ll&&!rl&&r
0440
MC/DC0%0/3
@steps > 1 and $steps[-1]{"axis"} eq "self" and $steps[-1]{"test"} == 5
@steps > 1 $steps[-1]{"axis"} eq "self" $steps[-1]{"test"} == 5
Truth table25%1/4
A and B and C
A= @steps > 1B= $steps[-1]{"axis"} eq "self"C= $steps[-1]{"test"} == 5
ABCresult
0XX0
10X0
1100
1111
689 $steps[-1]->{axis} eq 'self' &&
690 $steps[-1]->{test} == Tree::XPathEngine::Step::test_nt_node) {
691 0 pop @steps;
692 }
693 }
694
695 152 return @steps;
696 }
697  
698 211 ▶sub _step {
Subroutine _step: called CC=20 SCAR=32.9
699 211 my ($self, $tokens) = @_;
700  
701 211 ▶ _debug( "in _step\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 211 211
702
703 211 ▶ if (_match($self, $tokens, '\\.')) {
Branch: 2 branches
BranchTrueFalseTotal
if (_match($self, $tokens, '\\.')) { } 32 179 211
elsif (_match($self, $tokens, '\\.\\.')) { } 3 176 179
704 # self::node()
705 32 return Tree::XPathEngine::Step->new($self, 'self', Tree::XPathEngine::Step::test_nt_node);
706 }
707 elsif (_match($self, $tokens, '\\.\\.')) {
708 # parent::node()
709 3 return Tree::XPathEngine::Step->new($self, 'parent', Tree::XPathEngine::Step::test_nt_node);
710 }
711 else {
712 # AxisSpecifier NodeTest Predicate(s?)
713 176 my $token = $tokens->[$self->{_tokpos}];
714
715 176 ▶ _debug("p: Checking $token\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 176 176
716
717 176 my $step;
718 176 ▶ if ($token =~ /^\@($self->{NAME}|$WILD)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($token =~ /^\@($self->{'NAME'}|$Tree::XPathEngine::WILD)$/) { } 82 94 176
elsif ($token =~ /^$Tree::XPathEngine::WILD$/) { } 15 79 94
elsif ($token =~ /^$self->{'NAME'}$/) { } 66 13 79
elsif ($token eq 'text()') { } 0 13 13
elsif ($token eq 'node()') { } 0 13 13
elsif ($token =~ /^($Tree::XPathEngine::AXIS_NAME)($self->{'NAME'}|$Tree::XPathEngine::WILD|$Tree::XPathEngine::NODE_TYPE)$/) { } 12 1 13
719 82 $self->{_tokpos}++;
720 82 ▶ if ($token eq '@*') {
Branch: 2 branches
BranchTrueFalseTotal
if ($token eq '@*') { } 10 72 82
elsif ($token =~ /^\@($self->{'NAME'})$/) { } 72 0 72
721 10 $step = Tree::XPathEngine::Step->new($self,
722 'attribute',
723 Tree::XPathEngine::Step::test_attr_any,
724 '*');
725 }
726 elsif ($token =~ /^\@($self->{NAME})$/) {
727 72 $step = Tree::XPathEngine::Step->new($self,
728 'attribute',
729 Tree::XPathEngine::Step::test_attr_name,
730 $1);
731 }
732 }
733 elsif ($token =~ /^$WILD$/) { # *
734 15 $self->{_tokpos}++;
735 15 $step = Tree::XPathEngine::Step->new($self, 'child',
736 Tree::XPathEngine::Step::test_any,
737 $token);
738 }
739 elsif ($token =~ /^$self->{NAME}$/) { # name:name
740 66 $self->{_tokpos}++;
741 66 $step = Tree::XPathEngine::Step->new($self, 'child',
742 Tree::XPathEngine::Step::test_name,
743 $token);
744 }
745 elsif ($token eq 'text()') {
746 0 $self->{_tokpos}++;
747 0 $step = Tree::XPathEngine::Step->new($self, 'child',
748 Tree::XPathEngine::Step::test_nt_text);
749 }
750 elsif ($token eq 'node()') {
751 0 $self->{_tokpos}++;
752 0 $step = Tree::XPathEngine::Step->new($self, 'child',
753 Tree::XPathEngine::Step::test_nt_node);
754 }
755 elsif ($token =~ /^($AXIS_NAME)($self->{NAME}|$WILD|$NODE_TYPE)$/) {
756 12 my $axis = substr( $1, 0, -2);
757 12 $self->{_tokpos}++;
758 12 $token = $2;
759 12 ▶ if ($token =~ /^$WILD$/) { # *
Branch: 4 branches
BranchTrueFalseTotal
if ($token =~ /^$Tree::XPathEngine::WILD$/) { } 10 2 12
elsif ($token =~ /^$self->{'NAME'}$/) { } 2 0 2
elsif ($token eq 'text()') { } 0 0 0
elsif ($token eq 'node()') { } 0 0 0
760 10 ▶ $step = Tree::XPathEngine::Step->new($self, $axis,
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'attribute' ? : 0 10 10
761 (($axis eq 'attribute') ?
762 Tree::XPathEngine::Step::test_attr_any
763 :
764 Tree::XPathEngine::Step::test_any),
765 $token);
766 }
767 elsif ($token =~ /^$self->{NAME}$/) { # name:name
768 2 ▶ $step = Tree::XPathEngine::Step->new($self, $axis,
Branch: 1 branch
BranchTrueFalseTotal
$axis eq 'attribute' ? : 0 2 2
769 (($axis eq 'attribute') ?
770 Tree::XPathEngine::Step::test_attr_name
771 :
772 Tree::XPathEngine::Step::test_name),
773 $token);
774 }
775 elsif ($token eq 'text()') {
776 0 $step = Tree::XPathEngine::Step->new($self, $axis,
777 Tree::XPathEngine::Step::test_nt_text);
778 }
779 elsif ($token eq 'node()') {
780 0 $step = Tree::XPathEngine::Step->new($self, $axis,
781 Tree::XPathEngine::Step::test_nt_node);
782 }
783 else {
784 0 die "Shouldn't get here";
785 }
786 }
787 else {
788 1 die "token $token doesn't match format of a 'Step'\n";
789 }
790
791 175 ▶ while (_match($self, $tokens, '\\[')) {
Branch: 1 branch
BranchTrueFalseTotal
if (_match($self, $tokens, "\\[")) 95 173 268
792 95 push @{$step->{predicates}}, _expr($self, $tokens);
793 94 _match($self, $tokens, '\\]', 1);
794 }
795
796 173 return $step;
797 }
798 }
799  
800 325 ▶sub _is_step {
Subroutine _is_step: called CC=11 SCAR=24.6
801 325 my ($self, $tokens) = @_;
802
803 325 my $token = $tokens->[$self->{_tokpos}];
804
805 325 ▶ return unless defined $token;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 325 325
806
807 325 ▶ _debug("p: Checking if '$token' is a step\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 325 325
808
809 325 local $^W=0;
810
811 325 ▶ if( ($token eq 'processing-instruction')
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq 'processing-instruction' or $token =~ /^\@($self->{'NAME'}|$Tree::XPathEngine::WILD)$/ or $token =~ /^($self->{'NAME'}|$Tree::XPathEngine::WILD)$/ and ($$tokens[$self->{'_tokpos'} + 1] || '') ne '(' or $token =~ /^$Tree::XPathEngine::NODE_TYPE$/ or $token =~ /^$Tree::XPathEngine::AXIS_NAME($self->{'NAME'}|$Tree::XPathEngine::WILD|$Tree::XPathEngine::NODE_TYPE)$/) { } 60 265 325
Condition82%14/17
$token eq "processing-instruction" or $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ or $token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ and ($$tokens[$self->{"_tokpos"} + 1] || "") ne "(" or $token =~ /^$Tree::XPathEngine::NODE_TYPE$/ or $token =~ /^$Tree::XPathEngine::AXIS_NAME($self->{"NAME"}|$Tree::XPathEngine::WILD|$Tree::XPathEngine::NODE_TYPE)$/
l!l&&r!l&&!r
600265
$token eq "processing-instruction" or $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ or $token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ and ($$tokens[$self->{"_tokpos"} + 1] || "") ne "(" or $token =~ /^$Tree::XPathEngine::NODE_TYPE$/
l!l&&r!l&&!r
600265
$token eq "processing-instruction" or $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ or $token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ and ($$tokens[$self->{"_tokpos"} + 1] || "") ne "("
l!l&&r!l&&!r
4218265
$token eq "processing-instruction" or $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/
l!l&&r!l&&!r
042283
$token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ and ($$tokens[$self->{"_tokpos"} + 1] || "") ne "("
!ll&&!rl&&r
2194618
$$tokens[$self->{'_tokpos'} + 1] || ''
l!l
631
MC/DC33%2/6
$token eq "processing-instruction" or $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ or $token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ and ($$tokens[$self->{"_tokpos"} + 1] || "") ne "(" or $token =~ /^$Tree::XPathEngine::NODE_TYPE$/ or $token =~ /^$Tree::XPathEngine::AXIS_NAME($self->{"NAME"}|$Tree::XPathEngine::WILD|$Tree::XPathEngine::NODE_TYPE)$/
$token eq "processing-instruction" $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ $token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/ $$tokens[$self->{'_tokpos'} + 1] $token =~ /^$Tree::XPathEngine::NODE_TYPE$/ $token =~ /^$Tree::XPathEngine::AXIS_NAME($self->{"NAME"}|$Tree::XPathEngine::WILD|$Tree::XPathEngine::NODE_TYPE)$/
Truth table33%3/9
A or B or C and D or E or F
A= $token eq "processing-instruction"B= $token =~ /^\@($self->{"NAME"}|$Tree::XPathEngine::WILD)$/C= $token =~ /^($self->{"NAME"}|$Tree::XPathEngine::WILD)$/D= $$tokens[$self->{'_tokpos'} + 1]E= $token =~ /^$Tree::XPathEngine::NODE_TYPE$/F= $token =~ /^$Tree::XPathEngine::AXIS_NAME($self->{"NAME"}|$Tree::XPathEngine::WILD|$Tree::XPathEngine::NODE_TYPE)$/
ABCDEFresult
1XXXXX1
01XXXX1
0011XX1
000X1X1
00101X1
000X011
0010011
000X000
0010000
812 || ($token =~ /^\@($self->{NAME}|$WILD)$/)
813 || ( ($token =~ /^($self->{NAME}|$WILD)$/ )
814 && ( ($tokens->[$self->{_tokpos}+1] || '') ne '(') )
815 || ($token =~ /^$NODE_TYPE$/)
816 || ($token =~ /^$AXIS_NAME($self->{NAME}|$WILD|$NODE_TYPE)$/)
817 )
818 60 { return 1; }
819 else
820 265 ▶ { _debug("p: '$token' not a step\n") if( $Tree::XPathEngine::DEBUG);
Branch: 1 branch
BranchTrueFalseTotal
if $Tree::XPathEngine::DEBUG 0 265 265
821 265 return;
822 }
823 }
824  
825 0 ▶sub _debug {
Subroutine _debug: not called CC=2 SCAR=17.9
826
827 0 my ($pkg, $file, $line, $sub) = caller(1);
828
829 0 $sub =~ s/^$pkg\:://;
830
831 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
832 0 my $x = shift;
833 0 $x =~ s/\bPKG\b/$pkg/g;
834 0 $x =~ s/\bLINE\b/$line/g;
835 0 $x =~ s/\bg\b/$sub/g;
836 0 print STDERR $x;
837 }
838 }
839  
840  
841 __END__
« XPathEngine/Expr.pm ↑ Summary XPathEngine/Step.pm »