| 1 | package XML::DOM::Lite::NodeIterator; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use XML::DOM::Lite::Constants qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use constant BEFORE => -1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use constant AFTER => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 9 | 0 | ▶ | my ($class, $root, $whatToShow, $nodeFilter) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 11 | root => $root, | ||||||||||||||||||||||||||||||||||||||||||
| 12 | whatToShow => $whatToShow | ||||||||||||||||||||||||||||||||||||||||||
| 13 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | unless (defined $nodeFilter) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | $self->filter({ acceptNode => sub { return FILTER_ACCEPT } }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | $self->filter($nodeFilter); | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | $self->{currentNode} = $root; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | $self->{POSITION} = BEFORE; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub filter { $_[0]->{filter} = $_[1] if $_[1]; $_[0]->{filter} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | sub nextNode { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nextNode: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ($self->{POSITION} == BEFORE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | # do nothing so we test the currentNode | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } elsif ($self->{currentNode}->childNodes->length) { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->{currentNode} = $self->{currentNode}->childNodes->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } elsif ($self->{currentNode}->nextSibling) { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $self->{currentNode} = $self->{currentNode}->nextSibling; | |||||||||||||||||||||||||||||||||||||||||
| 36 | } elsif ($self->{currentNode}->parentNode) { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $p = $self->{currentNode}->parentNode; | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | while ($p and $p->nextSibling == undef and $p != $self->{root}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$p and $p->nextSibling == undef and $p != $self->{"root"}
$p and $p->nextSibling == undef
MC/DC0%0/3
$p and $p->nextSibling == undef and $p != $self->{"root"}
$p
$p->nextSibling == undef
$p != $self->{"root"}
Truth table0%0/4
A and B and C
A= $pB= $p->nextSibling == undefC= $p != $self->{"root"}
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $p = $p->parentNode; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | last unless ($p and $p->nextSibling); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p and $p->nextSibling
MC/DC0%0/2
$p and $p->nextSibling
$p
$p->nextSibling
Truth table0%0/3
A and B
A= $pB= $p->nextSibling
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->{currentNode} = $p->nextSibling; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->{POSITION} = AFTER; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($self->filter->{whatToShow} & (1 << ($self->{currentNode}->nodeType - 1))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $rv = $self->filter->{acceptNode}->($self->{currentNode}); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $rv = FILTER_REJECT; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($rv == FILTER_ACCEPT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | return $self->{currentNode}; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | elsif ($rv == FILTER_SKIP) { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ($self->{currentNode}->nextSibling) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $self->{currentNode} = $self->{currentNode}->nextSibling; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $p = $self->{currentNode}->parentNode; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | while ($p and $p->nextSibling == undef) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p and $p->nextSibling == undef
MC/DC0%0/2
$p and $p->nextSibling == undef
$p
$p->nextSibling == undef
Truth table0%0/3
A and B
A= $pB= $p->nextSibling == undef
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $p = $p->parentNode; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | last unless ($p and $p->nextSibling); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p and $p->nextSibling
MC/DC0%0/2
$p and $p->nextSibling
$p
$p->nextSibling
Truth table0%0/3
A and B
A= $pB= $p->nextSibling
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->{currentNode} = $p->nextSibling; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | elsif ($rv != FILTER_REJECT) { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | die('filter returned unknown value: `'.$rv."'"); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub previousNode { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
previousNode: not called CC=13 SCAR=52.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($self->{POSITION} == AFTER) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | # do nothing | ||||||||||||||||||||||||||||||||||||||||||
| 82 | } elsif ($self->{currentNode}->previousSibling) { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $p = $self->{currentNode}->previousSibling; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ($p->childNodes->length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $self->{currentNode} = $p->childNodes->[$p->childNodes->length-1]; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | while ($self->{currentNode}->childNodes->length) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $self->{currentNode} = $self->{currentNode}->childNodes->[$self->{currentNode}->childNodes->length - 1]; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $self->{currentNode} = $p; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | ▶ | } elsif ($self->{currentNode}->parentNode and $self->{currentNode}->parentNode != $self->{root}) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"currentNode"}->parentNode and $self->{"currentNode"}->parentNode != $self->{"root"}
MC/DC0%0/2
$self->{"currentNode"}->parentNode and $self->{"currentNode"}->parentNode != $self->{"root"}
$self->{"currentNode"}->parentNode
$self->{"currentNode"}->parentNode != $self->{"root"}
Truth table0%0/3
A and B
A= $self->{"currentNode"}->parentNodeB= $self->{"currentNode"}->parentNode != $self->{"root"}
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $self->{currentNode} = $self->{currentNode}->parentNode; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->{POSITION} = BEFORE; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($self->filter->{whatToShow} & (1 << ($self->{currentNode}->nodeType - 1))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $rv = $self->filter->{acceptNode}->($self->{currentNode}); | |||||||||||||||||||||||||||||||||||||||||
| 101 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $rv = FILTER_REJECT; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($rv == FILTER_ACCEPT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | return $self->{currentNode}; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | elsif ($rv == FILTER_SKIP) { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | ▶ | if ($self->{currentNode}->previousSibling) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->{currentNode} = $self->{currentNode}->previousSibling; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } elsif ($self->{currentNode}->parentNode) { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->{currentNode} = $self->{currentNode}->parentNode; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | elsif ($rv != FILTER_REJECT) { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | die('filter returned unknown value: `'.$rv."'"); | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||