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