lib/XML/DOM/Lite/NodeIterator.pm

filter: Statementstmt 13.5% 10 / 74 Branchbran 0.0% 0 / 52 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 4 totaltotal 7.7% 13 / 167 SCAR 68.1
CC
33
Cov
7%
nextNode
380.0
previousNode
182.0
new
6.0
CRAP 910.5
« blib/lib/XML/DOM/Lite/Node.pm ↑ Summary blib/lib/XML/DOM/Lite/NodeIterator.pm »
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
BranchTrueFalseTotal
if (defined $nodeFilter) { } 0 0 0
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
BranchTrueFalseTotal
if $_[1] 0 0 0
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
BranchTrueFalseTotal
if ($self->{'POSITION'} == -1) { } 0 0 0
elsif ($self->{'currentNode'}->childNodes->length) { } 0 0 0
elsif ($self->{'currentNode'}->nextSibling) { } 0 0 0
elsif ($self->{'currentNode'}->parentNode) { } 0 0 0
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
BranchTrueFalseTotal
if ($p and $p->nextSibling == undef and $p != $self->{"root"}) 0 0 0
Condition0%0/6
$p and $p->nextSibling == undef and $p != $self->{"root"}
!ll&&!rl&&r
000
$p and $p->nextSibling == undef
!ll&&!rl&&r
000
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"}
ABCresult
0XX0
10X0
1100
1111
39 0 $p = $p->parentNode;
40 }
41 0 ▶ last unless ($p and $p->nextSibling);
Branch: 1 branch
BranchTrueFalseTotal
unless $p and $p->nextSibling 0 0 0
Condition0%0/3
$p and $p->nextSibling
!ll&&!rl&&r
000
MC/DC0%0/2
$p and $p->nextSibling
$p $p->nextSibling
Truth table0%0/3
A and B
A= $pB= $p->nextSibling
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->filter->{'whatToShow'} & 1 << $self->{'currentNode'}->nodeType - 1) { } 0 0 0
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
BranchTrueFalseTotal
if ($rv == 1) { } 0 0 0
elsif ($rv == 3) { } 0 0 0
elsif ($rv != 2) { } 0 0 0
55 0 return $self->{currentNode};
56 }
57 elsif ($rv == FILTER_SKIP) {
58 0 ▶ if ($self->{currentNode}->nextSibling) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'currentNode'}->nextSibling) { } 0 0 0
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
BranchTrueFalseTotal
if ($p and $p->nextSibling == undef) 0 0 0
Condition0%0/3
$p and $p->nextSibling == undef
!ll&&!rl&&r
000
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
ABresult
0X0
100
111
63 0 $p = $p->parentNode;
64 }
65 0 ▶ last unless ($p and $p->nextSibling);
Branch: 1 branch
BranchTrueFalseTotal
unless $p and $p->nextSibling 0 0 0
Condition0%0/3
$p and $p->nextSibling
!ll&&!rl&&r
000
MC/DC0%0/2
$p and $p->nextSibling
$p $p->nextSibling
Truth table0%0/3
A and B
A= $pB= $p->nextSibling
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->{'POSITION'} == 1) { } 0 0 0
elsif ($self->{'currentNode'}->previousSibling) { } 0 0 0
elsif ($self->{'currentNode'}->parentNode and $self->{'currentNode'}->parentNode != $self->{'root'}) { } 0 0 0
81 # do nothing
82 } elsif ($self->{currentNode}->previousSibling) {
83 0 my $p = $self->{currentNode}->previousSibling;
84 0 ▶ if ($p->childNodes->length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->childNodes->length) { } 0 0 0
85 0 $self->{currentNode} = $p->childNodes->[$p->childNodes->length-1];
86 0 ▶ while ($self->{currentNode}->childNodes->length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"currentNode"}->childNodes->length) 0 0 0
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"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->filter->{'whatToShow'} & 1 << $self->{'currentNode'}->nodeType - 1) { } 0 0 0
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
BranchTrueFalseTotal
if ($rv == 1) { } 0 0 0
elsif ($rv == 3) { } 0 0 0
elsif ($rv != 2) { } 0 0 0
106 0 return $self->{currentNode};
107 }
108 elsif ($rv == FILTER_SKIP) {
109 0 ▶ if ($self->{currentNode}->previousSibling) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'currentNode'}->previousSibling) { } 0 0 0
elsif ($self->{'currentNode'}->parentNode) { } 0 0 0
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;
« blib/lib/XML/DOM/Lite/Node.pm ↑ Summary blib/lib/XML/DOM/Lite/NodeIterator.pm »