DOM/Collection.pm

filter: Statementstmt 94.4% 68 / 72 Branchbran 83.3% 15 / 18 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 94.7% 18 / 19 Podpod 60.0% 3 / 5 totaltotal 90.7% 117 / 129 CC 18 SCAR 14.1
CC
18
Cov
92%
NEXTKEY
8.0
namedItem
6.0
FIRSTKEY
5.6
CRAP 4.1
« DOM/CharacterData.pm ↑ Summary DOM/Element.pm »
1 package HTML::DOM::Collection;
2  
3 26 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 26 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 26 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 26 our $VERSION = '0.058';
9  
10 # Internals: \[$nodelist, $tie]
11  
12 # Field constants:
13 sub nodelist(){0}
14 sub tye(){1}
15 sub seen(){2} # whether this key has been seen
16 sub position(){3} # current (array) position used by NEXTKEY
17 sub ids(){4} # whether we are iterating through ids
18 # Number 5 is taken by ::Options (inside Element/Form.pm).
19 26 ▶{ no warnings 'misc';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 26 undef &nodelist; undef &tye; undef &seen; undef &position;
21 }
22  
23 26 ▶use overload fallback => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
24 39 ▶'%{}' => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
25 39 my $self = shift;
26 $$$self[tye] or
27 39 ▶ weaken(tie %{ $$$self[tye] }, __PACKAGE__, $self),
Branch: 1 branch
BranchTrueFalseTotal
$$self->[1] or builtin::weaken(tie(%{$$$self[1];}, __PACKAGE__, $self)), $$self->[1] 30 9 39
28 $$$self[tye];
29 },
30 26 ▶'@{}' => sub { ${+shift}->[nodelist] };
Subroutine __ANON__: called CC=1 SCAR=0.0
31  
32  
33 180 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 180 bless \[$_[1]], shift;
35 }
36  
37 26 my %NameableElements = map +($_ => 1), qw/
38 a area object param applet input select textarea button frame
39 iframe meta form img map
40 /;
41  
42 25 ▶sub namedItem {
Subroutine namedItem: called CC=6 SCAR=17.9
Pod documented
43 25 my($self, $name) = @_;
44 25 my $list = $$self->[nodelist];
45 25 my $named_elem; my $elem;
46 25 for(0..$list->length - 1) {
47 26 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
48 253 ▶ ($elem = $list->item($_))->id eq $name and return $elem;
Branch: 1 branch
BranchTrueFalseTotal
($elem = $list->item($_))->id eq $name and return $elem 2 251 253
49 251 ▶ exists $NameableElements{$elem->tag} and
Branch: 1 branch
BranchTrueFalseTotal
exists $NameableElements{$elem->tag} and $elem->attr("name") eq $name and $named_elem = $elem 22 229 251
Condition66%2/3
exists $NameableElements{$elem->tag} and $elem->attr("name") eq $name
!ll&&!rl&&r
022922
MC/DC50%1/2
exists $NameableElements{$elem->tag} and $elem->attr("name") eq $name
exists $NameableElements{$elem->tag} $elem->attr("name") eq $name
Truth table66%2/3
A and B
A= exists $NameableElements{$elem->tag}B= $elem->attr("name") eq $name
ABresult
0X0
100
111
50 $elem->attr('name') eq $name and
51 $named_elem = $elem;
52 }
53 $named_elem ||()
54 23 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$named_elem or () 22 1 23
55  
56 # Delegated methosd
57 26 for (qw/length item/) {
58 74 ▶ eval "sub $_ { \${+shift}->[" . nodelist . "]->$_(\@_) }"
Subroutine item: called CC=1 SCAR=0.0
Subroutine length: called CC=1 SCAR=0.0
Pod documented
Pod documented
59 }
60  
61  
62 9 ▶sub TIEHASH { $_[1] }
Subroutine TIEHASH: called CC=1 SCAR=0.0
63 34 ▶sub FETCH { $_[0]->namedItem($_[1]) }
Subroutine FETCH: called CC=1 SCAR=0.0
64 2 ▶sub EXISTS { $_[0]->namedItem($_[1]) } # nodes are true, undef is false
Subroutine EXISTS: called CC=1 SCAR=0.0
65 3 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=5 SCAR=17.2
66 3 my $self = shift;
67 3 (my $guts = $$self)->[seen] = {};
68 3 my($id,$item);
69 3 $guts->[ids] = 1;
70 3 for (0..$self->length - 1) {
71 defined($id = ($item = $self->item($_))->id)
72 2 ▶ and ++$guts->[seen]{$id}, $guts->[position] = $_,
Branch: 1 branch
BranchTrueFalseTotal
defined($id = ($item = $self->item($_))->id) and ++$guts->[2]{$id}, $guts->[3] = $_, (return $id) 2 0 2
73 return($id);
74 }
75 # If none of the items has an id...
76 1 $guts->[ids] = 0;
77 1 for (0..$self->length - 1) {
78 defined($id = ($item = $self->item($_))->attr('name'))
79 0 ▶ and ++$guts->[seen]{$id}, $guts->[position] = $_,
Branch: 1 branch
BranchTrueFalseTotal
defined($id = ($item = $self->item($_))->attr("name")) and ++$guts->[2]{$id}, $guts->[3] = $_, (return $id) 0 0 0
80 return($id);
81 }
82 1 return; # empty list
83 }
84  
85 8 ▶sub NEXTKEY{
Subroutine NEXTKEY: called CC=8 SCAR=20.8
86 8 my $self = shift;
87 8 my $guts = $$self;
88 8 my($id,$item);
89 8 ▶ if($guts->[ids]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($guts->[4]) 6 2 8
90 6 for ($guts->[position]..$self->length - 1) {
91 defined($id = ($item = $self->item($_))->id)
92 13 ▶ and !$guts->[seen]{$id}++
Branch: 1 branch
BranchTrueFalseTotal
defined($id = ($item = $self->item($_))->id) and not $guts->[2]{$id}++ and $guts->[3] = $_, (return $id) 5 8 13
Condition100%3/3
defined($id = ($item = $self->item($_))->id) and not $guts->[2]{$id}++
!ll&&!rl&&r
175
MC/DC100%2/2
defined($id = ($item = $self->item($_))->id) and not $guts->[2]{$id}++
defined($id = ($item = $self->item($_))->id) not $guts->[2]{$id}++
Truth table100%3/3
A and not(B)
A= defined($id = ($item = $self->item($_))->id)B= not $guts->[2]{$id}++
ABresult
0X0
100
111
93 and $guts->[position] = $_,
94 return($id);
95 }
96 }
97 # If we've exhausted all ids...
98 3 $guts->[ids] = 0;
99 3 for (0..$self->length - 1) {
100 defined($id = ($item = $self->item($_))->attr('name'))
101 16 ▶ and !$guts->[seen]{$id}++
Branch: 1 branch
BranchTrueFalseTotal
defined($id = ($item = $self->item($_))->attr("name")) and not $guts->[2]{$id}++ and $guts->[3] = $_, (return $id) 2 14 16
Condition100%3/3
defined($id = ($item = $self->item($_))->attr("name")) and not $guts->[2]{$id}++
!ll&&!rl&&r
1132
MC/DC100%2/2
defined($id = ($item = $self->item($_))->attr("name")) and not $guts->[2]{$id}++
defined($id = ($item = $self->item($_))->attr("name")) not $guts->[2]{$id}++
Truth table100%3/3
A and not(B)
A= defined($id = ($item = $self->item($_))->attr("name"))B= not $guts->[2]{$id}++
ABresult
0X0
100
111
102 and $guts->[position] = $_,
103 return($id);
104 }
105 1 return;
106 }
107  
108 2 ▶sub SCALAR {
Subroutine SCALAR: called CC=1 SCAR=0.0
109 2 defined FIRSTKEY @_;
110 }
111  
112 0 ▶sub DDS_freeze { my $self = shift; delete $$$self[tye]; $self }
Subroutine DDS_freeze: not called CC=1 SCAR=6.9
Pod undocumented
113  
114 26 1
115  
116 __END__
« DOM/CharacterData.pm ↑ Summary DOM/Element.pm »