Object/XPath/Expr.pm

filter: Statementstmt 44.4% 133 / 299 Branchbran 32.0% 41 / 128 Conditioncond 26.4% 14 / 53 MC/DCmcdc 3.4% 1 / 29 Subroutinesub 55.8% 24 / 43 Podpod 100% 34 / 34 totaltotal 42.1% 247 / 586 CC 102 SCAR 45.3
CC
102
Cov
39%
op_ge
380.0
op_gt
158.8
op_equals
91.3
CRAP 93.0
« Object/DOM/Element/Input.pm ↑ Summary Object/Element.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XPath/Expr.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/05
7 ## Modified 2022/09/18
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::XPath::Expr;
15 BEGIN
16 14 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 14 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 14 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 14 warnings::register_categories( 'HTML::Object' );
20 14 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 14 ▶ use vars qw( $TRUE $FALSE $BASE_CLASS $DEBUG $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 14 ▶ use HTML::Object::XPath::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 14 our $TRUE = HTML::Object::XPath::Boolean->True;
24 14 our $FALSE = HTML::Object::XPath::Boolean->False;
25 14 our $BASE_CLASS = 'HTML::Object::XPath';
26 14 our $DEBUG = 0;
27 14 our $VERSION = 'v0.2.0';
28 };
29  
30 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 sub init
34 240 ▶{
Subroutine init: called CC=2 SCAR=7.0
Pod documented
35 240 my $self = shift( @_ );
36 # XPath Parser -> HTML::Object::XPath
37 240 my $pp = shift( @_ );
38 240 $self->{pp} = $pp;
39 240 $self->{predicates} = [];
40 240 $self->{_init_strict_use_sub} = 1;
41 240 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 240 0 240
42 240 return( $self );
43 }
44  
45 sub as_string
46 0 ▶{
Subroutine as_string: not called CC=4 SCAR=30.0
Pod documented
47 0 my $self = shift( @_ );
48 # Use of uninitialized value! grrr
49 # local $^W;
50 0 my $string = '(' . $self->{lhs}->as_string;
51 0 ▶ $string .= ' ' . $self->{op} . ' ' if( defined( $self->{op} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"op"} 0 0 0
52 0 ▶ $string .= $self->{rhs}->as_string if( defined( $self->{rhs} ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"rhs"} 0 0 0
53 0 $string .= ')';
54 0 foreach my $predicate ( @{$self->{predicates}} )
55 {
56 0 $string .= '[' . $predicate->as_string . ']';
57 }
58 0 return( $string );
59 }
60  
61 sub as_xml
62 0 ▶{
Subroutine as_xml: not called CC=3 SCAR=24.8
Pod documented
63 0 my $self = shift( @_ );
64 # Use of uninitialized value! grrr
65 # local $^W;
66 0 my $string;
67 0 ▶ if( defined( $self->{op} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'op'}) { } 0 0 0
68 {
69 0 $string .= $self->op_xml();
70 }
71 else
72 {
73 0 $string .= $self->{lhs}->as_xml();
74 }
75 0 foreach my $predicate ( @{$self->{predicates}} )
76 {
77 0 $string .= "<Predicate>\n" . $predicate->as_xml() . "</Predicate>\n";
78 }
79 0 return( $string );
80 }
81  
82 sub evaluate
83 615 ▶{
Subroutine evaluate: called CC=6 SCAR=18.1
Pod documented
84 615 my $self = shift( @_ );
85 # HTML::Object::XPath::NodeSet
86 615 my $node = shift( @_ );
87  
88 # If there's an op, result is result of that op.
89 # If no op, just resolve Expr
90  
91 # warn "Evaluate Expr: ", $self->as_string, "\n";
92  
93 615 my $results;
94  
95 615 ▶ if( $self->{op} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'op'}) { } 162 453 615
96 {
97 162 ▶ die( "No RHS of ", $self->as_string ) unless( $self->{rhs} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"rhs"} 0 162 162
98 162 $results = $self->op_eval( $node );
99 }
100 else
101 {
102 # HTML::Object::XPath::LocationPath
103 453 $results = $self->{lhs}->evaluate( $node );
104 }
105  
106 609 ▶ if( !$self->predicates->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->predicates->is_empty) 2 607 609
107 {
108 2 ▶ if( !$self->_is_a( $results => 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_is_a($results, "HTML::Object::XPath::NodeSet")) 0 2 2
109 {
110 0 die( "Can't have predicates execute on object type: " . ref( $results ) );
111 }
112  
113 # filter initial nodeset by each predicate
114 2 foreach my $predicate ( @{$self->{predicates}} )
115 {
116 2 $results = $self->filter_by_predicate( $results, $predicate );
117 }
118 }
119 609 return( $results );
120 }
121  
122 sub filter_by_predicate
123 2 ▶{
Subroutine filter_by_predicate: called CC=8 SCAR=24.6
Pod documented
124 2 my $self = shift( @_ );
125 2 my( $nodeset, $predicate ) = @_;
126  
127 # See spec section 2.4, paragraphs 2 & 3:
128 # For each node in the node-set to be filtered, the predicate Expr
129 # is evaluated with that node as the context node, with the number
130 # of nodes in the node set as the context size, and with the
131 # proximity position of the node in the node set with respect to
132 # the axis as the context position.
133  
134 # use ref because nodeset has a bool context
135 2 ▶ if( !ref( $nodeset ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $nodeset) 0 2 2
136 {
137 0 die( "No nodeset!!!" );
138 }
139  
140 # warn "Filter by predicate: $predicate\n";
141  
142 2 my $newset = $self->new_nodeset->new();
143  
144 2 ▶ for( my $i = 1; $i <= $nodeset->size; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $nodeset->size) 18 2 20
145 {
146 # set context set each time 'cos a loc-path in the expr could change it
147 18 $self->{pp}->_set_context_set( $nodeset );
148 18 $self->{pp}->_set_context_pos( $i );
149 18 my $result = $predicate->evaluate( $nodeset->get_node( $i ) );
150 18 ▶ if( $self->_is_a( $result => 'HTML::Object::XPath::Boolean' ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_is_a($result, 'HTML::Object::XPath::Boolean')) { } 0 18 18
elsif ($self->_is_a($result, 'HTML::Object::XPath::Number')) { } 18 0 18
151 {
152 0 ▶ if( $result->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($result->value) 0 0 0
153 {
154 0 $newset->push( $nodeset->get_node( $i ) );
155 }
156 }
157 elsif( $self->_is_a( $result => 'HTML::Object::XPath::Number' ) )
158 {
159 18 ▶ if( $result->value == $i )
Branch: 1 branch
BranchTrueFalseTotal
if ($result->value == $i) 2 16 18
160 {
161 2 $newset->push( $nodeset->get_node( $i ) );
162 }
163 }
164 else
165 {
166 0 ▶ if( $result->to_boolean->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($result->to_boolean->value) 0 0 0
167 {
168 0 $newset->push( $nodeset->get_node( $i ) );
169 }
170 }
171 }
172 2 return( $newset );
173 }
174  
175 0 ▶sub get_lhs { return( $_[0]->{lhs} ); }
Subroutine get_lhs: not called CC=1 SCAR=6.9
Pod documented
176  
177 0 ▶sub get_rhs { return( $_[0]->{rhs} ); }
Subroutine get_rhs: not called CC=1 SCAR=6.9
Pod documented
178  
179 0 ▶sub get_op { return( $_[0]->{op} ); }
Subroutine get_op: not called CC=1 SCAR=6.9
Pod documented
180  
181 0 ▶sub new_literal { return( shift->_class_for( 'Literal' )->new( @_ ) ); }
Subroutine new_literal: not called CC=1 SCAR=6.9
Pod documented
182  
183 2 ▶sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); }
Subroutine new_nodeset: called CC=1 SCAR=0.0
Pod documented
184  
185 0 ▶sub new_number { return( shift->_class_for( 'Number' )->new( @_ ) ); }
Subroutine new_number: not called CC=1 SCAR=6.9
Pod documented
186  
187 sub op_and
188 10 ▶{
Subroutine op_and: called CC=2 SCAR=7.4
Pod documented
189 10 my $self = shift( @_ );
190 10 my( $node, $lhs, $rhs ) = @_;
191 10 ▶ if( ! $lhs->evaluate( $node )->to_boolean->value )
Branch: 1 branch
BranchTrueFalseTotal
if (not $lhs->evaluate($node)->to_boolean->value) { } 0 10 10
192 {
193 0 return( $FALSE );
194 }
195 else
196 {
197 10 return( $rhs->evaluate( $node )->to_boolean );
198 }
199 }
200  
201 sub op_div
202 0 ▶{
Subroutine op_div: not called CC=2 SCAR=17.9
Pod documented
203 0 my $self = shift( @_ );
204 0 my( $node, $lhs, $rhs ) = @_;
205 0 my $lh_results = $lhs->evaluate( $node );
206 0 my $rh_results = $rhs->evaluate( $node );
207  
208 0 my $result = eval{ $lh_results->to_number->value / $rh_results->to_number->value; };
209 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
210 {
211 # assume divide by zero
212 # This is probably a terrible way to handle this!
213 # Ah well... who wants to live forever...
214 0 return( $self->new_literal( 'Infinity' ) );
215 }
216 0 return( $self->new_number( $result ) );
217 }
218  
219 sub op_equals
220 99 ▶{
Subroutine op_equals: called CC=26 SCAR=45.1
Pod documented
221 99 my $self = shift( @_ );
222 99 my( $node, $lhs, $rhs ) = @_;
223  
224 99 my $lh_results = $lhs->evaluate( $node );
225 99 my $rh_results = $rhs->evaluate( $node );
226  
227 96 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) &&
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet') and $rh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 96 96
elsif ($lh_results->isa('HTML::Object::XPath::NodeSet') || $rh_results->isa('HTML::Object::XPath::NodeSet') and not $lh_results->isa('HTML::Object::XPath::NodeSet') && $rh_results->isa('HTML::Object::XPath::NodeSet')) { } 89 7 96
Condition66%2/3
$lh_results->isa("HTML::Object::XPath::NodeSet") and $rh_results->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
7890
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::NodeSet") and $rh_results->isa("HTML::Object::XPath::NodeSet")
$lh_results->isa("HTML::Object::XPath::NodeSet") $rh_results->isa("HTML::Object::XPath::NodeSet")
Truth table66%2/3
A and B
A= $lh_results->isa("HTML::Object::XPath::NodeSet")B= $rh_results->isa("HTML::Object::XPath::NodeSet")
ABresult
0X0
100
111
228 $rh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
229 {
230 # True if and only if there is a node in the
231 # first set and a node in the second set such
232 # that the result of performing the comparison
233 # on the string-values of the two nodes is true.
234 0 foreach my $lhnode ( $lh_results->get_nodelist )
235 {
236 0 foreach my $rhnode ( $rh_results->get_nodelist )
237 {
238 0 ▶ if( $lhnode->string_value eq $rhnode->string_value )
Branch: 1 branch
BranchTrueFalseTotal
if ($lhnode->string_value eq $rhnode->string_value) 0 0 0
239 {
240 0 return( $TRUE );
241 }
242 }
243 }
244 0 return( $FALSE );
245 }
246 ▶ elsif( ( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) ||
Condition55%5/9
$lh_results->isa("HTML::Object::XPath::NodeSet") || $rh_results->isa("HTML::Object::XPath::NodeSet") and not $lh_results->isa("HTML::Object::XPath::NodeSet") && $rh_results->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
7089
$lh_results->isa("HTML::Object::XPath::NodeSet") or $rh_results->isa("HTML::Object::XPath::NodeSet")
l!l&&r!l&&!r
8907
$lh_results->isa('HTML::Object::XPath::NodeSet') && $rh_results->isa('HTML::Object::XPath::NodeSet')
!ll&&!rl&&r
0890
MC/DC25%1/4
$lh_results->isa("HTML::Object::XPath::NodeSet") || $rh_results->isa("HTML::Object::XPath::NodeSet") and not $lh_results->isa("HTML::Object::XPath::NodeSet") && $rh_results->isa("HTML::Object::XPath::NodeSet")
$lh_results->isa("HTML::Object::XPath::NodeSet") $rh_results->isa("HTML::Object::XPath::NodeSet") $lh_results->isa('HTML::Object::XPath::NodeSet') $rh_results->isa('HTML::Object::XPath::NodeSet')
Truth table28%2/7
A or B and not(C && D)
A= $lh_results->isa("HTML::Object::XPath::NodeSet")B= $rh_results->isa("HTML::Object::XPath::NodeSet")C= $lh_results->isa('HTML::Object::XPath::NodeSet')D= $rh_results->isa('HTML::Object::XPath::NodeSet')
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
247 $rh_results->isa( 'HTML::Object::XPath::NodeSet' ) ) &&
248 ( !$lh_results->isa( 'HTML::Object::XPath::NodeSet' ) ||
249 !$rh_results->isa( 'HTML::Object::XPath::NodeSet' ) ) )
250 {
251 # (that says: one is a nodeset, and one is not a nodeset)
252 89 my( $nodeset, $other );
253 89 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet')) { } 89 0 89
254 {
255 89 $nodeset = $lh_results;
256 89 $other = $rh_results;
257 }
258 else
259 {
260 0 $nodeset = $rh_results;
261 0 $other = $lh_results;
262 }
263  
264 # True if and only if there is a node in the
265 # nodeset such that the result of performing
266 # the comparison on <type>(string_value($node))
267 # is true.
268 89 ▶ if( $self->_is_a( $other => 'HTML::Object::XPath::Number' ) )
Branch: 3 branches
BranchTrueFalseTotal
if ($self->_is_a($other, 'HTML::Object::XPath::Number')) { } 5 84 89
elsif ($self->_is_a($other, 'HTML::Object::XPath::Literal')) { } 84 0 84
elsif ($self->_is_a($other, 'HTML::Object::XPath::Boolean')) { } 0 0 0
269 {
270 5 foreach my $node ( $nodeset->get_nodelist )
271 {
272 5 ▶ if( $node->string_value == $other->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->string_value == $other->value) 3 2 5
273 {
274 3 return( $TRUE );
275 }
276 }
277 }
278 elsif( $self->_is_a( $other => 'HTML::Object::XPath::Literal' ) )
279 {
280 84 foreach my $node ( $nodeset->get_nodelist )
281 {
282 59 ▶ if( $node->string_value eq $other->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($node->string_value eq $other->value) 35 24 59
283 {
284 35 return( $TRUE );
285 }
286 }
287 }
288 elsif( $self->_is_a( $other => 'HTML::Object::XPath::Boolean' ) )
289 {
290 0 ▶ if( $nodeset->to_boolean->value == $other->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($nodeset->to_boolean->value == $other->value) 0 0 0
291 {
292 0 return( $TRUE );
293 }
294 }
295 51 return( $FALSE );
296 }
297 # Neither is a nodeset
298 else
299 {
300 7 ▶ if( $lh_results->isa( 'HTML::Object::XPath::Boolean' ) ||
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::Boolean') or $rh_results->isa('HTML::Object::XPath::Boolean')) { } 0 7 7
elsif ($lh_results->isa('HTML::Object::XPath::Number') or $rh_results->isa('HTML::Object::XPath::Number')) { } 7 0 7
Condition33%1/3
$lh_results->isa("HTML::Object::XPath::Boolean") or $rh_results->isa("HTML::Object::XPath::Boolean")
l!l&&r!l&&!r
007
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::Boolean") or $rh_results->isa("HTML::Object::XPath::Boolean")
$lh_results->isa("HTML::Object::XPath::Boolean") $rh_results->isa("HTML::Object::XPath::Boolean")
Truth table33%1/3
A or B
A= $lh_results->isa("HTML::Object::XPath::Boolean")B= $rh_results->isa("HTML::Object::XPath::Boolean")
ABresult
1X1
011
000
301 $rh_results->isa( 'HTML::Object::XPath::Boolean' ) )
302 {
303 # if either is a boolean
304 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
305 {
306 0 return( $TRUE );
307 }
308 0 return( $FALSE );
309 }
310 ▶ elsif( $lh_results->isa( 'HTML::Object::XPath::Number' ) ||
Condition33%1/3
$lh_results->isa("HTML::Object::XPath::Number") or $rh_results->isa("HTML::Object::XPath::Number")
l!l&&r!l&&!r
700
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::Number") or $rh_results->isa("HTML::Object::XPath::Number")
$lh_results->isa("HTML::Object::XPath::Number") $rh_results->isa("HTML::Object::XPath::Number")
Truth table33%1/3
A or B
A= $lh_results->isa("HTML::Object::XPath::Number")B= $rh_results->isa("HTML::Object::XPath::Number")
ABresult
1X1
011
000
311 $rh_results->isa( 'HTML::Object::XPath::Number' ) )
312 {
313 # if either is a number
314 # 'number' might result in undef
315 7 local $^W;
316 7 ▶ 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) 3 4 7
317 {
318 3 return( $TRUE );
319 }
320 4 return( $FALSE );
321 }
322 else
323 {
324 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
325 {
326 0 return( $TRUE );
327 }
328 0 return( $FALSE );
329 }
330 }
331 }
332  
333 sub op_eval
334 162 ▶{
Subroutine op_eval: called CC=2 SCAR=7.0
Pod documented
335 162 my $self = shift( @_ );
336 162 my $node = shift( @_ );
337 162 my $op = $self->{op};
338 162 my $map =
339 {
340 'or' => 'op_or',
341 'and' => 'op_and',
342 '=~' => 'op_match',
343 '!~' => 'op_not_match',
344 '=' => 'op_equals',
345 '!=' => 'op_nequals',
346 '<=' => 'op_le',
347 '>=' => 'op_ge',
348 '>' => 'op_gt',
349 '<' => 'op_lt',
350 '+' => 'op_plus',
351 '-' => 'op_minus',
352 'div' => 'op_div',
353 'mod' => 'op_mod',
354 '*' => 'op_mult',
355 '|' => 'op_union',
356 };
357 162 ▶ die( "No such operator, or operator unimplemented in ", $self->as_string, "\n" ) if( !CORE::exists( $map->{ $op } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $map->{$op} 0 162 162
358 162 my $mod = $map->{ $op };
359 162 return( $self->$mod( $node, $self->{lhs}, $self->{rhs} ) );
360 }
361  
362 sub op_ge
363 0 ▶{
Subroutine op_ge: not called CC=19 SCAR=59.4
Pod documented
364 0 my $self = shift( @_ );
365 0 my( $node, $lhs, $rhs ) = @_;
366  
367 0 my $lh_results = $lhs->evaluate( $node );
368 0 my $rh_results = $rhs->evaluate( $node );
369  
370 0 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) &&
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet') and $rh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 0 0
elsif ($lh_results->isa('HTML::Object::XPath::NodeSet') || $rh_results->isa('HTML::Object::XPath::NodeSet') and not $lh_results->isa('HTML::Object::XPath::NodeSet') && $rh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 0 0
Condition0%0/3
$lh_results->isa("HTML::Object::XPath::NodeSet") and $rh_results->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
000
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::NodeSet") and $rh_results->isa("HTML::Object::XPath::NodeSet")
$lh_results->isa("HTML::Object::XPath::NodeSet") $rh_results->isa("HTML::Object::XPath::NodeSet")
Truth table0%0/3
A and B
A= $lh_results->isa("HTML::Object::XPath::NodeSet")B= $rh_results->isa("HTML::Object::XPath::NodeSet")
ABresult
0X0
100
111
371 $rh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
372 {
373 0 foreach my $lhnode ( $lh_results->get_nodelist )
374 {
375 0 foreach my $rhnode ( $rh_results->get_nodelist )
376 {
377 0 my $lhNum = $self->new_number( $lhnode->string_value );
378 0 my $rhNum = $self->new_number( $rhnode->string_value );
379 0 ▶ if( $lhNum->value >= $rhNum->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($lhNum->value >= $rhNum->value) 0 0 0
380 {
381 0 return( $TRUE );
382 }
383 }
384 }
385 0 return( $FALSE );
386 }
387 ▶ elsif( ( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) ||
Condition0%0/9
$lh_results->isa("HTML::Object::XPath::NodeSet") || $rh_results->isa("HTML::Object::XPath::NodeSet") and not $lh_results->isa("HTML::Object::XPath::NodeSet") && $rh_results->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
000
$lh_results->isa("HTML::Object::XPath::NodeSet") or $rh_results->isa("HTML::Object::XPath::NodeSet")
l!l&&r!l&&!r
000
$lh_results->isa('HTML::Object::XPath::NodeSet') && $rh_results->isa('HTML::Object::XPath::NodeSet')
!ll&&!rl&&r
000
MC/DC0%0/4
$lh_results->isa("HTML::Object::XPath::NodeSet") || $rh_results->isa("HTML::Object::XPath::NodeSet") and not $lh_results->isa("HTML::Object::XPath::NodeSet") && $rh_results->isa("HTML::Object::XPath::NodeSet")
$lh_results->isa("HTML::Object::XPath::NodeSet") $rh_results->isa("HTML::Object::XPath::NodeSet") $lh_results->isa('HTML::Object::XPath::NodeSet') $rh_results->isa('HTML::Object::XPath::NodeSet')
Truth table0%0/7
A or B and not(C && D)
A= $lh_results->isa("HTML::Object::XPath::NodeSet")B= $rh_results->isa("HTML::Object::XPath::NodeSet")C= $lh_results->isa('HTML::Object::XPath::NodeSet')D= $rh_results->isa('HTML::Object::XPath::NodeSet')
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
388 $rh_results->isa( 'HTML::Object::XPath::NodeSet' ) ) &&
389 ( !$lh_results->isa( 'HTML::Object::XPath::NodeSet' ) ||
390 !$rh_results->isa( 'HTML::Object::XPath::NodeSet' ) ) )
391 {
392 # (that says: one is a nodeset, and one is not a nodeset)
393 0 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 0 0
394 {
395 0 foreach my $node ( $lh_results->get_nodelist )
396 {
397 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
398 {
399 0 return( $TRUE );
400 }
401 }
402 }
403 else
404 {
405 0 foreach my $node ( $rh_results->get_nodelist )
406 {
407 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
408 {
409 0 return( $TRUE );
410 }
411 }
412 }
413 0 return( $FALSE );
414 }
415 # Neither is a nodeset
416 else
417 {
418 0 ▶ if( $lh_results->isa( 'HTML::Object::XPath::Boolean' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::Boolean') or $rh_results->isa('HTML::Object::XPath::Boolean')) { } 0 0 0
Condition0%0/3
$lh_results->isa("HTML::Object::XPath::Boolean") or $rh_results->isa("HTML::Object::XPath::Boolean")
l!l&&r!l&&!r
000
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::Boolean") or $rh_results->isa("HTML::Object::XPath::Boolean")
$lh_results->isa("HTML::Object::XPath::Boolean") $rh_results->isa("HTML::Object::XPath::Boolean")
Truth table0%0/3
A or B
A= $lh_results->isa("HTML::Object::XPath::Boolean")B= $rh_results->isa("HTML::Object::XPath::Boolean")
ABresult
1X1
011
000
419 $rh_results->isa( 'HTML::Object::XPath::Boolean' ) )
420 {
421 # if either is a boolean
422 0 ▶ if( $lh_results->to_boolean->to_number->value >= $rh_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
423 {
424 0 return( $TRUE );
425 }
426 }
427 else
428 {
429 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
430 {
431 0 return( $TRUE );
432 }
433 }
434 0 return( $FALSE );
435 }
436 }
437  
438 sub op_gt
439 1 ▶{
Subroutine op_gt: called CC=19 SCAR=50.7
Pod documented
440 1 my $self = shift( @_ );
441 1 my( $node, $lhs, $rhs ) = @_;
442  
443 1 my $lh_results = $lhs->evaluate( $node );
444 1 my $rh_results = $rhs->evaluate( $node );
445  
446 1 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) &&
Branch: 2 branches
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet') and $rh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 1 1
elsif ($lh_results->isa('HTML::Object::XPath::NodeSet') || $rh_results->isa('HTML::Object::XPath::NodeSet') and not $lh_results->isa('HTML::Object::XPath::NodeSet') && $rh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 1 1
Condition33%1/3
$lh_results->isa("HTML::Object::XPath::NodeSet") and $rh_results->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
100
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::NodeSet") and $rh_results->isa("HTML::Object::XPath::NodeSet")
$lh_results->isa("HTML::Object::XPath::NodeSet") $rh_results->isa("HTML::Object::XPath::NodeSet")
Truth table33%1/3
A and B
A= $lh_results->isa("HTML::Object::XPath::NodeSet")B= $rh_results->isa("HTML::Object::XPath::NodeSet")
ABresult
0X0
100
111
447 $rh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
448 {
449 0 foreach my $lhnode ( $lh_results->get_nodelist )
450 {
451 0 foreach my $rhnode ( $rh_results->get_nodelist )
452 {
453 0 my $lhNum = $self->new_number( $lhnode->string_value );
454 0 my $rhNum = $self->new_number( $rhnode->string_value );
455 0 ▶ if( $lhNum->value > $rhNum->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($lhNum->value > $rhNum->value) 0 0 0
456 {
457 0 return( $TRUE );
458 }
459 }
460 }
461 0 return( $FALSE );
462 }
463 ▶ elsif( ( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) ||
Condition22%2/9
$lh_results->isa("HTML::Object::XPath::NodeSet") || $rh_results->isa("HTML::Object::XPath::NodeSet") and not $lh_results->isa("HTML::Object::XPath::NodeSet") && $rh_results->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
100
$lh_results->isa("HTML::Object::XPath::NodeSet") or $rh_results->isa("HTML::Object::XPath::NodeSet")
l!l&&r!l&&!r
001
$lh_results->isa('HTML::Object::XPath::NodeSet') && $rh_results->isa('HTML::Object::XPath::NodeSet')
!ll&&!rl&&r
000
MC/DC0%0/4
$lh_results->isa("HTML::Object::XPath::NodeSet") || $rh_results->isa("HTML::Object::XPath::NodeSet") and not $lh_results->isa("HTML::Object::XPath::NodeSet") && $rh_results->isa("HTML::Object::XPath::NodeSet")
$lh_results->isa("HTML::Object::XPath::NodeSet") $rh_results->isa("HTML::Object::XPath::NodeSet") $lh_results->isa('HTML::Object::XPath::NodeSet') $rh_results->isa('HTML::Object::XPath::NodeSet')
Truth table14%1/7
A or B and not(C && D)
A= $lh_results->isa("HTML::Object::XPath::NodeSet")B= $rh_results->isa("HTML::Object::XPath::NodeSet")C= $lh_results->isa('HTML::Object::XPath::NodeSet')D= $rh_results->isa('HTML::Object::XPath::NodeSet')
ABCDresult
00XX0
1X110
01110
1X0X1
1X101
010X1
01101
464 $rh_results->isa( 'HTML::Object::XPath::NodeSet' ) ) &&
465 ( !$lh_results->isa( 'HTML::Object::XPath::NodeSet' ) ||
466 !$rh_results->isa( 'HTML::Object::XPath::NodeSet' ) ) )
467 {
468 # (that says: one is a nodeset, and one is not a nodeset)
469 0 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 0 0
470 {
471 0 foreach my $node ( $lh_results->get_nodelist )
472 {
473 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
474 {
475 0 return( $TRUE );
476 }
477 }
478 }
479 else
480 {
481 0 foreach my $node ( $rh_results->get_nodelist )
482 {
483 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
484 {
485 0 return( $TRUE );
486 }
487 }
488 }
489 0 return( $FALSE );
490 }
491 # Neither is a nodeset
492 else
493 {
494 1 ▶ if( $lh_results->isa( 'HTML::Object::XPath::Boolean' ) ||
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::Boolean') or $rh_results->isa('HTML::Object::XPath::Boolean')) { } 0 1 1
Condition33%1/3
$lh_results->isa("HTML::Object::XPath::Boolean") or $rh_results->isa("HTML::Object::XPath::Boolean")
l!l&&r!l&&!r
001
MC/DC0%0/2
$lh_results->isa("HTML::Object::XPath::Boolean") or $rh_results->isa("HTML::Object::XPath::Boolean")
$lh_results->isa("HTML::Object::XPath::Boolean") $rh_results->isa("HTML::Object::XPath::Boolean")
Truth table33%1/3
A or B
A= $lh_results->isa("HTML::Object::XPath::Boolean")B= $rh_results->isa("HTML::Object::XPath::Boolean")
ABresult
1X1
011
000
495 $rh_results->isa( 'HTML::Object::XPath::Boolean' ) )
496 {
497 # if either is a boolean
498 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
499 {
500 0 return( $TRUE );
501 }
502 }
503 else
504 {
505 1 ▶ 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 1 1
506 {
507 0 return( $TRUE );
508 }
509 }
510 1 return( $FALSE );
511 }
512 }
513  
514 sub op_le
515 0 ▶{
Subroutine op_le: not called CC=1 SCAR=6.9
Pod documented
516 0 my $self = shift( @_ );
517 0 my( $node, $lhs, $rhs ) = @_;
518 0 return( $self->op_ge( $node, $rhs, $lhs ) );
519 }
520  
521 sub op_lt
522 0 ▶{
Subroutine op_lt: not called CC=1 SCAR=6.9
Pod documented
523 0 my $self = shift( @_ );
524 0 my( $node, $lhs, $rhs ) = @_;
525 0 return( $self->op_gt( $node, $rhs, $lhs ) );
526 }
527  
528 sub op_match
529 47 ▶{
Subroutine op_match: called CC=5 SCAR=16.7
Pod documented
530 47 my $self = shift( @_ );
531 47 my( $node, $lhs, $rhs ) = @_;
532  
533 47 my $lh_results = $lhs->evaluate( $node );
534 47 my $rh_results = $rhs->evaluate( $node );
535 47 my $rh_value = $rh_results->string_value;
536  
537 47 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet')) { } 47 0 47
538 {
539 47 foreach my $lhnode ( $lh_results->get_nodelist )
540 {
541 # / is important here, regexp is / delimited
542 21 ▶ if( $lhnode->string_value =~ m/$rh_value/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($lhnode->string_value =~ /$rh_value/) 12 9 21
543 {
544 12 return( $TRUE );
545 }
546 }
547 35 return( $FALSE );
548 }
549 else
550 {
551 return(
552 0 ▶ $lh_results->string_value =~ m/$rh_value/
Branch: 1 branch
BranchTrueFalseTotal
$lh_results->string_value =~ /$rh_value/ ? : 0 0 0
553 ? $TRUE
554 : $FALSE
555 );
556 }
557 }
558  
559 sub op_minus
560 0 ▶{
Subroutine op_minus: not called CC=1 SCAR=6.9
Pod documented
561 0 my $self = shift( @_ );
562 0 my( $node, $lhs, $rhs ) = @_;
563 0 my $lh_results = $lhs->evaluate( $node );
564 0 my $rh_results = $rhs->evaluate( $node );
565  
566 0 my $result = $lh_results->to_number->value - $rh_results->to_number->value;
567 0 return( $self->new_number( $result ) );
568 }
569  
570 sub op_mod
571 0 ▶{
Subroutine op_mod: not called CC=1 SCAR=6.9
Pod documented
572 0 my $self = shift( @_ );
573 0 my( $node, $lhs, $rhs ) = @_;
574 0 my $lh_results = $lhs->evaluate( $node );
575 0 my $rh_results = $rhs->evaluate( $node );
576  
577 0 my $result = $lh_results->to_number->value % $rh_results->to_number->value;
578 0 return( $self->new_number( $result ) );
579 }
580  
581 sub op_mult
582 0 ▶{
Subroutine op_mult: not called CC=1 SCAR=6.9
Pod documented
583 0 my $self = shift( @_ );
584 0 my( $node, $lhs, $rhs ) = @_;
585 0 my $lh_results = $lhs->evaluate( $node );
586 0 my $rh_results = $rhs->evaluate( $node );
587  
588 0 my $result = $lh_results->to_number->value * $rh_results->to_number->value;
589 0 return( $self->new_number( $result ) );
590 }
591  
592 sub op_nequals
593 0 ▶{
Subroutine op_nequals: not called CC=2 SCAR=17.9
Pod documented
594 0 my $self = shift( @_ );
595 0 my( $node, $lhs, $rhs ) = @_;
596 0 ▶ if( $self->op_equals( $node, $lhs, $rhs)->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->op_equals($node, $lhs, $rhs)->value) 0 0 0
597 {
598 0 return( $FALSE );
599 }
600 0 return( $TRUE );
601 }
602  
603 sub op_not_match
604 0 ▶{
Subroutine op_not_match: not called CC=5 SCAR=34.0
Pod documented
605 0 my $self = shift( @_ );
606 0 my( $node, $lhs, $rhs ) = @_;
607  
608 0 my $lh_results = $lhs->evaluate( $node );
609 0 my $rh_results = $rhs->evaluate( $node );
610 0 my $rh_value = $rh_results->string_value;
611  
612 0 ▶ if( $lh_results->isa( 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_results->isa('HTML::Object::XPath::NodeSet')) { } 0 0 0
613 {
614 0 foreach my $lhnode ( $lh_results->get_nodelist )
615 {
616 0 ▶ if( $lhnode->string_value !~ m/$rh_value/ )
Branch: 1 branch
BranchTrueFalseTotal
unless ($lhnode->string_value =~ /$rh_value/) 0 0 0
617 {
618 0 return( $TRUE );
619 }
620 }
621 0 return( $FALSE );
622 }
623 else
624 {
625 0 ▶ return( $lh_results->string_value !~ m/$rh_value/ ? $TRUE : $FALSE );
Branch: 1 branch
BranchTrueFalseTotal
!($lh_results->string_value =~ /$rh_value/) ? : 0 0 0
626 }
627 }
628  
629 sub op_or
630 5 ▶{
Subroutine op_or: called CC=2 SCAR=7.4
Pod documented
631 5 my $self = shift( @_ );
632 5 my( $node, $lhs, $rhs ) = @_;
633 5 ▶ if( $lhs->evaluate( $node )->to_boolean->value )
Branch: 1 branch
BranchTrueFalseTotal
if ($lhs->evaluate($node)->to_boolean->value) { } 5 0 5
634 {
635 5 return( $TRUE );
636 }
637 else
638 {
639 0 return $rhs->evaluate( $node )->to_boolean;
640 }
641 }
642  
643 sub op_plus
644 0 ▶{
Subroutine op_plus: not called CC=1 SCAR=6.9
Pod documented
645 0 my $self = shift( @_ );
646 0 my( $node, $lhs, $rhs ) = @_;
647 0 my $lh_results = $lhs->evaluate( $node );
648 0 my $rh_results = $rhs->evaluate( $node );
649  
650 0 my $result = $lh_results->to_number->value + $rh_results->to_number->value;
651 0 return( $self->new_number( $result ) );
652 }
653  
654 sub op_union
655 0 ▶{
Subroutine op_union: not called CC=6 SCAR=37.4
Pod documented
656 0 my $self = shift( @_ );
657 0 my( $node, $lhs, $rhs ) = @_;
658 0 my $lh_result = $lhs->evaluate( $node );
659 0 my $rh_result = $rhs->evaluate( $node );
660  
661 0 ▶ if( $lh_result->isa( 'HTML::Object::XPath::NodeSet' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($lh_result->isa("HTML::Object::XPath::NodeSet") and $rh_result->isa("HTML::Object::XPath::NodeSet")) 0 0 0
Condition0%0/3
$lh_result->isa("HTML::Object::XPath::NodeSet") and $rh_result->isa("HTML::Object::XPath::NodeSet")
!ll&&!rl&&r
000
MC/DC0%0/2
$lh_result->isa("HTML::Object::XPath::NodeSet") and $rh_result->isa("HTML::Object::XPath::NodeSet")
$lh_result->isa("HTML::Object::XPath::NodeSet") $rh_result->isa("HTML::Object::XPath::NodeSet")
Truth table0%0/3
A and B
A= $lh_result->isa("HTML::Object::XPath::NodeSet")B= $rh_result->isa("HTML::Object::XPath::NodeSet")
ABresult
0X0
100
111
662 $rh_result->isa( 'HTML::Object::XPath::NodeSet' ) )
663 {
664 0 my %found;
665 0 my $results = $self->new_nodeset;
666 0 foreach my $lhnode ( $lh_result->get_nodelist )
667 {
668 0 $found{ "$lhnode" }++;
669 0 $results->push( $lhnode );
670 }
671 0 foreach my $rhnode ( $rh_result->get_nodelist )
672 {
673 0 ▶ $results->push( $rhnode ) unless( exists( $found{ "$rhnode" } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $found{"$rhnode"} 0 0 0
674 }
675 0 return( $results->sort->remove_duplicates );
676 }
677 0 die( "Both sides of a union must be Node Sets\n" );
678 }
679  
680 sub op_xml
681 0 ▶{
Subroutine op_xml: not called CC=2 SCAR=17.9
Pod documented
682 0 my $self = shift( @_ );
683 0 my $op = $self->{op};
684  
685 0 my $map =
686 {
687 'and' => 'And',
688 'div' => 'Div',
689 'mod' => 'Mod',
690 'or' => 'Or',
691 '=' => 'Equals',
692 '!=' => 'NotEquals',
693 '<=' => 'LessThanOrEquals',
694 '>=' => 'GreaterThanOrEquals',
695 '>' => 'GreaterThan',
696 '<' => 'LessThan',
697 '+' => 'Plus',
698 '-' => 'Minus',
699 '*' => 'Multiply',
700 '|' => 'Union',
701 };
702 0 ▶ die( "No tag equivalent for operator \"$op\".\n" ) if( !CORE::exists( $map->{ $op } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $map->{$op} 0 0 0
703 0 my $tag = $map->{ $op };
704 0 return( "<$tag>\n" . $self->{lhs}->as_xml() . $self->{rhs}->as_xml() . "</$tag>\n" );
705 }
706  
707 613 ▶sub predicates { return( shift->_set_get_array_as_object( 'predicates', @_ ) ); }
Subroutine predicates: called CC=1 SCAR=0.0
Pod documented
708  
709 sub push_predicate
710 2 ▶{
Subroutine push_predicate: called CC=2 SCAR=7.0
Pod documented
711 2 my $self = shift( @_ );
712  
713 2 ▶ die( "Only 1 predicate allowed on FilterExpr in W3C XPath 1.0" ) if( @{$self->{predicates}} );
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"predicates"};} 0 2 2
714 # push( @{$self->{predicates}}, $_[0] );
715 2 $self->predicates->push( $_[0] );
716 # Need to return $self
717 # return( $self );
718 2 return( $self->predicates->length );
719 }
720  
721 sub set_lhs
722 177 ▶{
Subroutine set_lhs: called CC=1 SCAR=0.0
Pod documented
723 177 my $self = shift( @_ );
724 177 $self->{lhs} = $_[0];
725 }
726  
727 sub set_op
728 28 ▶{
Subroutine set_op: called CC=1 SCAR=0.0
Pod documented
729 28 my $self = shift( @_ );
730 28 $self->{op} = $_[0];
731 }
732  
733 sub set_rhs
734 28 ▶{
Subroutine set_rhs: called CC=1 SCAR=0.0
Pod documented
735 28 my $self = shift( @_ );
736 28 $self->{rhs} = $_[0];
737 }
738  
739 sub _class_for
740 2 ▶{
Subroutine _class_for: called CC=3 SCAR=11.3
741 2 my( $self, $mod ) = @_;
742 2 eval( "require ${BASE_CLASS}\::${mod};" );
743 2 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
744 # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
745 2 ▶ eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
Condition50%1/2
$HTML::Object::XPath::Expr::DEBUG // 0
l!l
20
MC/DC0%0/1
$HTML::Object::XPath::Expr::DEBUG // 0
$HTML::Object::XPath::Expr::DEBUG
Truth table50%1/2
A
A= $HTML::Object::XPath::Expr::DEBUG
Aresult
11
00
746 2 return( "${BASE_CLASS}::${mod}" );
747 }
748  
749 14 1;
750 # NOTE: POD
751 __END__
« Object/DOM/Element/Input.pm ↑ Summary Object/Element.pm »