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