lib/XML/XMetaL/Utilities/Iterator.pm

filter: Statementstmt 26.7% 19 / 71 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 35.2% 6 / 17 Podpod 66.6% 2 / 3 totaltotal 19.4% 27 / 139 CC 20 SCAR 39.7
CC
20
Cov
17%
_find_next_node
132.0
new
56.0
_traverse_tree_upwards_recursively
12.0
CRAP 53.1
↑ Summary lib/XML/XMetaL.pm »
1 package XML::XMetaL::Utilities::Iterator;
2
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Hash::Util qw(lock_keys);
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 2 ▶use constant TRUE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use constant FALSE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 0 ▶sub new {
Subroutine new: not called CC=7 SCAR=40.3
Pod undocumented
13 0 my ($class, %args) = @_;
14 0 my $self;
15 0 eval {
16 0 lock_keys(%args, qw(-domnode -filter));
17 die "-domnode argument is missing or not a DOM node type"
18 0 ▶ unless $args{-domnode}->{nodeType};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"-domnode"}{"nodeType"} 0 0 0
19 die "-filter argument is missing, or is not a subclass of XML::XMetaL::Utilities::Filter::Base"
20 0 ▶ unless $args{-filter}->isa('XML::XMetaL::Utilities::Filter::Base');
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"-filter"}->isa("XML::XMetaL::Utilities::Filter::Base") 0 0 0
21 $self = bless {
22 _next_node => $args{-domnode} || croak("-domnode parameter missing or undefined"),
23 _filter => $args{-filter},
24 0 ▶ _depth => 0,
Condition0%0/5
$args{'-domnode'} || croak('-domnode parameter missing or undefined')
l!l
00
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/1
$args{'-domnode'} || croak('-domnode parameter missing or undefined')
$args{'-domnode'}
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/2
A
A= $args{'-domnode'}
Aresult
11
00
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
25 }, ref($class) || $class;
26 0 lock_keys(%$self, keys %$self);
27 0 my $next_node = $self->_get_next_node();
28 0 my $filter = $self->_get_filter();
29 0 ▶ unless ($filter->accept($next_node)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($filter->accept($next_node)) 0 0 0
30 0 $next_node = $self->_find_next_node($next_node);
31 0 $self->_set_next_node($next_node);
32 }
33 };
34 0 ▶ croak $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
35 0 return $self;
36 }
37
38 0 ▶sub _get_next_node {$_[0]->{_next_node}}
Subroutine _get_next_node: not called CC=1 SCAR=6.9
39 0 ▶sub _set_next_node {$_[0]->{_next_node} = $_[1];}
Subroutine _set_next_node: not called CC=1 SCAR=6.9
40
41 0 ▶sub _get_filter {$_[0]->{_filter}}
Subroutine _get_filter: not called CC=1 SCAR=6.9
42
43 0 ▶sub _increment_depth {
Subroutine _increment_depth: not called CC=1 SCAR=6.9
44 0 $_[0]->{_depth}++;
45 #print "depth: ".$_[0]->_get_depth()."\n";
46 }
47 0 ▶sub _decrement_depth {
Subroutine _decrement_depth: not called CC=1 SCAR=6.9
48 0 $_[0]->{_depth}--;
49 #print "depth: ".$_[0]->_get_depth()."\n";
50 }
51
52 0 ▶sub _get_depth {$_[0]->{_depth}}
Subroutine _get_depth: not called CC=1 SCAR=6.9
53
54 0 ▶sub has_next {
Subroutine has_next: not called CC=2 SCAR=17.9
Pod documented
55 0 my ($self) = @_;
56 0 ▶ return $self->_get_next_node() ? TRUE : FALSE;
Branch: 1 branch
BranchTrueFalseTotal
$self->_get_next_node ? : 0 0 0
57 }
58
59 0 ▶sub next {
Subroutine next: not called CC=1 SCAR=6.9
Pod documented
60 0 my ($self) = @_;
61 0 my $current_node = $self->_get_next_node();
62 0 my $next_node = $self->_find_next_node($current_node);
63 0 $self->_set_next_node($next_node);
64 0 return $current_node;
65 }
66
67 0 ▶sub _find_next_node {
Subroutine _find_next_node: not called CC=11 SCAR=48.8
68 0 my ($self, $current_node) = @_;
69 0 ▶ return undef unless $current_node;
Branch: 1 branch
BranchTrueFalseTotal
unless $current_node 0 0 0
70 0 my $child_nodes;
71 my $next_node;
72 0 my $filter = $self->_get_filter();
73
74 0 ▶ if ($current_node->hasChildNodes()) {
Branch: 3 branches
BranchTrueFalseTotal
if ($current_node->hasChildNodes) { } 0 0 0
elsif ($self->_get_depth >= 1 and $current_node->{'nextSibling'}) { } 0 0 0
elsif ($self->_get_depth > 1 and $current_node->{'parentNode'}) { } 0 0 0
75 0 $self->_increment_depth();
76 0 $child_nodes = $current_node->{childNodes};
77 0 $next_node = $child_nodes->item(0);
78 0 ▶ return $next_node if $filter->accept($next_node);
Branch: 1 branch
BranchTrueFalseTotal
if $filter->accept($next_node) 0 0 0
79 ▶ } elsif ($self->_get_depth() >= 1 && $current_node->{nextSibling}) {
Condition0%0/3
$self->_get_depth >= 1 and $current_node->{"nextSibling"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_get_depth >= 1 and $current_node->{"nextSibling"}
$self->_get_depth >= 1 $current_node->{"nextSibling"}
Truth table0%0/3
A and B
A= $self->_get_depth >= 1B= $current_node->{"nextSibling"}
ABresult
0X0
100
111
80 0 $next_node = $current_node->{nextSibling};
81 0 ▶ return $next_node if $filter->accept($next_node);
Branch: 1 branch
BranchTrueFalseTotal
if $filter->accept($next_node) 0 0 0
82 #} elsif ($self->_get_depth() > 1 && $current_node->{parentNode}->{nextSibling}) {
83 # $self->_decrement_depth();
84 # $next_node = $current_node->{parentNode}->{nextSibling};
85 # return $next_node if $filter->accept($next_node);
86 ▶ } elsif ($self->_get_depth() > 1 && $current_node->{parentNode}) {
Condition0%0/3
$self->_get_depth > 1 and $current_node->{"parentNode"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_get_depth > 1 and $current_node->{"parentNode"}
$self->_get_depth > 1 $current_node->{"parentNode"}
Truth table0%0/3
A and B
A= $self->_get_depth > 1B= $current_node->{"parentNode"}
ABresult
0X0
100
111
87 0 $next_node = $self->_traverse_tree_upwards_recursively($current_node);
88 0 ▶ return $next_node if $filter->accept($next_node);
Branch: 1 branch
BranchTrueFalseTotal
if $filter->accept($next_node) 0 0 0
89 }
90
91 0 ▶ if ($next_node) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_node) 0 0 0
92 0 return $self->_find_next_node($next_node);
93 }
94 0 return undef;
95 }
96
97 #sub _traverse_tree_downwards {}
98 #
99 #sub _traverse_tree_sideways {}
100
101 0 ▶sub _traverse_tree_upwards_recursively {
Subroutine _traverse_tree_upwards_recursively: not called CC=3 SCAR=24.8
102 0 my ($self, $current_node) = @_;
103 0 ▶ return undef if $self->_get_depth() < 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_get_depth < 1 0 0 0
104 0 my $parent_node = $current_node->{parentNode};
105 0 my $sibling_of_parent = $parent_node->{nextSibling};
106
107 0 $self->_decrement_depth();
108 0 ▶ if ($sibling_of_parent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sibling_of_parent) { } 0 0 0
109 0 return $sibling_of_parent;
110 } else {
111 0 return $self->_traverse_tree_upwards_recursively($parent_node);
112 }
113 }
114
115 2 1;
116
117 __END__
↑ Summary lib/XML/XMetaL.pm »