lib/XML/DOM/Lite/NodeList.pm

filter: Statementstmt 94.4% 34 / 36 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 7 totaltotal 80.3% 49 / 61 SCAR 20.9
CC
8
Cov
89%
nodeIndex
4.1
as_hashref
3.0
new
2.1
CRAP 8.1
« lib/XML/DOM/Lite/Serializer.pm ↑ Summary lib/XML/DOM/Lite/Document.pm »
1 package XML::DOM::Lite::NodeList;
2  
3 =head1 NAME
4  
5 XML::DOM::Lite::NodeList - blessed array ref for containing Node objects
6  
7 =head1 SYNOPSIS
8  
9 $node->childNodes->insertNode($childNode, [$index]);
10 my @removedNodes = $node->childNodes->removeNode($childNode);
11 my $childNode = $node->childNodes->item($index);
12 my $numChilds = $node->childNodes->length;
13  
14 =cut
15  
16 8 ▶use overload '%{}' => \&as_hashref, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 sub new {
19 263 ▶ my ($class, $nodes) = @_;
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
20 263 my $self;
21 263 ▶ if (ref $nodes eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $nodes eq 'ARRAY') { } 263 0 263
22 # take a copy of the array
23 263 $self = bless [ @$nodes ], $class;
24 } else {
25 0 die "usage error, $class must be constructed with an ARRAY ref";
26 }
27 263 return $self;
28 }
29  
30 sub as_hashref {
31 2 ▶ my $self = shift;
Subroutine as_hashref: called CC=3 SCAR=11.1
Pod undocumented
32 2 my $hashref = { };
33 2 foreach my $n (@$self) {
34 2 ▶ $hashref->{$n->nodeName} = ($n->nodeValue ? $n->nodeValue : $n);
Branch: 1 branch
BranchTrueFalseTotal
$n->nodeValue ? : 2 0 2
35 }
36 2 return $hashref;
37 }
38  
39 sub insertNode {
40 80 ▶ my ($self, $node, $index) = @_;
Subroutine insertNode: called CC=2 SCAR=6.9
Pod undocumented
41 80 ▶ if (defined $index) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $index) { } 1 79 80
42 1 splice(@{$self}, $index, 0, $node);
43 } else {
44 79 push(@{$self}, $node);
45 }
46 80 return $node;
47 }
48  
49 sub removeNode {
50 4 ▶ my ($self, $node) = @_;
Subroutine removeNode: called CC=1 SCAR=0.0
Pod undocumented
51 4 return splice (@{$self}, $self->nodeIndex($node), 1);
52 }
53  
54 sub item {
55 21 ▶ my ($self, $index) = @_;
Subroutine item: called CC=1 SCAR=0.0
Pod undocumented
56 21 return $self->[$index];
57 }
58  
59 sub length {
60 145 ▶ my $self = shift;
Subroutine length: called CC=1 SCAR=0.0
Pod undocumented
61 145 return scalar(@$self);
62 }
63  
64 sub nodeIndex {
65 15 ▶ my ($self, $node) = @_;
Subroutine nodeIndex: called CC=4 SCAR=14.1
Pod undocumented
66 15 ▶ die "usage error" unless (scalar(@_) == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ == 2 0 15 15
67 15 my $i = 0;
68 15 foreach (@$self) {
69 21 ▶ return $i if $_ eq $node;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $node 15 6 21
70 6 $i++;
71 }
72 0 return undef;
73 }
74  
75 8 1;
« lib/XML/DOM/Lite/Serializer.pm ↑ Summary lib/XML/DOM/Lite/Document.pm »