blib/lib/XML/LibXML/AttributeHash.pm

filter: Statementstmt 90.2% 74 / 82 Branchbran 78.1% 25 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 4 totaltotal 84.6% 116 / 137 CC 20 SCAR 11.8
CC
20
Cov
87%
NEXTKEY
7.3
CLEAR
6.0
all_keys
4.0
CRAP 3.2
« blib/lib/XML/LibXML/XPathContext.pm ↑ Summary blib/lib/XML/LibXML/NodeList.pm »
1 package XML::LibXML::AttributeHash;
2  
3 69 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 69 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 69 ▶use Scalar::Util qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 69 ▶use Tie::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 69 our @ISA = qw/Tie::Hash/;
8  
9 69 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 69 $VERSION = "2.0210"; # VERSION TEMPLATE: DO NOT CHANGE
11  
12 BEGIN
13 {
14 *__HAS_WEAKEN = defined(&Scalar::Util::weaken)
15 ? sub () { 1 }
16 69 ▶ : sub () { 0 };
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
defined &Scalar::Util::weaken ? : 69 0 69
17 };
18  
19 sub element
20 {
21 24 ▶ return $_[0][0];
Subroutine element: called CC=1 SCAR=0.0
Pod undocumented
22 }
23  
24 sub from_clark
25 {
26 20 ▶ my ($self, $str) = @_;
Subroutine from_clark: called CC=2 SCAR=6.9
Pod undocumented
27 20 ▶ if ($str =~ m! \{ (.+) \} (.+) !x)
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ / \{ (.+) \} (.+) /x) 10 10 20
28 {
29 10 return ($1, $2);
30 }
31 10 return (undef, $str);
32 }
33  
34 sub to_clark
35 {
36 7 ▶ my ($self, $ns, $local) = @_;
Subroutine to_clark: called CC=2 SCAR=6.9
Pod undocumented
37 7 ▶ defined $ns ? "{$ns}$local" : $local;
Branch: 1 branch
BranchTrueFalseTotal
defined $ns ? : 4 3 7
38 }
39  
40 sub all_keys
41 {
42 4 ▶ my ($self, @keys) = @_;
Subroutine all_keys: called CC=4 SCAR=13.9
Pod undocumented
43  
44 4 my $elem = $self->element;
45  
46 4 ▶ foreach my $attr (defined($elem) ? $elem->attributes : ())
Branch: 1 branch
BranchTrueFalseTotal
defined $elem ? : 4 0 4
47 {
48 11 ▶ if (! $attr->isa('XML::LibXML::Namespace'))
Branch: 1 branch
BranchTrueFalseTotal
unless ($attr->isa("XML::LibXML::Namespace")) 7 4 11
49 {
50 7 push @keys, $self->to_clark($attr->namespaceURI, $attr->localname);
51 }
52 }
53  
54 4 return sort @keys;
55 }
56  
57 sub TIEHASH
58 {
59 5 ▶ my ($class, $element, %args) = @_;
Subroutine TIEHASH: called CC=2 SCAR=7.0
60 5 my $self = bless [$element, undef, \%args], $class;
61 5 ▶ if (__HAS_WEAKEN and $args{weaken})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"weaken"}) 5 0 5
62 {
63 5 Scalar::Util::weaken( $self->[0] );
64 }
65 5 return $self;
66 }
67  
68 sub STORE
69 {
70 5 ▶ my ($self, $key, $value) = @_;
Subroutine STORE: called CC=2 SCAR=6.9
71 5 my ($key_ns, $key_local) = $self->from_clark($key);
72 5 ▶ if (defined $key_ns)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key_ns) { } 3 2 5
73 {
74 3 return $self->element->setAttributeNS($key_ns, "xxx:$key_local", "$value");
75 }
76 else
77 {
78 2 return $self->element->setAttribute($key_local, "$value");
79 }
80 }
81  
82 sub FETCH
83 {
84 11 ▶ my ($self, $key) = @_;
Subroutine FETCH: called CC=2 SCAR=6.9
85 11 my ($key_ns, $key_local) = $self->from_clark($key);
86 11 ▶ if (defined $key_ns)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key_ns) { } 5 6 11
87 {
88 5 return $self->element->getAttributeNS($key_ns, "$key_local");
89 }
90 else
91 {
92 6 return $self->element->getAttribute($key_local);
93 }
94 }
95  
96 sub EXISTS
97 {
98 2 ▶ my ($self, $key) = @_;
Subroutine EXISTS: called CC=2 SCAR=6.9
99 2 my ($key_ns, $key_local) = $self->from_clark($key);
100 2 ▶ if (defined $key_ns)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key_ns) { } 1 1 2
101 {
102 1 return $self->element->hasAttributeNS($key_ns, "$key_local");
103 }
104 else
105 {
106 1 return $self->element->hasAttribute($key_local);
107 }
108 }
109  
110 sub DELETE
111 {
112 2 ▶ my ($self, $key) = @_;
Subroutine DELETE: called CC=2 SCAR=6.9
113 2 my ($key_ns, $key_local) = $self->from_clark($key);
114 2 ▶ if (defined $key_ns)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key_ns) { } 1 1 2
115 {
116 1 return $self->element->removeAttributeNS($key_ns, "$key_local");
117 }
118 else
119 {
120 1 return $self->element->removeAttribute($key_local);
121 }
122 }
123  
124 sub FIRSTKEY
125 {
126 4 ▶ my ($self) = @_;
Subroutine FIRSTKEY: called CC=2 SCAR=7.2
127 4 my @keys = $self->all_keys;
128 4 $self->[1] = \@keys;
129 4 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 4 4
130 {
131 0 return ($keys[0], $self->FETCH($keys[0]));
132 }
133 4 $keys[0];
134 }
135  
136 sub NEXTKEY
137 {
138 7 ▶ my ($self, $lastkey) = @_;
Subroutine NEXTKEY: called CC=7 SCAR=19.8
139 7 ▶ my @keys = defined $self->[1] ? @{ $self->[1] } : $self->all_keys;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[1] ? : 7 0 7
140 7 my $found;
141 7 foreach my $k (@keys)
142 {
143 16 ▶ if ($k gt $lastkey)
Branch: 1 branch
BranchTrueFalseTotal
if ($k gt $lastkey) 4 12 16
144 {
145 4 ▶ $found = $k and last;
Branch: 1 branch
BranchTrueFalseTotal
$found = $k and last 4 0 4
146 }
147 }
148 7 ▶ if (!defined $found)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $found) 3 4 7
149 {
150 3 $self->[1] = undef;
151 3 return;
152 }
153 4 ▶ if (wantarray)
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 4 4
154 {
155 0 return ($found, $self->FETCH($found));
156 }
157 4 return $found;
158 }
159  
160 sub SCALAR
161 {
162 0 ▶ my ($self) = @_;
Subroutine SCALAR: not called CC=1 SCAR=6.9
163 0 return $self->element;
164 }
165  
166 sub CLEAR
167 {
168 0 ▶ my ($self) = @_;
Subroutine CLEAR: not called CC=2 SCAR=17.9
169 0 foreach my $k ($self->all_keys)
170 {
171 0 $self->DELETE($k);
172 }
173 0 return $self;
174 }
175  
176 69 __PACKAGE__
177 __END__
« blib/lib/XML/LibXML/XPathContext.pm ↑ Summary blib/lib/XML/LibXML/NodeList.pm »