| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 47 | { | ||||||||||
| 48 | 11 | ▶ | if (! $attr->isa('XML::LibXML::Namespace')) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 140 | 7 | my $found; | |||||||||
| 141 | 7 | foreach my $k (@keys) | |||||||||
| 142 | { | ||||||||||
| 143 | 16 | ▶ | if ($k gt $lastkey) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | { | ||||||||||
| 145 | 4 | ▶ | $found = $k and last; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | } | ||||||||||
| 147 | } | ||||||||||
| 148 | 7 | ▶ | if (!defined $found) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | { | ||||||||||
| 150 | 3 | $self->[1] = undef; | |||||||||
| 151 | 3 | return; | |||||||||
| 152 | } | ||||||||||
| 153 | 4 | ▶ | if (wantarray) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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__ | ||||||||||