| 1 | # $Id: Iterators.pm,v 2.2 2007-01-02 22:03:22 pajas Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package XML::XSH2::Iterators; | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 8 | $VERSION='2.2.10'; # VERSION TEMPLATE | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | #namespace ??? | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | #attribute ?? | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub create_iterator { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_iterator: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | my ($class,$node,$axis,$filter)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 0 | my $iterator; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | die "Unsupported or unknown axis $axis\n" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | unless $class->can("iterate_$axis"); | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | ▶ | if ($class->can("init_$axis")) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | $node=&{"init_$axis"}($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return undef unless defined $node; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | $iterator= XML::XSH2::FilteredIterator->new($node, $filter); | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | $iterator->iterator_function(\&{"iterate_$axis"}); | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $iterator->first_filtered() || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | return $iterator; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub iterate_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_self: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return undef; # the most trivial iterator :-) | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub init_child { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_child: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $node->firstChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub iterate_child { # iteration must start at the first child! | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_child: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ($iter, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return $iter->{CURRENT}->previousSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return $iter->{CURRENT}->nextSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub init_following_sibling { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_following_sibling: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | return $node->nextSibling(); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub iterate_following_sibling { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_following_sibling: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ($iter, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($iter->{FIRST}->isSameNode( $iter->{CURRENT}->previousSibling )) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return $iter->{CURRENT}->previousSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | return $iter->{CURRENT}->nextSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub init_preceding_sibling { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_preceding_sibling: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return $node->nextSibling(); | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub iterate_preceding_sibling { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_preceding_sibling: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my ($iter, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | if ($iter->{FIRST}->isSameNode( $iter->{CURRENT}->nextSibling )) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | return $iter->{CURRENT}->nextSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | return $iter->{CURRENT}->previousSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub iterate_ancestor_or_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_ancestor_or_self: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ($iter, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $node = undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return undef if $iter->{CURRENT}->isSameNode( $iter->{FIRST} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $node=$iter->{FIRST}; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | while ($node->parentNode and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$node->parentNode and not $node->parentNode->isSameNode($iter->{"CURRENT"})
MC/DC0%0/2
$node->parentNode and not $node->parentNode->isSameNode($iter->{"CURRENT"})
$node->parentNode
not $node->parentNode->isSameNode($iter->{"CURRENT"})
Truth table0%0/3
A and not(B)
A= $node->parentNodeB= not $node->parentNode->isSameNode($iter->{"CURRENT"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | not($node->parentNode->isSameNode($iter->{CURRENT}))) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $node=$node->parentNode; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 92 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return $iter->{CURRENT}->parentNode; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub init_ancestor { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_ancestor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | return $node->parentNode(); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | *iterate_ancestor = *iterate_ancestor_or_self; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 8 | *init_parent = *init_ancestor; | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | *iterate_parent = *iterate_ancestor_or_self; | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub iterate_descendant_or_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_descendant_or_self: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | return undef if $iter->{CURRENT}->isSameNode( $iter->{FIRST} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return get_prev_node($iter->{CURRENT}); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | return get_next_node($iter->{CURRENT},$iter->{FIRST}); | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub init_descendant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_descendant: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | return $node->firstChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub iterate_descendant { # iteration must start at the first child! | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_descendant: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | return undef if $iter->{CURRENT}->isSameNode( $iter->{FIRST} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | return get_prev_node($iter->{CURRENT}); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | return get_next_node($iter->{CURRENT},$iter->{FIRST}->parentNode); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub iterate_following_or_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_following_or_self: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | return undef if $iter->{CURRENT}->isSameNode( $iter->{FIRST} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | return get_prev_node($iter->{CURRENT}); | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return get_next_node($iter->{CURRENT}); | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub iterate_preceding_or_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_preceding_or_self: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $iter = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $dir = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | return undef if $iter->{CURRENT}->isSameNode( $iter->{FIRST} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return get_next_node($iter->{CURRENT}); | |||||||||||||||||||||||||||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | return get_prev_node($iter->{CURRENT}); | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub init_following { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_following: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return get_next_node($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 8 | *iterate_following = *iterate_following_or_self; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub init_preceding { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_preceding: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return get_prev_node($_[0]); | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 8 | *iterate_preceding = *iterate_preceding_or_self; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub init_first_descendant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_first_descendant: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return $_[0]->firstChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub iterate_first_descendant_or_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_first_descendant_or_self: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my ($iter, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ($iter->{FIRST}->isSameNode( $iter->{CURRENT} )) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return $iter->{CURRENT}->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | return $iter->{CURRENT}->firstChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | sub iterate_first_descendant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_first_descendant: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | iterate_first_descendant_or_self(@_); | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | #*iterate_first_descendant = *iterate_first_descendant_or_self; | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub init_last_descendant { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init_last_descendant: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | return $_[0]->lastChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 8 | *iterate_last_descendant = *iterate_last_descendant_or_self; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | sub iterate_last_descendant_or_self { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iterate_last_descendant_or_self: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my ($iter, $dir) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ( $dir < 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | if ($iter->{FIRST}->isSameNode( $iter->{CURRENT} )) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | return $iter->{CURRENT}->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | return $iter->{CURRENT}->lastChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | #STATIC | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | sub get_prev_node { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_prev_node: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my ($node) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ($node->previousSibling) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $node = $node->previousSibling; | |||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | ▶ | if ($node->hasChildNodes) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return $node->lastChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 211 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return $node->parentNode; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | #STATIC | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | sub get_next_node { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_next_node: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | my ($node,$stop) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ( $node->hasChildNodes ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return $node->firstChild; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | while ($node) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | return undef if ($stop and $node->isSameNode($stop) or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$stop and $node->isSameNode($stop) or not $node->parentNode
$stop and $node->isSameNode($stop)
MC/DC0%0/3
$stop and $node->isSameNode($stop) or not $node->parentNode
$stop
$node->isSameNode($stop)
not $node->parentNode
Truth table0%0/5
A and B or not(C)
A= $stopB= $node->isSameNode($stop)C= not $node->parentNode
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | not $node->parentNode); | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | return $node->nextSibling if $node->nextSibling; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $node = $node->parentNode; | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | package XML::XSH2::FilteredIterator; | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 8 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 8 | local $^W=0; # suppress warning with perl5.8.2 | |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 8 | require XML::LibXML::Iterator; | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 8 | ▶ | use base qw(XML::LibXML::Iterator); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my ($class,$node,$filter)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $self = $class->SUPER::new($node); | |||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->{FILTER}=$filter; | |||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | sub filter { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if (@_) { $self->{FILTER}=$_[0]; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | return $self->{FILTER}; | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | sub first_filtered { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_filtered: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | my $filter=$self->filter; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | ▶ | $self->first(@_) || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if (ref($filter) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | while ($self->current() and not &$filter($self->current())) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->current and not &$filter($self->current)
MC/DC0%0/2
$self->current and not &$filter($self->current)
$self->current
not &$filter($self->current)
Truth table0%0/3
A and not(B)
A= $self->currentB= not &$filter($self->current)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | $self->next() || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return $self->current(); | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | sub next { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my $filter=$self->filter; | |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | ▶ | $self->SUPER::next() || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | while ($self->current() and not &$filter($self->current())) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->current and not &$filter($self->current)
MC/DC0%0/2
$self->current and not &$filter($self->current)
$self->current
not &$filter($self->current)
Truth table0%0/3
A and not(B)
A= $self->currentB= not &$filter($self->current)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | $self->SUPER::next() || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | return $self->current(); | |||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | sub prev { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prev: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $self=shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | my ($node)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $filter=$self->filter; | |||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $self->SUPER::prev() || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | ▶ | while ($self->current() and not &$filter($self->current())) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->current and not &$filter($self->current)
MC/DC0%0/2
$self->current and not &$filter($self->current)
$self->current
not &$filter($self->current)
Truth table0%0/3
A and not(B)
A= $self->currentB= not &$filter($self->current)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | ▶ | $self->SUPER::prev() || return undef; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | return $self->current(); | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 8 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||