XPath/Expr.pm

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