| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/XPath/Step.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::Step; | ||||||||||||||||||||||||||||||||||
| 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( $BASE_CLASS $DEBUG $VERSION ); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 22 | 14 | ▶ | use constant { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 23 | # Full name | ||||||||||||||||||||||||||||||||||
| 24 | 14 | TEST_QNAME => 0, | |||||||||||||||||||||||||||||||||
| 25 | # NCName:* | ||||||||||||||||||||||||||||||||||
| 26 | TEST_NCWILD => 1, | ||||||||||||||||||||||||||||||||||
| 27 | # * | ||||||||||||||||||||||||||||||||||
| 28 | TEST_ANY => 2, | ||||||||||||||||||||||||||||||||||
| 29 | # @ns:attrib | ||||||||||||||||||||||||||||||||||
| 30 | TEST_ATTR_QNAME => 3, | ||||||||||||||||||||||||||||||||||
| 31 | # @nc:* | ||||||||||||||||||||||||||||||||||
| 32 | TEST_ATTR_NCWILD => 4, | ||||||||||||||||||||||||||||||||||
| 33 | # @* | ||||||||||||||||||||||||||||||||||
| 34 | TEST_ATTR_ANY => 5, | ||||||||||||||||||||||||||||||||||
| 35 | # comment() | ||||||||||||||||||||||||||||||||||
| 36 | TEST_NT_COMMENT => 6, | ||||||||||||||||||||||||||||||||||
| 37 | # text() | ||||||||||||||||||||||||||||||||||
| 38 | TEST_NT_TEXT => 7, | ||||||||||||||||||||||||||||||||||
| 39 | # processing-instruction() | ||||||||||||||||||||||||||||||||||
| 40 | TEST_NT_PI => 8, | ||||||||||||||||||||||||||||||||||
| 41 | # node() | ||||||||||||||||||||||||||||||||||
| 42 | TEST_NT_NODE => 9, | ||||||||||||||||||||||||||||||||||
| 43 | 14 | }; | |||||||||||||||||||||||||||||||||
| 44 | 14 | our $BASE_CLASS = 'HTML::Object::XPath'; | |||||||||||||||||||||||||||||||||
| 45 | 14 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||
| 46 | 14 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||
| 49 | 14 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 50 | 14 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | sub init | ||||||||||||||||||||||||||||||||||
| 53 | 161 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 54 | 161 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 55 | # HTML::Object::XPath class | ||||||||||||||||||||||||||||||||||
| 56 | 161 | $self->{pp} = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 57 | 161 | $self->{axis} = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 58 | 161 | $self->{test} = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 59 | 161 | $self->{literal} = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 60 | 161 | $self->{predicates} = []; | |||||||||||||||||||||||||||||||||
| 61 | 161 | $self->{axis_method} = 'axis_' . $self->{axis}; | |||||||||||||||||||||||||||||||||
| 62 | 161 | $self->{axis_method} =~ tr/-/_/; | |||||||||||||||||||||||||||||||||
| 63 | # my( $pp, $axis, $test, $literal) = @_; | ||||||||||||||||||||||||||||||||||
| 64 | 161 | my $axis_method = "axis_$self->{axis}"; | |||||||||||||||||||||||||||||||||
| 65 | 161 | $axis_method =~ tr/-/_/; | |||||||||||||||||||||||||||||||||
| 66 | 161 | $self->{_init_strict_use_sub} = 1; | |||||||||||||||||||||||||||||||||
| 67 | 161 | ▶ | $self->SUPER::init( @_ ) || return( $self->pass_error ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 68 | 161 | return( $self ); | |||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | sub as_string | ||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_string: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 73 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 74 | 0 | my $string = $self->{axis} . '::'; | |||||||||||||||||||||||||||||||||
| 75 | 0 | my $test = $self->{test}; | |||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if( $test == TEST_NT_PI ) | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||
| 78 | 0 | $string .= 'processing-instruction('; | |||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if( $self->{literal}->value ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||
| 81 | 0 | $string .= $self->{literal}->as_string; | |||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||
| 83 | 0 | $string .= ')'; | |||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||
| 85 | elsif ($test == TEST_NT_COMMENT ) | ||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||
| 87 | 0 | $string .= 'comment()'; | |||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||
| 89 | elsif ($test == TEST_NT_TEXT ) | ||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||
| 91 | 0 | $string .= 'text()'; | |||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||
| 93 | elsif ($test == TEST_NT_NODE ) | ||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||
| 95 | 0 | $string .= 'node()'; | |||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||
| 97 | ▶ | elsif ($test == TEST_NCWILD || $test == TEST_ATTR_NCWILD ) | |||||||||||||||||||||||||||||||||
|
Condition0%0/3
$test == 1 or $test == 4
MC/DC0%0/2
$test == 1 or $test == 4
$test == 1
$test == 4
Truth table0%0/3
A or B
A= $test == 1B= $test == 4
| |||||||||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||||||||
| 99 | 0 | $string .= $self->{literal} . ':*'; | |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | else | ||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||
| 103 | 0 | $string .= $self->{literal}; | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||
| 106 | 0 | foreach( @{$self->{predicates}} ) | |||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | next unless( defined( $_ ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 109 | 0 | $string .= '[' . $_->as_string . ']'; | |||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | 0 | return( $string ); | |||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||
| 114 | sub as_xml | ||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
as_xml: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 117 | 0 | my $string = "<Step>\n"; | |||||||||||||||||||||||||||||||||
| 118 | 0 | $string .= "<Axis>" . $self->{axis} . "</Axis>\n"; | |||||||||||||||||||||||||||||||||
| 119 | 0 | my $test = $self->{test}; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 0 | $string .= "<Test>"; | |||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if( $test == TEST_NT_PI ) | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||||||||
| 125 | 0 | $string .= '<processing-instruction'; | |||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if( $self->{literal}->value ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||
| 128 | 0 | $string .= '>'; | |||||||||||||||||||||||||||||||||
| 129 | 0 | $string .= $self->{literal}->as_string; | |||||||||||||||||||||||||||||||||
| 130 | 0 | $string .= '</processing-instruction>'; | |||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||
| 132 | else | ||||||||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||||||||
| 134 | 0 | $string .= '/>'; | |||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | elsif( $test == TEST_NT_COMMENT ) | ||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||
| 139 | 0 | $string .= '<comment/>'; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | elsif( $test == TEST_NT_TEXT ) | ||||||||||||||||||||||||||||||||||
| 142 | { | ||||||||||||||||||||||||||||||||||
| 143 | 0 | $string .= '<text/>'; | |||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||
| 145 | elsif( $test == TEST_NT_NODE ) | ||||||||||||||||||||||||||||||||||
| 146 | { | ||||||||||||||||||||||||||||||||||
| 147 | 0 | $string .= '<node/>'; | |||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||
| 149 | ▶ | elsif( $test == TEST_NCWILD || $test == TEST_ATTR_NCWILD ) | |||||||||||||||||||||||||||||||||
|
Condition0%0/3
$test == 1 or $test == 4
MC/DC0%0/2
$test == 1 or $test == 4
$test == 1
$test == 4
Truth table0%0/3
A or B
A= $test == 1B= $test == 4
| |||||||||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||||||||
| 151 | 0 | $string .= '<namespace-prefix>' . $self->{literal} . '</namespace-prefix>'; | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | else | ||||||||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||||||||
| 155 | 0 | $string .= '<nametest>' . $self->{literal} . '</nametest>'; | |||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||
| 157 | 0 | $string .= "</Test>\n"; | |||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 0 | foreach( @{$self->{predicates}} ) | |||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | next unless( defined( $_ ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 0 | $string .= "<Predicate>\n" . $_->as_xml() . "</Predicate>\n"; | |||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||
| 164 | 0 | $string .= "</Step>\n"; | |||||||||||||||||||||||||||||||||
| 165 | 0 | return( $string ); | |||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||
| 168 | 84 | ▶ | sub axis { return( shift->_set_get_scalar( 'axis', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
axis: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||
| 170 | sub axis_ancestor | ||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_ancestor: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 172 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 173 | 0 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 174 | 0 | my $parent = $context->getParentNode; | |||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||
| 176 | # START: | ||||||||||||||||||||||||||||||||||
| 177 | # return( $results ) unless( $parent ); | ||||||||||||||||||||||||||||||||||
| 178 | # if( $self->node_test( $parent ) ) | ||||||||||||||||||||||||||||||||||
| 179 | # { | ||||||||||||||||||||||||||||||||||
| 180 | # $results->push( $parent ); | ||||||||||||||||||||||||||||||||||
| 181 | # } | ||||||||||||||||||||||||||||||||||
| 182 | # $parent = $parent->getParentNode; | ||||||||||||||||||||||||||||||||||
| 183 | # goto( START ); | ||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | while( $parent ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if( $self->node_test( $parent ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||
| 188 | 0 | $results->push( $parent ); | |||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||
| 190 | 0 | $parent = $parent->getParentNode; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | 0 | return( $results ); | |||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | sub axis_ancestor_or_self | ||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_ancestor_or_self: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 197 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 198 | 0 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||
| 200 | # START: | ||||||||||||||||||||||||||||||||||
| 201 | # return $results unless $context; | ||||||||||||||||||||||||||||||||||
| 202 | # if( $self->node_test( $context ) ) | ||||||||||||||||||||||||||||||||||
| 203 | # { | ||||||||||||||||||||||||||||||||||
| 204 | # $results->push( $context ); | ||||||||||||||||||||||||||||||||||
| 205 | # } | ||||||||||||||||||||||||||||||||||
| 206 | # $context = $context->getParentNode; | ||||||||||||||||||||||||||||||||||
| 207 | # goto START; | ||||||||||||||||||||||||||||||||||
| 208 | 0 | ▶ | while( $context ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | if( $self->node_test( $context ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||
| 212 | 0 | $results->push( $context ); | |||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||
| 214 | 0 | $context = $context->getParentNode; | |||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||
| 216 | 0 | return( $results ); | |||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | sub axis_attribute | ||||||||||||||||||||||||||||||||||
| 220 | 204 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_attribute: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 221 | 204 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 222 | 204 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||
| 224 | 204 | foreach my $attrib ( @{$context->getAttributes} ) | |||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||
| 226 | 433 | ▶ | if( $self->test_attribute( $attrib ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||
| 228 | 187 | $results->push( $attrib ); | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||
| 233 | sub axis_child | ||||||||||||||||||||||||||||||||||
| 234 | 455 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_child: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 235 | 455 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 236 | 455 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 237 | 455 | my $children = $context->getChildNodes; | |||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||
| 239 | 454 | foreach my $node ( @{$context->getChildNodes} ) | |||||||||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||||||||
| 241 | 452 | ▶ | if( $self->node_test( $node ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 242 | { | ||||||||||||||||||||||||||||||||||
| 243 | 150 | $results->push( $node ); | |||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||
| 248 | sub axis_descendant | ||||||||||||||||||||||||||||||||||
| 249 | 36 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_descendant: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 250 | 36 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 251 | 36 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | 36 | my @queue = $context->getChildNodes; | |||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||
| 255 | 36 | ▶ | while( @queue ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 256 | { | ||||||||||||||||||||||||||||||||||
| 257 | 1093 | my $node = shift( @queue ); | |||||||||||||||||||||||||||||||||
| 258 | 1093 | ▶ | if( $self->node_test( $node ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||
| 260 | 105 | $results->push( $node ); | |||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||
| 262 | else | ||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||
| 264 | # Node failed the test. | ||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||
| 266 | 1093 | push( @queue, $node->getChildNodes ); | |||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||
| 270 | sub axis_descendant_or_self | ||||||||||||||||||||||||||||||||||
| 271 | 26 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_descendant_or_self: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 272 | 26 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 273 | 26 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||
| 275 | # Use a queue (FIFO) instead of a stack (LIFO) for traversal. | ||||||||||||||||||||||||||||||||||
| 276 | # push/shift (BFS) vs unshift/shift (DFS) yields the same node set for | ||||||||||||||||||||||||||||||||||
| 277 | # descendant-or-self since all nodes are visited regardless of order. | ||||||||||||||||||||||||||||||||||
| 278 | # BFS is O(1) per enqueue (push appends), whereas DFS via unshift is | ||||||||||||||||||||||||||||||||||
| 279 | # O(n) per step because it must shift all existing elements rightward. | ||||||||||||||||||||||||||||||||||
| 280 | # On a document with many siblings, this makes a significant difference | ||||||||||||||||||||||||||||||||||
| 281 | # in both CPU time and peak memory (the queue never grows beyond the | ||||||||||||||||||||||||||||||||||
| 282 | # width of the widest level, vs a DFS stack that holds entire subtrees). | ||||||||||||||||||||||||||||||||||
| 283 | 26 | my @queue = ( $context ); | |||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||
| 285 | 26 | ▶ | while( @queue ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 286 | { | ||||||||||||||||||||||||||||||||||
| 287 | 471 | my $node = shift( @queue ); | |||||||||||||||||||||||||||||||||
| 288 | 471 | ▶ | if( $self->node_test( $node ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||
| 290 | 471 | $results->push( $node ); | |||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||
| 292 | 471 | push( @queue, $node->getChildNodes ); | |||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | sub axis_following | ||||||||||||||||||||||||||||||||||
| 297 | 5 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_following: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 298 | 5 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 299 | 5 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | 5 | ▶ | my $elt = $context->getNextSibling || _next_sibling_of_an_ancestor_of( $context ); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$context->getNextSibling || _next_sibling_of_an_ancestor_of($context)
MC/DC0%0/2
$context->getNextSibling || _next_sibling_of_an_ancestor_of($context)
$context->getNextSibling
_next_sibling_of_an_ancestor_of($context)
Truth table33%1/3
A || B
A= $context->getNextSiblingB= _next_sibling_of_an_ancestor_of($context)
| |||||||||||||||||||||||||||||||||||
| 302 | 5 | ▶ | while( $elt ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 303 | { | ||||||||||||||||||||||||||||||||||
| 304 | 30 | ▶ | if( $self->node_test( $elt ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||
| 306 | 9 | $results->push( $elt ); | |||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||
| 308 | 30 | ▶ | $elt = $elt->getFirstChild || $elt->getNextSibling || _next_sibling_of_an_ancestor_of( $elt ); | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$elt->getFirstChild || $elt->getNextSibling || _next_sibling_of_an_ancestor_of($elt)
$elt->getFirstChild or $elt->getNextSibling
MC/DC100%3/3
$elt->getFirstChild || $elt->getNextSibling || _next_sibling_of_an_ancestor_of($elt)
$elt->getFirstChild
$elt->getNextSibling
_next_sibling_of_an_ancestor_of($elt)
Truth table100%4/4
A or B || C
A= $elt->getFirstChildB= $elt->getNextSiblingC= _next_sibling_of_an_ancestor_of($elt)
| |||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||
| 312 | sub axis_following_sibling | ||||||||||||||||||||||||||||||||||
| 313 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_following_sibling: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 314 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 315 | 0 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||
| 317 | # warn "in axis_following_sibling"; | ||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | while( $context = $context->getNextSibling ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | if( $self->node_test( $context ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 321 | { | ||||||||||||||||||||||||||||||||||
| 322 | 0 | $results->push( $context ); | |||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||
| 327 | 30 | ▶ | sub axis_method { return( shift->_set_get_scalar( 'axis_method', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_method: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||
| 329 | sub axis_namespace | ||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_namespace: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 331 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 332 | 0 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return( $results ) unless( $context->isElementNode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 335 | 0 | foreach my $ns ( @{$context->getNamespaces} ) | |||||||||||||||||||||||||||||||||
| 336 | { | ||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if( $self->test_namespace( $ns ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 338 | { | ||||||||||||||||||||||||||||||||||
| 339 | 0 | $results->push( $ns ); | |||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||
| 344 | sub axis_parent | ||||||||||||||||||||||||||||||||||
| 345 | 39 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_parent: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 346 | 39 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 347 | 39 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||
| 349 | 39 | my $parent = $context->getParentNode; | |||||||||||||||||||||||||||||||||
| 350 | 38 | ▶ | return( $results ) unless( $parent ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 351 | 38 | ▶ | if( $self->node_test( $parent ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||
| 353 | 38 | $results->push( $parent ); | |||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||
| 357 | sub axis_preceding | ||||||||||||||||||||||||||||||||||
| 358 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_preceding: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 359 | 3 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 360 | 3 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||
| 362 | 3 | ▶ | my $elt = $context->getPreviousSibling || _previous_sibling_of_an_ancestor_of( $context ); | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
$context->getPreviousSibling || _previous_sibling_of_an_ancestor_of($context)
MC/DC0%0/2
$context->getPreviousSibling || _previous_sibling_of_an_ancestor_of($context)
$context->getPreviousSibling
_previous_sibling_of_an_ancestor_of($context)
Truth table33%1/3
A || B
A= $context->getPreviousSiblingB= _previous_sibling_of_an_ancestor_of($context)
| |||||||||||||||||||||||||||||||||||
| 363 | 3 | ▶ | while( $elt ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 364 | { | ||||||||||||||||||||||||||||||||||
| 365 | 18 | ▶ | if( $self->node_test( $elt ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||||||||
| 367 | 6 | $results->push( $elt ); | |||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||
| 369 | 18 | ▶ | $elt = $elt->getLastChild || $elt->getPreviousSibling || _previous_sibling_of_an_ancestor_of( $elt ); | ||||||||||||||||||||||||||||||||
|
Condition100%6/6
$elt->getLastChild || $elt->getPreviousSibling || _previous_sibling_of_an_ancestor_of($elt)
$elt->getLastChild or $elt->getPreviousSibling
MC/DC100%3/3
$elt->getLastChild || $elt->getPreviousSibling || _previous_sibling_of_an_ancestor_of($elt)
$elt->getLastChild
$elt->getPreviousSibling
_previous_sibling_of_an_ancestor_of($elt)
Truth table100%4/4
A or B || C
A= $elt->getLastChildB= $elt->getPreviousSiblingC= _previous_sibling_of_an_ancestor_of($elt)
| |||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||
| 373 | sub axis_preceding_sibling | ||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_preceding_sibling: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 375 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 376 | 0 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | while( $context = $context->getPreviousSibling ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | if( $self->node_test( $context ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 380 | { | ||||||||||||||||||||||||||||||||||
| 381 | 0 | $results->push( $context ); | |||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||
| 386 | sub axis_self | ||||||||||||||||||||||||||||||||||
| 387 | 82 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
axis_self: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 388 | 82 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 389 | 82 | my( $context, $results ) = @_; | |||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||
| 391 | 82 | ▶ | if( $self->node_test( $context ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||
| 393 | 82 | $results->push( $context ); | |||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||
| 397 | sub evaluate | ||||||||||||||||||||||||||||||||||
| 398 | 359 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 399 | 359 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 400 | # context nodeset | ||||||||||||||||||||||||||||||||||
| 401 | 359 | my $from = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||
| 403 | 359 | ▶ | if( $from && !$from->isa( 'HTML::Object::XPath::NodeSet' ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$from and not $from->isa("HTML::Object::XPath::NodeSet")
MC/DC100%2/2
$from and not $from->isa("HTML::Object::XPath::NodeSet")
$from
not $from->isa("HTML::Object::XPath::NodeSet")
Truth table100%3/3
A and not(B)
A= $fromB= not $from->isa("HTML::Object::XPath::NodeSet")
| |||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||
| 405 | 3 | my $from_nodeset = $self->new_nodeset(); | |||||||||||||||||||||||||||||||||
| 406 | 3 | $from_nodeset->push( $from ); | |||||||||||||||||||||||||||||||||
| 407 | 3 | $from = $from_nodeset; | |||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||
| 409 | # warn "Step::evaluate called with ", $from->size, " length nodeset\n"; | ||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||
| 411 | 359 | my $saved_context = $self->{pp}->_get_context_set; | |||||||||||||||||||||||||||||||||
| 412 | 359 | my $saved_pos = $self->{pp}->_get_context_pos; | |||||||||||||||||||||||||||||||||
| 413 | 359 | $self->{pp}->_set_context_set( $from ); | |||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||
| 415 | 359 | my $initial_nodeset = $self->new_nodeset(); | |||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||
| 417 | # See spec section 2.1, paragraphs 3,4,5: | ||||||||||||||||||||||||||||||||||
| 418 | # The node-set selected by the location step is the node-set | ||||||||||||||||||||||||||||||||||
| 419 | # that results from generating an initial node set from the | ||||||||||||||||||||||||||||||||||
| 420 | # axis and node-test, and then filtering that node-set by | ||||||||||||||||||||||||||||||||||
| 421 | # each of the predicates in turn. | ||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||
| 423 | # Make each node in the nodeset be the context node, one by one | ||||||||||||||||||||||||||||||||||
| 424 | 359 | ▶ | for( my $i = 1; $i <= $from->size; $i++ ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||||||||
| 426 | 850 | $self->{pp}->_set_context_pos( $i ); | |||||||||||||||||||||||||||||||||
| 427 | # Capture the intermediate NodeSet in a lexical variable and release | ||||||||||||||||||||||||||||||||||
| 428 | # it immediately after appending its nodes to $initial_nodeset. | ||||||||||||||||||||||||||||||||||
| 429 | # Without this, the temporary NodeSet returned by evaluate_node() | ||||||||||||||||||||||||||||||||||
| 430 | # would stay alive until the end of the for() scope, causing | ||||||||||||||||||||||||||||||||||
| 431 | # accumulated memory pressure when $from is large (e.g. after a | ||||||||||||||||||||||||||||||||||
| 432 | # descendant-or-self step that returns every node in the document). | ||||||||||||||||||||||||||||||||||
| 433 | { | ||||||||||||||||||||||||||||||||||
| 434 | 850 | my $tmp = $self->evaluate_node( $from->get_node( $i ) ); | |||||||||||||||||||||||||||||||||
| 435 | 847 | $initial_nodeset->append( $tmp ); | |||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||
| 439 | # warn "Step::evaluate initial nodeset size: ", $initial_nodeset->size, "\n"; | ||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||
| 441 | 356 | $self->{pp}->_set_context_set( $saved_context ); | |||||||||||||||||||||||||||||||||
| 442 | 356 | $self->{pp}->_set_context_pos( $saved_pos ); | |||||||||||||||||||||||||||||||||
| 443 | 356 | return( $initial_nodeset ); | |||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||
| 446 | # Evaluate the step against a particular node | ||||||||||||||||||||||||||||||||||
| 447 | sub evaluate_node | ||||||||||||||||||||||||||||||||||
| 448 | 850 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
evaluate_node: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 449 | 850 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 450 | 850 | my $context = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 451 | # warn "Evaluate node: $self->{axis}\n"; | ||||||||||||||||||||||||||||||||||
| 452 | # warn "Node: ", $context->[node_name], "\n"; | ||||||||||||||||||||||||||||||||||
| 453 | 850 | my $method = $self->{axis_method}; | |||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||
| 455 | 850 | my $results = $self->new_nodeset(); | |||||||||||||||||||||||||||||||||
| 456 | 14 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 457 | 850 | eval{ $self->$method( $context, $results ); }; | |||||||||||||||||||||||||||||||||
| 458 | 850 | ▶ | if( $@ ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 459 | { | ||||||||||||||||||||||||||||||||||
| 460 | 3 | die( "axis $method not implemented [$@]\n" ); | |||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||
| 463 | # warn("results: ", join('><', map {$_->string_value} @$results), "\n"); | ||||||||||||||||||||||||||||||||||
| 464 | # filter initial nodeset by each predicate | ||||||||||||||||||||||||||||||||||
| 465 | 847 | foreach my $predicate ( @{$self->{predicates}} ) | |||||||||||||||||||||||||||||||||
| 466 | { | ||||||||||||||||||||||||||||||||||
| 467 | 462 | $results = $self->filter_by_predicate( $results, $predicate ); | |||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||
| 469 | 847 | return( $results ); | |||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||
| 472 | sub filter_by_predicate | ||||||||||||||||||||||||||||||||||
| 473 | 462 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
filter_by_predicate: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 474 | 462 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 475 | 462 | my( $nodeset, $predicate ) = @_; | |||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||
| 477 | # See spec section 2.4, paragraphs 2 & 3: | ||||||||||||||||||||||||||||||||||
| 478 | # For each node in the node-set to be filtered, the predicate Expr | ||||||||||||||||||||||||||||||||||
| 479 | # is evaluated with that node as the context node, with the number | ||||||||||||||||||||||||||||||||||
| 480 | # of nodes in the node set as the context size, and with the | ||||||||||||||||||||||||||||||||||
| 481 | # proximity position of the node in the node set with respect to | ||||||||||||||||||||||||||||||||||
| 482 | # the axis as the context position. | ||||||||||||||||||||||||||||||||||
| 483 | # use ref because nodeset has a bool context | ||||||||||||||||||||||||||||||||||
| 484 | 462 | ▶ | if( !ref( $nodeset ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 485 | { | ||||||||||||||||||||||||||||||||||
| 486 | 0 | die( "No nodeset!!!" ); | |||||||||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||
| 489 | # warn "Filter by predicate: $predicate\n"; | ||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||
| 491 | 462 | my $newset = $self->new_nodeset(); | |||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||
| 493 | 462 | ▶ | for( my $i = 1; $i <= $nodeset->size; $i++ ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 494 | { | ||||||||||||||||||||||||||||||||||
| 495 | # set context set each time 'cos a loc-path in the expr could change it | ||||||||||||||||||||||||||||||||||
| 496 | 171 | $self->{pp}->_set_context_set( $nodeset ); | |||||||||||||||||||||||||||||||||
| 497 | 171 | $self->{pp}->_set_context_pos( $i ); | |||||||||||||||||||||||||||||||||
| 498 | 171 | my $result = $predicate->evaluate( $nodeset->get_node( $i ) ); | |||||||||||||||||||||||||||||||||
| 499 | 171 | ▶ | if( $result->isa( 'HTML::Object::XPath::Boolean' ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 500 | { | ||||||||||||||||||||||||||||||||||
| 501 | 138 | ▶ | if( $result->value ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||||||||
| 503 | 47 | $newset->push( $nodeset->get_node( $i ) ); | |||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||
| 506 | elsif( $result->isa( 'HTML::Object::XPath::Number' ) ) | ||||||||||||||||||||||||||||||||||
| 507 | { | ||||||||||||||||||||||||||||||||||
| 508 | 17 | ▶ | if( $result->value == $i ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 509 | { | ||||||||||||||||||||||||||||||||||
| 510 | 14 | $newset->push( $nodeset->get_node( $i ) ); | |||||||||||||||||||||||||||||||||
| 511 | 14 | last; | |||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||
| 514 | else | ||||||||||||||||||||||||||||||||||
| 515 | { | ||||||||||||||||||||||||||||||||||
| 516 | 16 | ▶ | if( $result->to_boolean->value ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 517 | { | ||||||||||||||||||||||||||||||||||
| 518 | 10 | $newset->push( $nodeset->get_node( $i ) ); | |||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||
| 522 | 462 | return( $newset ); | |||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | sub literal { return( shift->_set_get_scalar( 'literal', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
literal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||
| 527 | 1674 | ▶ | sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
new_nodeset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||
| 529 | sub node_test | ||||||||||||||||||||||||||||||||||
| 530 | 2184 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
node_test: called CC=25 SCAR=48.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 531 | 2184 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 532 | 2184 | my $node = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 533 | 2184 | my $test_types = [qw( TEST_QNAME TEST_NCWILD TEST_ANY TEST_ATTR_QNAME TEST_ATTR_NCWILD TEST_ATTR_ANY TEST_NT_COMMENT TEST_NT_TEXT TEST_NT_PI TEST_NT_NODE )]; | |||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||
| 535 | # if node passes test, return true | ||||||||||||||||||||||||||||||||||
| 536 | 2184 | my $test = $self->{test}; | |||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||
| 538 | 2184 | ▶ | return(1) if( $test == TEST_NT_NODE ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||
| 540 | 1631 | ▶ | if( $test == TEST_ANY ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 541 | { | ||||||||||||||||||||||||||||||||||
| 542 | 220 | ▶ | return(1) if( $node->isElementNode && defined( $node->getName ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$node->isElementNode and defined $node->getName
MC/DC50%1/2
$node->isElementNode and defined $node->getName
$node->isElementNode
defined $node->getName
Truth table66%2/3
A and B
A= $node->isElementNodeB= defined $node->getName
| |||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||
| 545 | # local $^W; | ||||||||||||||||||||||||||||||||||
| 546 | 1482 | ▶ | if( $test == TEST_NCWILD ) | ||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||
| 547 | { | ||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | return unless( $node->isElementNode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 549 | 0 | return( $self->_match_ns( $node ) ); | |||||||||||||||||||||||||||||||||
| 550 | } | ||||||||||||||||||||||||||||||||||
| 551 | elsif( $test == TEST_QNAME ) | ||||||||||||||||||||||||||||||||||
| 552 | { | ||||||||||||||||||||||||||||||||||
| 553 | 1411 | ▶ | return unless( $node->isElementNode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 554 | 852 | ▶ | if( $self->{literal} =~ /:/ || $self->{pp}->{strict_namespaces} ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->{"literal"} =~ /:/ or $self->{"pp"}{"strict_namespaces"}
MC/DC0%0/2
$self->{"literal"} =~ /:/ or $self->{"pp"}{"strict_namespaces"}
$self->{"literal"} =~ /:/
$self->{"pp"}{"strict_namespaces"}
Truth table33%1/3
A or B
A= $self->{"literal"} =~ /:/B= $self->{"pp"}{"strict_namespaces"}
| |||||||||||||||||||||||||||||||||||
| 555 | { | ||||||||||||||||||||||||||||||||||
| 556 | 0 | my( $prefix, $name ) = _name2prefix_and_local_name( $self->{literal} ); | |||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | return(1) if( ( $name eq $node->getLocalName ) && $self->_match_ns( $node ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq $node->getLocalName and $self->_match_ns($node)
MC/DC0%0/2
$name eq $node->getLocalName and $self->_match_ns($node)
$name eq $node->getLocalName
$self->_match_ns($node)
Truth table0%0/3
A and B
A= $name eq $node->getLocalNameB= $self->_match_ns($node)
| |||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||
| 559 | else | ||||||||||||||||||||||||||||||||||
| 560 | { | ||||||||||||||||||||||||||||||||||
| 561 | 852 | ▶ | return(1) if( $node->getName eq $self->{literal} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||
| 564 | elsif( $test == TEST_NT_TEXT ) | ||||||||||||||||||||||||||||||||||
| 565 | { | ||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | return(1) if( $node->isTextNode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||
| 568 | elsif( $test == TEST_NT_COMMENT ) | ||||||||||||||||||||||||||||||||||
| 569 | { | ||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | return(1) if( $node->isCommentNode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||
| 572 | ▶ | elsif( $test == TEST_NT_PI && !$self->{literal} ) | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
$test == 8 and not $self->{"literal"}
MC/DC0%0/2
$test == 8 and not $self->{"literal"}
$test == 8
not $self->{"literal"}
Truth table33%1/3
A and not(B)
A= $test == 8B= not $self->{"literal"}
| |||||||||||||||||||||||||||||||||||
| 573 | { | ||||||||||||||||||||||||||||||||||
| 574 | 0 | ▶ | return(1) if( $node->isPINode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||
| 576 | elsif( $test == TEST_NT_PI ) | ||||||||||||||||||||||||||||||||||
| 577 | { | ||||||||||||||||||||||||||||||||||
| 578 | 0 | ▶ | return unless( $node->isPINode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | if( my $val = $self->{literal}->value ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 580 | { | ||||||||||||||||||||||||||||||||||
| 581 | 0 | ▶ | return(1) if( $node->getTarget eq $val ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||
| 583 | else | ||||||||||||||||||||||||||||||||||
| 584 | { | ||||||||||||||||||||||||||||||||||
| 585 | 0 | return(1); | |||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||
| 588 | # fallthrough returns false | ||||||||||||||||||||||||||||||||||
| 589 | 764 | return; | |||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||
| 592 | 7 | ▶ | sub test { return( shift->_set_get_scalar( 'test', @_ ) ); } | ||||||||||||||||||||||||||||||||
|
Subroutine
test: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||
| 594 | sub test_attribute | ||||||||||||||||||||||||||||||||||
| 595 | 433 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
test_attribute: called CC=10 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 596 | 433 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 597 | 433 | my $node = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 598 | 433 | my $test = $self->{test}; | |||||||||||||||||||||||||||||||||
| 599 | 433 | ▶ | return(1) if( ( $test == TEST_ATTR_ANY ) || ( $test == TEST_NT_NODE ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$test == 5 or $test == 9
MC/DC50%1/2
$test == 5 or $test == 9
$test == 5
$test == 9
Truth table66%2/3
A or B
A= $test == 5B= $test == 9
| |||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||
| 601 | 357 | ▶ | if( $test == TEST_ATTR_NCWILD ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 602 | { | ||||||||||||||||||||||||||||||||||
| 603 | 0 | ▶ | return(1) if( $self->_match_ns( $node ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||
| 605 | elsif( $test == TEST_ATTR_QNAME ) | ||||||||||||||||||||||||||||||||||
| 606 | { | ||||||||||||||||||||||||||||||||||
| 607 | 357 | ▶ | if( $self->{literal} =~ /:/ ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 608 | { | ||||||||||||||||||||||||||||||||||
| 609 | 0 | my( $prefix, $name ) = _name2prefix_and_local_name( $self->{literal} ); | |||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | return(1) if( ( $name eq $node->getLocalName ) && ( $self->_match_ns( $node ) ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name eq $node->getLocalName and $self->_match_ns($node)
MC/DC0%0/2
$name eq $node->getLocalName and $self->_match_ns($node)
$name eq $node->getLocalName
$self->_match_ns($node)
Truth table0%0/3
A and B
A= $name eq $node->getLocalNameB= $self->_match_ns($node)
| |||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||
| 612 | else | ||||||||||||||||||||||||||||||||||
| 613 | { | ||||||||||||||||||||||||||||||||||
| 614 | 357 | ▶ | return(1) if( $node->getName eq $self->{literal} ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||
| 616 | } | ||||||||||||||||||||||||||||||||||
| 617 | # fallthrough returns false | ||||||||||||||||||||||||||||||||||
| 618 | 246 | return; | |||||||||||||||||||||||||||||||||
| 619 | } | ||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||
| 621 | sub test_namespace | ||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
test_namespace: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 623 | 0 | my $self = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 624 | 0 | my $node = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 625 | # Not sure if this is correct. The spec seems very unclear on what | ||||||||||||||||||||||||||||||||||
| 626 | # constitutes a namespace test... bah! | ||||||||||||||||||||||||||||||||||
| 627 | 0 | my $test = $self->{test}; | |||||||||||||||||||||||||||||||||
| 628 | # True for all nodes of principal type | ||||||||||||||||||||||||||||||||||
| 629 | 0 | ▶ | return(1) if( $test == TEST_ANY ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | if( $test == TEST_ANY ) | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 632 | { | ||||||||||||||||||||||||||||||||||
| 633 | 0 | return(1); | |||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||
| 635 | elsif( $self->{literal} eq $node->getExpanded ) | ||||||||||||||||||||||||||||||||||
| 636 | { | ||||||||||||||||||||||||||||||||||
| 637 | 0 | return(1); | |||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||
| 639 | 0 | return; | |||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||
| 642 | sub _class_for | ||||||||||||||||||||||||||||||||||
| 643 | 1674 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_class_for: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||
| 644 | 1674 | my( $self, $mod ) = @_; | |||||||||||||||||||||||||||||||||
| 645 | 1674 | eval( "require ${BASE_CLASS}\::${mod};" ); | |||||||||||||||||||||||||||||||||
| 646 | 1674 | ▶ | die( $@ ) if( $@ ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 647 | # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG; | ||||||||||||||||||||||||||||||||||
| 648 | 1674 | ▶ | eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) ); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$HTML::Object::XPath::Step::DEBUG // 0
MC/DC0%0/1
$HTML::Object::XPath::Step::DEBUG // 0
$HTML::Object::XPath::Step::DEBUG
Truth table50%1/2
A
A= $HTML::Object::XPath::Step::DEBUG
| |||||||||||||||||||||||||||||||||||
| 649 | 1674 | return( "${BASE_CLASS}::${mod}" ); | |||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||
| 652 | sub _match_ns | ||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_match_ns: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||
| 654 | 0 | my( $self, $node ) = @_; | |||||||||||||||||||||||||||||||||
| 655 | 0 | my $pp = $self->{pp}; | |||||||||||||||||||||||||||||||||
| 656 | 0 | my $prefix = _name2prefix( $self->{literal} ); | |||||||||||||||||||||||||||||||||
| 657 | 0 | my( $match_ns, $node_ns ); | |||||||||||||||||||||||||||||||||
| 658 | 0 | ▶ | if( $pp->{uses_namespaces} || $pp->{strict_namespaces} ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$pp->{"uses_namespaces"} or $pp->{"strict_namespaces"}
MC/DC0%0/2
$pp->{"uses_namespaces"} or $pp->{"strict_namespaces"}
$pp->{"uses_namespaces"}
$pp->{"strict_namespaces"}
Truth table0%0/3
A or B
A= $pp->{"uses_namespaces"}B= $pp->{"strict_namespaces"}
| |||||||||||||||||||||||||||||||||||
| 659 | { | ||||||||||||||||||||||||||||||||||
| 660 | 0 | $match_ns = $pp->get_namespace( $prefix ); | |||||||||||||||||||||||||||||||||
| 661 | 0 | ▶ | if( $match_ns || $pp->{strict_namespaces} ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$match_ns or $pp->{"strict_namespaces"}
MC/DC0%0/2
$match_ns or $pp->{"strict_namespaces"}
$match_ns
$pp->{"strict_namespaces"}
Truth table0%0/3
A or B
A= $match_nsB= $pp->{"strict_namespaces"}
| |||||||||||||||||||||||||||||||||||
| 662 | { | ||||||||||||||||||||||||||||||||||
| 663 | 0 | $node_ns = $node->getNamespace->getValue; | |||||||||||||||||||||||||||||||||
| 664 | } | ||||||||||||||||||||||||||||||||||
| 665 | # non-standard behaviour: if the query prefix is not declared | ||||||||||||||||||||||||||||||||||
| 666 | # compare the 2 prefixes | ||||||||||||||||||||||||||||||||||
| 667 | else | ||||||||||||||||||||||||||||||||||
| 668 | { | ||||||||||||||||||||||||||||||||||
| 669 | 0 | $match_ns = $prefix; | |||||||||||||||||||||||||||||||||
| 670 | 0 | $node_ns = _name2prefix( $node->getName ); | |||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||
| 673 | else | ||||||||||||||||||||||||||||||||||
| 674 | { | ||||||||||||||||||||||||||||||||||
| 675 | 0 | $match_ns = $prefix; | |||||||||||||||||||||||||||||||||
| 676 | 0 | $node_ns = _name2prefix( $node->getName ); | |||||||||||||||||||||||||||||||||
| 677 | } | ||||||||||||||||||||||||||||||||||
| 678 | 0 | return( $match_ns eq $node_ns ); | |||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||
| 681 | sub _name2prefix | ||||||||||||||||||||||||||||||||||
| 682 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_name2prefix: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 683 | 0 | my $name = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 684 | 0 | ▶ | if( $name =~ m{^(.*?):} ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 685 | { | ||||||||||||||||||||||||||||||||||
| 686 | 0 | return( $1 ); | |||||||||||||||||||||||||||||||||
| 687 | } | ||||||||||||||||||||||||||||||||||
| 688 | else | ||||||||||||||||||||||||||||||||||
| 689 | { | ||||||||||||||||||||||||||||||||||
| 690 | 0 | return( '' ); | |||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||
| 692 | } | ||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||
| 694 | sub _name2prefix_and_local_name | ||||||||||||||||||||||||||||||||||
| 695 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_name2prefix_and_local_name: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 696 | 0 | my $name = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 697 | 0 | ▶ | return( $name =~ /:/ ? split( ':', $name, 2 ) : ( '', $name ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||
| 700 | sub _next_sibling_of_an_ancestor_of | ||||||||||||||||||||||||||||||||||
| 701 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_next_sibling_of_an_ancestor_of: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||
| 702 | 10 | my $elt = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 703 | # NOTE: return 0 instead of undef ? | ||||||||||||||||||||||||||||||||||
| 704 | 10 | ▶ | $elt = $elt->getParentNode || return; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$elt->getParentNode || (return)
MC/DC0%0/1
$elt->getParentNode || (return)
$elt->getParentNode
Truth table50%1/2
A
A= $elt->getParentNode
| |||||||||||||||||||||||||||||||||||
| 705 | 10 | my $next_elt; | |||||||||||||||||||||||||||||||||
| 706 | 10 | ▶ | while( !( $next_elt= $elt->getNextSibling ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 707 | { | ||||||||||||||||||||||||||||||||||
| 708 | 15 | $elt= $elt->getParentNode; | |||||||||||||||||||||||||||||||||
| 709 | 15 | ▶ | return unless( $elt && $elt->can( 'getNextSibling' ) ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$elt and $elt->can("getNextSibling")
MC/DC50%1/2
$elt and $elt->can("getNextSibling")
$elt
$elt->can("getNextSibling")
Truth table66%2/3
A and B
A= $eltB= $elt->can("getNextSibling")
| |||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||
| 711 | 5 | return( $next_elt ); | |||||||||||||||||||||||||||||||||
| 712 | } | ||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||
| 714 | sub _previous_sibling_of_an_ancestor_of | ||||||||||||||||||||||||||||||||||
| 715 | 6 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
_previous_sibling_of_an_ancestor_of: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||
| 716 | 6 | my $elt = shift( @_ ); | |||||||||||||||||||||||||||||||||
| 717 | # NOTE: Should we return 0 instead of undef ? | ||||||||||||||||||||||||||||||||||
| 718 | 6 | ▶ | $elt = $elt->getParentNode || return; | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
$elt->getParentNode || (return)
MC/DC0%0/1
$elt->getParentNode || (return)
$elt->getParentNode
Truth table50%1/2
A
A= $elt->getParentNode
| |||||||||||||||||||||||||||||||||||
| 719 | 6 | my $next_elt; | |||||||||||||||||||||||||||||||||
| 720 | 6 | ▶ | while( !( $next_elt = $elt->getPreviousSibling ) ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 721 | { | ||||||||||||||||||||||||||||||||||
| 722 | 6 | $elt = $elt->getParentNode; | |||||||||||||||||||||||||||||||||
| 723 | # so we do not have to write a getPreviousSibling | ||||||||||||||||||||||||||||||||||
| 724 | 6 | ▶ | return unless( $elt->getParentNode ); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||
| 726 | 3 | return( $next_elt ); | |||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||
| 729 | 14 | 1; | |||||||||||||||||||||||||||||||||
| 730 | # NOTE: POD | ||||||||||||||||||||||||||||||||||
| 731 | __END__ | ||||||||||||||||||||||||||||||||||