DOM/NamedNodeMap.pm

filter: Statementstmt 95.4% 84 / 88 Branchbran 66.6% 8 / 12 Conditioncond 66.6% 4 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 22 / 22 Podpod 0.0% 0 / 6 totaltotal 85.5% 118 / 138 SCAR 23.1
CC
10
Cov
91%
removeNamedItem
3.5
NEXTKEY
3.0
EXISTS
2.1
CRAP 10.1
« DOM/NodeList/Magic.pm ↑ Summary DOM/Event.pm »
1 package HTML::DOM::NamedNodeMap;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶use HTML::DOM::Exception qw'NOT_FOUND_ERR';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use HTML::DOM::_FieldHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 25 our $VERSION = '0.057';
11  
12 25 fieldhashes \my(%a, %h);
13  
14 use overload fallback => 1,
15 '@{}' => sub {
16 7 ▶ my $self = ${+shift};
Subroutine __ANON__: called CC=2 SCAR=7.0
17 7 ▶ $a{$self} ||= do {
Condition66%2/3
$a{$self} ||= do { my $t = []; tie @$t, "HTML::DOM::NamedNodeMap'_atie", $self; $t }
l!l&&r!l&&!r
610
MC/DC0%0/2
$a{$self} ||= do { my $t = []; tie @$t, "HTML::DOM::NamedNodeMap'_atie", $self; $t }
$a{$self} do { my $t = []; tie @$t, "HTML::DOM::NamedNodeMap'_atie", $self; $t }
Truth table66%2/3
A ||= B
A= $a{$self}B= do { my $t = []; tie @$t, "HTML::DOM::NamedNodeMap'_atie", $self; $t }
ABresult
1X1
011
000
18 1 my $t = [];
19 1 tie @$t, __PACKAGE__."'_atie", $self;
20 1 $t
21 };
22 },
23 '%{}' => sub {
24 7 ▶ my $self = ${+shift};
Subroutine __ANON__: called CC=2 SCAR=7.0
25 7 ▶ $h{$self} ||= do {
Condition66%2/3
$h{$self} ||= do { my $t = {}; tie %$t, "HTML::DOM::NamedNodeMap'_htie", $self; $t }
l!l&&r!l&&!r
610
MC/DC0%0/2
$h{$self} ||= do { my $t = {}; tie %$t, "HTML::DOM::NamedNodeMap'_htie", $self; $t }
$h{$self} do { my $t = {}; tie %$t, "HTML::DOM::NamedNodeMap'_htie", $self; $t }
Truth table66%2/3
A ||= B
A= $h{$self}B= do { my $t = {}; tie %$t, "HTML::DOM::NamedNodeMap'_htie", $self; $t }
ABresult
1X1
011
000
26 1 my $t = {};
27 1 tie %$t, __PACKAGE__."'_htie", $self;
28 1 $t
29 };
30 25 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32  
33 # This object stores nothing more than the Element object whose attributes
34 # it purports to hold.
35 sub new { # [0] class [1] element obj
36 8 ▶ my $map = bless \(my $elem = $_[1]), shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
37 8 weaken $$map;
38 8 $map;
39 }
40  
41 sub getNamedItem {
42 4 ▶ ${+shift}->getAttributeNode(shift);
Subroutine getNamedItem: called CC=1 SCAR=0.0
Pod undocumented
43 }
44  
45 sub setNamedItem {
46 2 ▶ ${+shift}->setAttributeNode(shift);
Subroutine setNamedItem: called CC=1 SCAR=0.0
Pod undocumented
47 }
48  
49 sub removeNamedItem {
50 # The spec contradicts itself slightly. It says that null is
51 # returned if no node with such a name exists, but then it says
52 # that a NOT_FOUND_ERR is thrown if no node with such a name
53 # exists. I can't do both.
54 1 ▶ my($elem,$name) = (${+shift},shift);
Subroutine removeNamedItem: called CC=3 SCAR=12.5
Pod undocumented
55 1 my $attr = $elem->attr($name);
56 1 ▶ defined $attr or die HTML::DOM::Exception->new(NOT_FOUND_ERR,
Branch: 1 branch
BranchTrueFalseTotal
defined $attr or die "HTML::DOM::Exception"->new(8, "No attribute named $name exists") 0 1 1
57 "No attribute named $name exists");
58 1 ▶ if(ref $attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $attr) { } 1 0 1
59 1 $elem->attr($name, undef);
60 1 $attr->_element(undef);
61 1 return $attr
62 }
63 else {
64 0 my $new_attr = HTML::DOM::Attr->new($name);
65 0 $new_attr->_set_ownerDocument($elem->ownerDocument);
66 0 $new_attr->value($attr);
67 0 return $new_attr;
68 }
69 }
70  
71 sub item {
72 11 ▶ my $elem = ${+shift};
Subroutine item: called CC=2 SCAR=7.0
Pod undocumented
73 11 my $name = (sort $elem->all_external_attr_names)[shift];
74 11 ▶ defined $name or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $name or return 0 11 11
75 11 $elem->getAttributeNode($name);
76 }
77  
78 sub length {
79 11 ▶ scalar(() = ${$_[0]}-> all_external_attr_names);
Subroutine length: called CC=1 SCAR=0.0
Pod undocumented
80 }
81  
82 package HTML::DOM::NamedNodeMap::_atie;
83  
84 25 our @ISA = "Tie::Array";
85  
86 sub TIEARRAY {
87 1 ▶ require Tie::Array;
Subroutine TIEARRAY: called CC=1 SCAR=0.0
88 1 goto &HTML::DOM'NamedNodeMap'new;
89 }
90  
91 25 *FETCH = *HTML::DOM::NamedNodeMap::item;
92 25 *FETCHSIZE = *HTML::DOM::NamedNodeMap::length;
93 4 ▶sub EXISTS { $_[1] >=0 && $_[1] < &FETCHSIZE }
Subroutine EXISTS: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[1] >= 0 and $_[1] < &FETCHSIZE 4 0 4
94  
95 package HTML::DOM::NamedNodeMap::_htie;
96  
97 25 our @ISA = "Tie::Hash";
98  
99 sub TIEHASH {
100 1 ▶ require Tie::Hash;
Subroutine TIEHASH: called CC=1 SCAR=0.0
101 1 goto &HTML::DOM'NamedNodeMap'new;
102 }
103 25 *STORE = *HTML'DOM'NamedNodeMap'setNamedItem;
104 25 *FETCH = *HTML'DOM'NamedNodeMap'getNamedItem;
105  
106 sub FIRSTKEY {
107 # reset iterator; I don’t *think* any other code uses it.
108 1 ▶ keys %${$_[0]};
Subroutine FIRSTKEY: called CC=1 SCAR=0.0
109 1 goto &NEXTKEY;
110 }
111 sub NEXTKEY {
112 3 ▶ my $elem = ${+shift};
Subroutine NEXTKEY: called CC=3 SCAR=11.0
113 3 ▶ while (defined($_ = each %$elem)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = each %$elem)) 6 1 7
114 6 ▶ return $_ unless /^_/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^_/ 2 4 6
115 }
116 1 return undef;
117 }
118 sub EXISTS {
119 3 ▶ my($elem,$name) = (${+shift},shift);
Subroutine EXISTS: called CC=1 SCAR=0.0
120 3 defined $elem->attr($name);
121 }
122 sub DELETE {
123 1 ▶ my($elem,$name) = (${+shift},shift);
Subroutine DELETE: called CC=1 SCAR=0.0
124 1 $elem->attr($name, undef);
125 }
126 sub CLEAR {
127 1 ▶ my $elem = ${+shift};
Subroutine CLEAR: called CC=2 SCAR=6.9
128 1 $elem->attr($_,undef) for $elem->all_external_attr_names;
129 }
130 25 *SCALAR = *HTML::DOM::NamedNodeMap::length;
131  
132 25 1
« DOM/NodeList/Magic.pm ↑ Summary DOM/Event.pm »