XPathEngine/Expr.pm

filter: Statementstmt 77.7% 216 / 278 Branchbran 70.0% 105 / 150 Conditioncond 70.5% 36 / 51 MC/DCmcdc 46.4% 13 / 28 Subroutinesub 80.0% 24 / 30 Podpod 100% 11 / 11 totaltotal 73.9% 405 / 548 CC 112 SCAR 30.2
CC
112
Cov
75%
filter_by_predicate
72.0
_op_equals
32.4
_op_gt
24.4
CRAP 20.4
↑ Summary XPathEngine.pm »
1 # $Id: /tree-xpathengine/trunk/lib/Tree/XPathEngine/Expr.pm 19 2006-02-13T10:40:57.804258Z mrodrigu $
2  
3 package Tree::XPathEngine::Expr;
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 806 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
7 806 my $class = shift;
8 806 my ($pp) = @_;
9 806 bless { predicates => [], pp => $pp }, $class;
10 }
11  
12 0 ▶sub as_string {
Subroutine as_string: not called CC=4 SCAR=30.0
Pod documented
13 0 my $self = shift;
14 0 local $^W; # Use of uninitialized value! grrr
15 0 my $string = "(" . $self->{lhs}->as_string;
16 0 ▶ $string .= " " . $self->{op} . " " if defined $self->{op};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"op"} 0 0 0
17 0 ▶ $string .= $self->{rhs}->as_string if defined $self->{rhs};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"rhs"} 0 0 0
18 0 $string .= ")";
19 0 foreach my $predicate (@{$self->{predicates}}) {
20 0 $string .= "[" . $predicate->as_string . "]";
21 }
22 0 return $string;
23 }
24  
25  
26 537 ▶sub set_lhs {
Subroutine set_lhs: called CC=1 SCAR=0.0
Pod documented
27 537 my $self = shift;
28 537 $self->{lhs} = $_[0];
29 }
30  
31 121 ▶sub set_op {
Subroutine set_op: called CC=1 SCAR=0.0
Pod documented
32 121 my $self = shift;
33 121 $self->{op} = $_[0];
34 }
35  
36 121 ▶sub set_rhs {
Subroutine set_rhs: called CC=1 SCAR=0.0
Pod documented
37 121 my $self = shift;
38 121 $self->{rhs} = $_[0];
39 }
40  
41 0 ▶sub push_predicate {
Subroutine push_predicate: not called CC=2 SCAR=17.9
Pod documented
42 0 my $self = shift;
43
44 die "Only 1 predicate allowed on FilterExpr in W3C XPath 1.0"
45 0 ▶ if @{$self->{predicates}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"predicates"};} 0 0 0
46
47 0 push @{$self->{predicates}}, $_[0];
48 }
49  
50 0 ▶sub get_lhs { $_[0]->{lhs}; }
Subroutine get_lhs: not called CC=1 SCAR=6.9
Pod documented
51 0 ▶sub get_rhs { $_[0]->{rhs}; }
Subroutine get_rhs: not called CC=1 SCAR=6.9
Pod documented
52 0 ▶sub get_op { $_[0]->{op}; }
Subroutine get_op: not called CC=1 SCAR=6.9
Pod documented
53  
54 2399 ▶sub evaluate {
Subroutine evaluate: called CC=6 SCAR=21.0
Pod documented
55 2399 my $self = shift;
56 2399 my $node = shift;
57
58 # If there's an op, result is result of that op.
59 # If no op, just resolve Expr
60
61 # warn "Evaluate Expr: ", $self->as_string, "\n";
62
63 2399 my $results;
64
65 2399 ▶ if ($self->{op}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'op'}) { } 730 1669 2399
66 730 ▶ die ("No RHS of ", $self->as_string) unless $self->{rhs};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"rhs"} 0 730 730
67 730 $results = $self->_op_eval($node);
68 }
69 else {
70 1669 $results = $self->{lhs}->evaluate($node);
71 }
72
73 2393 ▶ if (my @predicates = @{$self->{predicates}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@predicates) = @{$self->{"predicates"};}) 0 2393 2393
74 0 ▶ if (!$results->isa('Tree::XPathEngine::NodeSet')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($results->isa("Tree::XPathEngine::NodeSet")) 0 0 0
75 0 die "Can't have predicates execute on object type: " . ref($results);
76 }
77
78 # filter initial nodeset by each predicate
79 0 foreach my $predicate (@{$self->{predicates}}) {
80 0 $results = $self->filter_by_predicate($results, $predicate);
81 }
82 }
83
84 2393 return $results;
85 }
86  
87 730 ▶sub _op_eval {
Subroutine _op_eval: called CC=18 SCAR=28.9
88 730 my $self = shift;
89 730 my $node = shift;
90
91 730 my $op = $self->{op};
92
93 730 for ($op) {
94 730 ▶ /^or$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^or$/ and do { return _op_or($node, $self->{"lhs"}, $self->{"rhs"}) } 5 725 730
95 5 return _op_or($node, $self->{lhs}, $self->{rhs});
96 };
97 725 ▶ /^and$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^and$/ and do { return _op_and($node, $self->{"lhs"}, $self->{"rhs"}) } 10 715 725
98 10 return _op_and($node, $self->{lhs}, $self->{rhs});
99 };
100 715 ▶ /^=~$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^=~$/ and do { return _op_match($node, $self->{"lhs"}, $self->{"rhs"}) } 104 611 715
101 104 return _op_match($node, $self->{lhs}, $self->{rhs});
102 };
103 611 ▶ /^!~$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^!~$/ and do { return _op_not_match($node, $self->{"lhs"}, $self->{"rhs"}) } 5 606 611
104 5 return _op_not_match($node, $self->{lhs}, $self->{rhs});
105 };
106 606 ▶ /^=$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^=$/ and do { return _op_equals($node, $self->{"lhs"}, $self->{"rhs"}) } 427 179 606
107 427 return _op_equals($node, $self->{lhs}, $self->{rhs});
108 };
109 179 ▶ /^!=$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^!=$/ and do { return _op_nequals($node, $self->{"lhs"}, $self->{"rhs"}) } 18 161 179
110 18 return _op_nequals($node, $self->{lhs}, $self->{rhs});
111 };
112 161 ▶ /^<=$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^<=$/ and do { return _op_le($node, $self->{"lhs"}, $self->{"rhs"}) } 8 153 161
113 8 return _op_le($node, $self->{lhs}, $self->{rhs});
114 };
115 153 ▶ /^>=$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^>=$/ and do { return _op_ge($node, $self->{"lhs"}, $self->{"rhs"}) } 13 140 153
116 13 return _op_ge($node, $self->{lhs}, $self->{rhs});
117 };
118 140 ▶ /^>$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^>$/ and do { return _op_gt($node, $self->{"lhs"}, $self->{"rhs"}) } 48 92 140
119 48 return _op_gt($node, $self->{lhs}, $self->{rhs});
120 };
121 92 ▶ /^<$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^<$/ and do { return _op_lt($node, $self->{"lhs"}, $self->{"rhs"}) } 19 73 92
122 19 return _op_lt($node, $self->{lhs}, $self->{rhs});
123 };
124 73 ▶ /^\+$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^\+$/ and do { return _op_plus($node, $self->{"lhs"}, $self->{"rhs"}) } 25 48 73
125 25 return _op_plus($node, $self->{lhs}, $self->{rhs});
126 };
127 48 ▶ /^-$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^-$/ and do { return _op_minus($node, $self->{"lhs"}, $self->{"rhs"}) } 23 25 48
128 23 return _op_minus($node, $self->{lhs}, $self->{rhs});
129 };
130 25 ▶ /^div$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^div$/ and do { return _op_div($node, $self->{"lhs"}, $self->{"rhs"}) } 6 19 25
131 6 return _op_div($node, $self->{lhs}, $self->{rhs});
132 };
133 19 ▶ /^mod$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^mod$/ and do { return _op_mod($node, $self->{"lhs"}, $self->{"rhs"}) } 6 13 19
134 6 return _op_mod($node, $self->{lhs}, $self->{rhs});
135 };
136 13 ▶ /^\*$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^\*$/ and do { return _op_mult($node, $self->{"lhs"}, $self->{"rhs"}) } 11 2 13
137 11 return _op_mult($node, $self->{lhs}, $self->{rhs});
138 };
139 2 ▶ /^\|$/ && do {
Branch: 1 branch
BranchTrueFalseTotal
/^\|$/ and do { return _op_union($node, $self->{"lhs"}, $self->{"rhs"}) } 2 0 2
140 2 return _op_union($node, $self->{lhs}, $self->{rhs});
141 };
142
143 0 die "No such operator, or operator unimplemented in ", $self->as_string, "\n";
144 }
145 }
146  
147 # Operators
148  
149 6 ▶use Tree::XPathEngine::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151 5 ▶sub _op_or {
Subroutine _op_or: called CC=2 SCAR=6.9
152 5 my ($node, $lhs, $rhs) = @_;
153 5 ▶ if($lhs->evaluate($node)->xpath_to_boolean->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhs->evaluate($node)->xpath_to_boolean->value) { } 1 4 5
154 1 return Tree::XPathEngine::Boolean->_true;
155 }
156 else {
157 4 return $rhs->evaluate($node)->xpath_to_boolean;
158 }
159 }
160  
161 10 ▶sub _op_and {
Subroutine _op_and: called CC=2 SCAR=6.9
162 10 my ($node, $lhs, $rhs) = @_;
163 10 ▶ if( ! $lhs->evaluate($node)->xpath_to_boolean->value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $lhs->evaluate($node)->xpath_to_boolean->value) { } 8 2 10
164 8 return Tree::XPathEngine::Boolean->_false;
165 }
166 else {
167 2 return $rhs->evaluate($node)->xpath_to_boolean;
168 }
169 }
170  
171 445 ▶sub _op_equals {
Subroutine _op_equals: called CC=26 SCAR=34.8
172 445 my ($node, $lhs, $rhs) = @_;
173  
174 445 my $lh_results = $lhs->evaluate($node);
175 444 my $rh_results = $rhs->evaluate($node);
176
177 444 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet') &&
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet') and $rh_results->isa('Tree::XPathEngine::NodeSet')) { } 10 434 444
elsif ($lh_results->isa('Tree::XPathEngine::NodeSet') || $rh_results->isa('Tree::XPathEngine::NodeSet') and not $lh_results->isa('Tree::XPathEngine::NodeSet') && $rh_results->isa('Tree::XPathEngine::NodeSet')) { } 364 70 434
Condition100%3/3
$lh_results->isa("Tree::XPathEngine::NodeSet") and $rh_results->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
7036410
MC/DC100%2/2
$lh_results->isa("Tree::XPathEngine::NodeSet") and $rh_results->isa("Tree::XPathEngine::NodeSet")
$lh_results->isa("Tree::XPathEngine::NodeSet") $rh_results->isa("Tree::XPathEngine::NodeSet")
Truth table100%3/3
A and B
A= $lh_results->isa("Tree::XPathEngine::NodeSet")B= $rh_results->isa("Tree::XPathEngine::NodeSet")
ABresult
0X0
100
111
178 $rh_results->isa('Tree::XPathEngine::NodeSet')) {
179 # _true if and only if there is a node in the
180 # first set and a node in the second set such
181 # that the result of performing the comparison
182 # on the string-values of the two nodes is true.
183 10 foreach my $lhnode ($lh_results->get_nodelist) {
184 30 foreach my $rhnode ($rh_results->get_nodelist) {
185 30 ▶ if ($lhnode->xpath_string_value eq $rhnode->xpath_string_value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhnode->xpath_string_value eq $rhnode->xpath_string_value) 10 20 30
186 10 return Tree::XPathEngine::Boolean->_true;
187 }
188 }
189 }
190 0 return Tree::XPathEngine::Boolean->_false;
191 }
192 ▶ elsif (($lh_results->isa('Tree::XPathEngine::NodeSet') ||
Condition55%5/9
$lh_results->isa("Tree::XPathEngine::NodeSet") || $rh_results->isa("Tree::XPathEngine::NodeSet") and not $lh_results->isa("Tree::XPathEngine::NodeSet") && $rh_results->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
700364
$lh_results->isa("Tree::XPathEngine::NodeSet") or $rh_results->isa("Tree::XPathEngine::NodeSet")
l!l&&r!l&&!r
364070
$lh_results->isa('Tree::XPathEngine::NodeSet') && $rh_results->isa('Tree::XPathEngine::NodeSet')
!ll&&!rl&&r
03640
MC/DC25%1/4
$lh_results->isa("Tree::XPathEngine::NodeSet") || $rh_results->isa("Tree::XPathEngine::NodeSet") and not $lh_results->isa("Tree::XPathEngine::NodeSet") && $rh_results->isa("Tree::XPathEngine::NodeSet")
$lh_results->isa("Tree::XPathEngine::NodeSet") $rh_results->isa("Tree::XPathEngine::NodeSet") $lh_results->isa('Tree::XPathEngine::NodeSet') $rh_results->isa('Tree::XPathEngine::NodeSet')
Truth table28%2/7
A or B and not(C && D)
A= $lh_results->isa("Tree::XPathEngine::NodeSet")B= $rh_results->isa("Tree::XPathEngine::NodeSet")C= $lh_results->isa('Tree::XPathEngine::NodeSet')D= $rh_results->isa('Tree::XPathEngine::NodeSet')
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
193 $rh_results->isa('Tree::XPathEngine::NodeSet')) &&
194 (!$lh_results->isa('Tree::XPathEngine::NodeSet') ||
195 !$rh_results->isa('Tree::XPathEngine::NodeSet'))) {
196 # (that says: one is a nodeset, and one is not a nodeset)
197
198 364 my ($nodeset, $other);
199 364 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet')) { } 364 0 364
200 364 $nodeset = $lh_results;
201 364 $other = $rh_results;
202 }
203 else {
204 0 $nodeset = $rh_results;
205 0 $other = $lh_results;
206 }
207
208 # _true if and only if there is a node in the
209 # nodeset such that the result of performing
210 # the comparison on <type>(string_value($node))
211 # is true.
212 364 ▶ if ($other->isa('Tree::XPathEngine::Number')) {
Branch: 3 branches
BranchTrueFalseTotal
if ($other->isa('Tree::XPathEngine::Number')) { } 22 342 364
elsif ($other->isa('Tree::XPathEngine::Literal')) { } 342 0 342
elsif ($other->isa('Tree::XPathEngine::Boolean')) { } 0 0 0
213 22 foreach my $node ($nodeset->get_nodelist) {
214 35 local $^W; # argument isn't numeric
215 35 ▶ if ($node->xpath_string_value == $other->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->xpath_string_value == $other->value) 8 27 35
216 8 return Tree::XPathEngine::Boolean->_true;
217 }
218 }
219 }
220 elsif ($other->isa('Tree::XPathEngine::Literal')) {
221 342 foreach my $node ($nodeset->get_nodelist) {
222 474 ▶ if ($node->xpath_string_value eq $other->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->xpath_string_value eq $other->value) 72 402 474
223 72 return Tree::XPathEngine::Boolean->_true;
224 }
225 }
226 }
227 elsif ($other->isa('Tree::XPathEngine::Boolean')) {
228 0 ▶ if ($nodeset->xpath_to_boolean->value == $other->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nodeset->xpath_to_boolean->value == $other->value) 0 0 0
229 0 return Tree::XPathEngine::Boolean->_true;
230 }
231 }
232  
233 284 return Tree::XPathEngine::Boolean->_false;
234 }
235 else { # Neither is a nodeset
236 70 ▶ if ($lh_results->isa('Tree::XPathEngine::Boolean') ||
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::Boolean') or $rh_results->isa('Tree::XPathEngine::Boolean')) { } 6 64 70
elsif ($lh_results->isa('Tree::XPathEngine::Number') or $rh_results->isa('Tree::XPathEngine::Number')) { } 42 22 64
Condition100%3/3
$lh_results->isa("Tree::XPathEngine::Boolean") or $rh_results->isa("Tree::XPathEngine::Boolean")
l!l&&r!l&&!r
4264
MC/DC100%2/2
$lh_results->isa("Tree::XPathEngine::Boolean") or $rh_results->isa("Tree::XPathEngine::Boolean")
$lh_results->isa("Tree::XPathEngine::Boolean") $rh_results->isa("Tree::XPathEngine::Boolean")
Truth table100%3/3
A or B
A= $lh_results->isa("Tree::XPathEngine::Boolean")B= $rh_results->isa("Tree::XPathEngine::Boolean")
ABresult
1X1
011
000
237 $rh_results->isa('Tree::XPathEngine::Boolean')) {
238 # if either is a boolean
239 6 ▶ if ($lh_results->xpath_to_boolean->value == $rh_results->xpath_to_boolean->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_boolean->value == $rh_results->xpath_to_boolean->value) 6 0 6
240 6 return Tree::XPathEngine::Boolean->_true;
241 }
242 0 return Tree::XPathEngine::Boolean->_false;
243 }
244 ▶ elsif ($lh_results->isa('Tree::XPathEngine::Number') ||
Condition66%2/3
$lh_results->isa("Tree::XPathEngine::Number") or $rh_results->isa("Tree::XPathEngine::Number")
l!l&&r!l&&!r
42022
MC/DC50%1/2
$lh_results->isa("Tree::XPathEngine::Number") or $rh_results->isa("Tree::XPathEngine::Number")
$lh_results->isa("Tree::XPathEngine::Number") $rh_results->isa("Tree::XPathEngine::Number")
Truth table66%2/3
A or B
A= $lh_results->isa("Tree::XPathEngine::Number")B= $rh_results->isa("Tree::XPathEngine::Number")
ABresult
1X1
011
000
245 $rh_results->isa('Tree::XPathEngine::Number')) {
246 # if either is a number
247 42 local $^W; # 'number' might result in undef
248 42 ▶ if ($lh_results->xpath_to_number->value == $rh_results->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_number->value == $rh_results->xpath_to_number->value) 29 13 42
249 29 return Tree::XPathEngine::Boolean->_true;
250 }
251 13 return Tree::XPathEngine::Boolean->_false;
252 }
253 else {
254 22 ▶ if ($lh_results->xpath_to_literal->value eq $rh_results->xpath_to_literal->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_literal->value eq $rh_results->xpath_to_literal->value) 2 20 22
255 2 return Tree::XPathEngine::Boolean->_true;
256 }
257 20 return Tree::XPathEngine::Boolean->_false;
258 }
259 }
260 }
261  
262 sub _op_match
263 104 ▶ { my ($node, $lhs, $rhs) = @_;
Subroutine _op_match: called CC=5 SCAR=16.1
264  
265 104 my $lh_results = $lhs->evaluate($node);
266 104 my $rh_results = $rhs->evaluate($node);
267 104 my $rh_value = $rh_results->xpath_string_value;
268  
269 104 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet') )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet')) { } 24 80 104
270 24 { foreach my $lhnode ($lh_results->get_nodelist)
271 24 ▶ { if ($lhnode->xpath_string_value=~ m/$rh_value/) # / is important here, regexp is / delimited
Branch: 1 branch
BranchTrueFalseTotal
if ($lhnode->xpath_string_value =~ /$rh_value/) 13 11 24
272 13 { return Tree::XPathEngine::Boolean->_true; }
273 }
274 11 return Tree::XPathEngine::Boolean->_false;
275 }
276 else
277 80 ▶ { return $lh_results->xpath_string_value =~ m!$rh_value! ?
Branch: 1 branch
BranchTrueFalseTotal
$lh_results->xpath_string_value =~ /$rh_value/ ? : 6 74 80
278 Tree::XPathEngine::Boolean->_true : Tree::XPathEngine::Boolean->_false;
279 }
280 }
281
282 sub _op_not_match
283 5 ▶ { my ($node, $lhs, $rhs) = @_;
Subroutine _op_not_match: called CC=5 SCAR=17.5
284  
285 5 my $lh_results = $lhs->evaluate($node);
286 5 my $rh_results = $rhs->evaluate($node);
287 5 my $rh_value = $rh_results->xpath_string_value;
288
289 5 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet') )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet')) { } 5 0 5
290 5 { foreach my $lhnode ($lh_results->get_nodelist)
291 10 ▶ { if ($lhnode->xpath_string_value!~ m!$rh_value!)
Branch: 1 branch
BranchTrueFalseTotal
unless ($lhnode->xpath_string_value =~ /$rh_value/) 5 5 10
292 5 { return Tree::XPathEngine::Boolean->_true; }
293 }
294 0 return Tree::XPathEngine::Boolean->_false;
295 }
296 else
297 0 ▶ { return $lh_results->xpath_string_value !~ m!$rh_value! ?
Branch: 1 branch
BranchTrueFalseTotal
!($lh_results->xpath_string_value =~ /$rh_value/) ? : 0 0 0
298 Tree::XPathEngine::Boolean->_true : Tree::XPathEngine::Boolean->_false;
299 }
300 }
301  
302 18 ▶sub _op_nequals {
Subroutine _op_nequals: called CC=2 SCAR=6.9
303 18 my ($node, $lhs, $rhs) = @_;
304 18 ▶ if (_op_equals($node, $lhs, $rhs)->value) {
Branch: 1 branch
BranchTrueFalseTotal
if (_op_equals($node, $lhs, $rhs)->value) 13 5 18
305 13 return Tree::XPathEngine::Boolean->_false;
306 }
307 5 return Tree::XPathEngine::Boolean->_true;
308 }
309  
310 8 ▶sub _op_le {
Subroutine _op_le: called CC=1 SCAR=0.0
311 8 my ($node, $lhs, $rhs) = @_;
312 8 _op_ge($node, $rhs, $lhs);
313 }
314  
315 21 ▶sub _op_ge {
Subroutine _op_ge: called CC=19 SCAR=30.5
316 21 my ($node, $lhs, $rhs) = @_;
317  
318 21 my $lh_results = $lhs->evaluate($node);
319 21 my $rh_results = $rhs->evaluate($node);
320
321 21 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet') &&
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet') and $rh_results->isa('Tree::XPathEngine::NodeSet')) { } 5 16 21
elsif ($lh_results->isa('Tree::XPathEngine::NodeSet') || $rh_results->isa('Tree::XPathEngine::NodeSet') and not $lh_results->isa('Tree::XPathEngine::NodeSet') && $rh_results->isa('Tree::XPathEngine::NodeSet')) { } 12 4 16
Condition100%3/3
$lh_results->isa("Tree::XPathEngine::NodeSet") and $rh_results->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
1065
MC/DC100%2/2
$lh_results->isa("Tree::XPathEngine::NodeSet") and $rh_results->isa("Tree::XPathEngine::NodeSet")
$lh_results->isa("Tree::XPathEngine::NodeSet") $rh_results->isa("Tree::XPathEngine::NodeSet")
Truth table100%3/3
A and B
A= $lh_results->isa("Tree::XPathEngine::NodeSet")B= $rh_results->isa("Tree::XPathEngine::NodeSet")
ABresult
0X0
100
111
322 $rh_results->isa('Tree::XPathEngine::NodeSet')) {
323  
324 5 foreach my $lhnode ($lh_results->get_nodelist) {
325 5 foreach my $rhnode ($rh_results->get_nodelist) {
326 5 my $lhNum = Tree::XPathEngine::Number->new($lhnode->xpath_string_value);
327 5 my $rhNum = Tree::XPathEngine::Number->new($rhnode->xpath_string_value);
328 5 local $^W; # Use of uninitialized value!
329 5 ▶ if ($lhNum->value >= $rhNum->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhNum->value >= $rhNum->value) 5 0 5
330 5 return Tree::XPathEngine::Boolean->_true;
331 }
332 }
333 }
334 0 return Tree::XPathEngine::Boolean->_false;
335 }
336 ▶ elsif (($lh_results->isa('Tree::XPathEngine::NodeSet') ||
Condition77%7/9
$lh_results->isa("Tree::XPathEngine::NodeSet") || $rh_results->isa("Tree::XPathEngine::NodeSet") and not $lh_results->isa("Tree::XPathEngine::NodeSet") && $rh_results->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
4012
$lh_results->isa("Tree::XPathEngine::NodeSet") or $rh_results->isa("Tree::XPathEngine::NodeSet")
l!l&&r!l&&!r
664
$lh_results->isa('Tree::XPathEngine::NodeSet') && $rh_results->isa('Tree::XPathEngine::NodeSet')
!ll&&!rl&&r
660
MC/DC50%2/4
$lh_results->isa("Tree::XPathEngine::NodeSet") || $rh_results->isa("Tree::XPathEngine::NodeSet") and not $lh_results->isa("Tree::XPathEngine::NodeSet") && $rh_results->isa("Tree::XPathEngine::NodeSet")
$lh_results->isa("Tree::XPathEngine::NodeSet") $rh_results->isa("Tree::XPathEngine::NodeSet") $lh_results->isa('Tree::XPathEngine::NodeSet') $rh_results->isa('Tree::XPathEngine::NodeSet')
Truth table42%3/7
A or B and not(C && D)
A= $lh_results->isa("Tree::XPathEngine::NodeSet")B= $rh_results->isa("Tree::XPathEngine::NodeSet")C= $lh_results->isa('Tree::XPathEngine::NodeSet')D= $rh_results->isa('Tree::XPathEngine::NodeSet')
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
337 $rh_results->isa('Tree::XPathEngine::NodeSet')) &&
338 (!$lh_results->isa('Tree::XPathEngine::NodeSet') ||
339 !$rh_results->isa('Tree::XPathEngine::NodeSet'))) {
340 # (that says: one is a nodeset, and one is not a nodeset)
341  
342 12 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet')) { } 6 6 12
343 6 foreach my $node ($lh_results->get_nodelist) {
344 6 local $^W; # Use of uninitialized value!
345 6 ▶ if ($node->xpath_to_number->value >= $rh_results->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->xpath_to_number->value >= $rh_results->xpath_to_number->value) 4 2 6
346 4 return Tree::XPathEngine::Boolean->_true;
347 }
348 }
349 }
350 else {
351 6 foreach my $node ($rh_results->get_nodelist) {
352 6 local $^W; # Use of uninitialized value!
353 6 ▶ if ( $lh_results->xpath_to_number->value >= $node->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_number->value >= $node->xpath_to_number->value) 3 3 6
354 3 return Tree::XPathEngine::Boolean->_true;
355 }
356 }
357 }
358 5 return Tree::XPathEngine::Boolean->_false;
359 }
360 else { # Neither is a nodeset
361 4 ▶ if ($lh_results->isa('Tree::XPathEngine::Boolean') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::Boolean') or $rh_results->isa('Tree::XPathEngine::Boolean')) { } 4 0 4
Condition33%1/3
$lh_results->isa("Tree::XPathEngine::Boolean") or $rh_results->isa("Tree::XPathEngine::Boolean")
l!l&&r!l&&!r
400
MC/DC0%0/2
$lh_results->isa("Tree::XPathEngine::Boolean") or $rh_results->isa("Tree::XPathEngine::Boolean")
$lh_results->isa("Tree::XPathEngine::Boolean") $rh_results->isa("Tree::XPathEngine::Boolean")
Truth table33%1/3
A or B
A= $lh_results->isa("Tree::XPathEngine::Boolean")B= $rh_results->isa("Tree::XPathEngine::Boolean")
ABresult
1X1
011
000
362 $rh_results->isa('Tree::XPathEngine::Boolean')) {
363 # if either is a boolean
364 4 ▶ if ($lh_results->xpath_to_boolean->xpath_to_number->value
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_boolean->xpath_to_number->value >= $rh_results->xpath_to_boolean->xpath_to_number->value) 2 2 4
365 >= $rh_results->xpath_to_boolean->xpath_to_number->value) {
366 2 return Tree::XPathEngine::Boolean->_true;
367 }
368 }
369 else {
370 0 ▶ if ($lh_results->xpath_to_number->value >= $rh_results->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_number->value >= $rh_results->xpath_to_number->value) 0 0 0
371 0 return Tree::XPathEngine::Boolean->_true;
372 }
373 }
374 2 return Tree::XPathEngine::Boolean->_false;
375 }
376 }
377  
378 67 ▶sub _op_gt {
Subroutine _op_gt: called CC=19 SCAR=31.9
379 67 my ($node, $lhs, $rhs) = @_;
380  
381 67 my $lh_results = $lhs->evaluate($node);
382 67 my $rh_results = $rhs->evaluate($node);
383
384 67 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet') &&
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet') and $rh_results->isa('Tree::XPathEngine::NodeSet')) { } 0 67 67
elsif ($lh_results->isa('Tree::XPathEngine::NodeSet') || $rh_results->isa('Tree::XPathEngine::NodeSet') and not $lh_results->isa('Tree::XPathEngine::NodeSet') && $rh_results->isa('Tree::XPathEngine::NodeSet')) { } 33 34 67
Condition66%2/3
$lh_results->isa("Tree::XPathEngine::NodeSet") and $rh_results->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
45220
MC/DC0%0/2
$lh_results->isa("Tree::XPathEngine::NodeSet") and $rh_results->isa("Tree::XPathEngine::NodeSet")
$lh_results->isa("Tree::XPathEngine::NodeSet") $rh_results->isa("Tree::XPathEngine::NodeSet")
Truth table66%2/3
A and B
A= $lh_results->isa("Tree::XPathEngine::NodeSet")B= $rh_results->isa("Tree::XPathEngine::NodeSet")
ABresult
0X0
100
111
385 $rh_results->isa('Tree::XPathEngine::NodeSet')) {
386  
387 0 foreach my $lhnode ($lh_results->get_nodelist) {
388 0 foreach my $rhnode ($rh_results->get_nodelist) {
389 0 my $lhNum = Tree::XPathEngine::Number->new($lhnode->xpath_string_value);
390 0 my $rhNum = Tree::XPathEngine::Number->new($rhnode->xpath_string_value);
391 0 local $^W; # Use of uninitialized value!
392 0 ▶ if ($lhNum->value > $rhNum->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lhNum->value > $rhNum->value) 0 0 0
393 0 return Tree::XPathEngine::Boolean->_true;
394 }
395 }
396 }
397 0 return Tree::XPathEngine::Boolean->_false;
398 }
399 ▶ elsif (($lh_results->isa('Tree::XPathEngine::NodeSet') ||
Condition77%7/9
$lh_results->isa("Tree::XPathEngine::NodeSet") || $rh_results->isa("Tree::XPathEngine::NodeSet") and not $lh_results->isa("Tree::XPathEngine::NodeSet") && $rh_results->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
34033
$lh_results->isa("Tree::XPathEngine::NodeSet") or $rh_results->isa("Tree::XPathEngine::NodeSet")
l!l&&r!l&&!r
221134
$lh_results->isa('Tree::XPathEngine::NodeSet') && $rh_results->isa('Tree::XPathEngine::NodeSet')
!ll&&!rl&&r
11220
MC/DC50%2/4
$lh_results->isa("Tree::XPathEngine::NodeSet") || $rh_results->isa("Tree::XPathEngine::NodeSet") and not $lh_results->isa("Tree::XPathEngine::NodeSet") && $rh_results->isa("Tree::XPathEngine::NodeSet")
$lh_results->isa("Tree::XPathEngine::NodeSet") $rh_results->isa("Tree::XPathEngine::NodeSet") $lh_results->isa('Tree::XPathEngine::NodeSet') $rh_results->isa('Tree::XPathEngine::NodeSet')
Truth table42%3/7
A or B and not(C && D)
A= $lh_results->isa("Tree::XPathEngine::NodeSet")B= $rh_results->isa("Tree::XPathEngine::NodeSet")C= $lh_results->isa('Tree::XPathEngine::NodeSet')D= $rh_results->isa('Tree::XPathEngine::NodeSet')
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
400 $rh_results->isa('Tree::XPathEngine::NodeSet')) &&
401 (!$lh_results->isa('Tree::XPathEngine::NodeSet') ||
402 !$rh_results->isa('Tree::XPathEngine::NodeSet'))) {
403 # (that says: one is a nodeset, and one is not a nodeset)
404  
405 33 ▶ if ($lh_results->isa('Tree::XPathEngine::NodeSet')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::NodeSet')) { } 22 11 33
406 22 foreach my $node ($lh_results->get_nodelist) {
407 22 local $^W; # Use of uninitialized value!
408 22 ▶ if ($node->xpath_to_number->value > $rh_results->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->xpath_to_number->value > $rh_results->xpath_to_number->value) 12 10 22
409 12 return Tree::XPathEngine::Boolean->_true;
410 }
411 }
412 }
413 else {
414 11 foreach my $node ($rh_results->get_nodelist) {
415 16 local $^W; # Use of uninitialized value!
416 16 ▶ if ( $lh_results->xpath_to_number->value > $node->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_number->value > $node->xpath_to_number->value) 7 9 16
417 7 return Tree::XPathEngine::Boolean->_true;
418 }
419 }
420 }
421 14 return Tree::XPathEngine::Boolean->_false;
422 }
423 else { # Neither is a nodeset
424 34 ▶ if ($lh_results->isa('Tree::XPathEngine::Boolean') ||
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('Tree::XPathEngine::Boolean') or $rh_results->isa('Tree::XPathEngine::Boolean')) { } 4 30 34
Condition66%2/3
$lh_results->isa("Tree::XPathEngine::Boolean") or $rh_results->isa("Tree::XPathEngine::Boolean")
l!l&&r!l&&!r
4030
MC/DC50%1/2
$lh_results->isa("Tree::XPathEngine::Boolean") or $rh_results->isa("Tree::XPathEngine::Boolean")
$lh_results->isa("Tree::XPathEngine::Boolean") $rh_results->isa("Tree::XPathEngine::Boolean")
Truth table66%2/3
A or B
A= $lh_results->isa("Tree::XPathEngine::Boolean")B= $rh_results->isa("Tree::XPathEngine::Boolean")
ABresult
1X1
011
000
425 $rh_results->isa('Tree::XPathEngine::Boolean')) {
426 # if either is a boolean
427 4 ▶ if ($lh_results->xpath_to_boolean->value > $rh_results->xpath_to_boolean->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_boolean->value > $rh_results->xpath_to_boolean->value) 2 2 4
428 2 return Tree::XPathEngine::Boolean->_true;
429 }
430 }
431 else {
432 30 ▶ if ($lh_results->xpath_to_number->value > $rh_results->xpath_to_number->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->xpath_to_number->value > $rh_results->xpath_to_number->value) 13 17 30
433 13 return Tree::XPathEngine::Boolean->_true;
434 }
435 }
436 19 return Tree::XPathEngine::Boolean->_false;
437 }
438 }
439  
440 19 ▶sub _op_lt {
Subroutine _op_lt: called CC=1 SCAR=0.0
441 19 my ($node, $lhs, $rhs) = @_;
442 19 _op_gt($node, $rhs, $lhs);
443 }
444  
445 25 ▶sub _op_plus {
Subroutine _op_plus: called CC=1 SCAR=0.0
446 25 my ($node, $lhs, $rhs) = @_;
447 25 my $lh_results = $lhs->evaluate($node);
448 25 my $rh_results = $rhs->evaluate($node);
449
450 25 local $^W;
451 25 my $result =
452 $lh_results->xpath_to_number->value
453 +
454 $rh_results->xpath_to_number->value
455 ;
456 25 return Tree::XPathEngine::Number->new($result);
457 }
458  
459 23 ▶sub _op_minus {
Subroutine _op_minus: called CC=1 SCAR=0.0
460 23 my ($node, $lhs, $rhs) = @_;
461 23 my $lh_results = $lhs->evaluate($node);
462 23 my $rh_results = $rhs->evaluate($node);
463
464 23 local $^W;
465 23 my $result =
466 $lh_results->xpath_to_number->value
467 -
468 $rh_results->xpath_to_number->value
469 ;
470 23 return Tree::XPathEngine::Number->new($result);
471 }
472  
473 6 ▶sub _op_div {
Subroutine _op_div: called CC=2 SCAR=7.1
474 6 my ($node, $lhs, $rhs) = @_;
475 6 my $lh_results = $lhs->evaluate($node);
476 6 my $rh_results = $rhs->evaluate($node);
477  
478 6 local $^W;
479 6 my $result = eval {
480 6 $lh_results->xpath_to_number->value
481 /
482 $rh_results->xpath_to_number->value
483 ;
484 };
485 6 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 6 6
486 # assume divide by zero
487 # This is probably a terrible way to handle this!
488 # Ah well... who wants to live forever...
489 0 return Tree::XPathEngine::Literal->new('Infinity');
490 }
491 6 return Tree::XPathEngine::Number->new($result);
492 }
493  
494 6 ▶sub _op_mod {
Subroutine _op_mod: called CC=1 SCAR=0.0
495 6 my ($node, $lhs, $rhs) = @_;
496 6 my $lh_results = $lhs->evaluate($node);
497 6 my $rh_results = $rhs->evaluate($node);
498
499 6 local $^W;
500 6 my $result =
501 $lh_results->xpath_to_number->value
502 %
503 $rh_results->xpath_to_number->value
504 ;
505 6 return Tree::XPathEngine::Number->new($result);
506 }
507  
508 11 ▶sub _op_mult {
Subroutine _op_mult: called CC=1 SCAR=0.0
509 11 my ($node, $lhs, $rhs) = @_;
510 11 my $lh_results = $lhs->evaluate($node);
511 11 my $rh_results = $rhs->evaluate($node);
512
513 11 local $^W;
514 11 my $result =
515 $lh_results->xpath_to_number->value
516 *
517 $rh_results->xpath_to_number->value
518 ;
519 11 return Tree::XPathEngine::Number->new($result);
520 }
521  
522 2 ▶sub _op_union {
Subroutine _op_union: called CC=6 SCAR=18.8
523 2 my ($node, $lhs, $rhs) = @_;
524 2 my $lh_result = $lhs->evaluate($node);
525 2 my $rh_result = $rhs->evaluate($node);
526
527 2 ▶ if ($lh_result->isa('Tree::XPathEngine::NodeSet') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_result->isa("Tree::XPathEngine::NodeSet") and $rh_result->isa("Tree::XPathEngine::NodeSet")) 2 0 2
Condition33%1/3
$lh_result->isa("Tree::XPathEngine::NodeSet") and $rh_result->isa("Tree::XPathEngine::NodeSet")
!ll&&!rl&&r
002
MC/DC0%0/2
$lh_result->isa("Tree::XPathEngine::NodeSet") and $rh_result->isa("Tree::XPathEngine::NodeSet")
$lh_result->isa("Tree::XPathEngine::NodeSet") $rh_result->isa("Tree::XPathEngine::NodeSet")
Truth table33%1/3
A and B
A= $lh_result->isa("Tree::XPathEngine::NodeSet")B= $rh_result->isa("Tree::XPathEngine::NodeSet")
ABresult
0X0
100
111
528 $rh_result->isa('Tree::XPathEngine::NodeSet')) {
529 2 my %found;
530 2 my $results = Tree::XPathEngine::NodeSet->new;
531 2 foreach my $lhnode ($lh_result->get_nodelist) {
532 3 $found{"$lhnode"}++;
533 3 $results->push($lhnode);
534 }
535 2 foreach my $rhnode ($rh_result->get_nodelist) {
536 $results->push($rhnode)
537 2 ▶ unless exists $found{"$rhnode"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $found{"$rhnode"} 2 0 2
538 }
539 2 return $results->sort->remove_duplicates;
540 }
541 0 die "Both sides of a union must be Node Sets\n";
542 }
543  
544 0 ▶sub filter_by_predicate {
Subroutine filter_by_predicate: not called CC=8 SCAR=42.8
Pod documented
545 0 my $self = shift;
546 0 my ($nodeset, $predicate) = @_;
547
548 # See spec section 2.4, paragraphs 2 & 3:
549 # For each node in the node-set to be filtered, the predicate Expr
550 # is evaluated with that node as the context node, with the number
551 # of nodes in the node set as the context size, and with the
552 # proximity position of the node in the node set with respect to
553 # the axis as the context position.
554
555 0 ▶ if (!ref($nodeset)) { # use ref because nodeset has a bool context
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $nodeset) 0 0 0
556 0 die "No nodeset!!!";
557 }
558
559 # warn "Filter by predicate: $predicate\n";
560
561 0 my $newset = Tree::XPathEngine::NodeSet->new();
562
563 0 ▶ for(my $i = 1; $i <= $nodeset->size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $nodeset->size) 0 0 0
564 # set context set each time 'cos a loc-path in the expr could change it
565 0 $self->{pp}->_set_context_set($nodeset);
566 0 $self->{pp}->_set_context_pos($i);
567 0 my $result = $predicate->evaluate($nodeset->get_node($i));
568 0 ▶ if ($result->isa('Tree::XPathEngine::Boolean')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result->isa('Tree::XPathEngine::Boolean')) { } 0 0 0
elsif ($result->isa('Tree::XPathEngine::Number')) { } 0 0 0
569 0 ▶ if ($result->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->value) 0 0 0
570 0 $newset->push($nodeset->get_node($i));
571 }
572 }
573 elsif ($result->isa('Tree::XPathEngine::Number')) {
574 0 ▶ if ($result->value == $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->value == $i) 0 0 0
575 0 $newset->push($nodeset->get_node($i));
576 }
577 }
578 else {
579 0 ▶ if ($result->xpath_to_boolean->value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->xpath_to_boolean->value) 0 0 0
580 0 $newset->push($nodeset->get_node($i));
581 }
582 }
583 }
584
585 0 return $newset;
586 }
587  
588 6 1;
589  
590 __END__
↑ Summary XPathEngine.pm »