line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::DOM::Lite::Node; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
48
|
use Scalar::Util qw(weaken); |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
827
|
|
4
|
8
|
|
|
8
|
|
43
|
use XML::DOM::Lite::NodeList; |
|
8
|
|
|
|
|
181
|
|
|
8
|
|
|
|
|
178
|
|
5
|
8
|
|
|
8
|
|
36
|
use XML::DOM::Lite::Constants qw(:all); |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
15504
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
121
|
|
|
121
|
0
|
231
|
my ($class, $proto) = @_; |
9
|
121
|
50
|
|
|
|
570
|
unless (UNIVERSAL::isa($proto->{childNodes}, 'XML::DOM::Lite::NodeList')) { |
10
|
121
|
|
100
|
|
|
1143
|
$proto->{childNodes} = XML::DOM::Lite::NodeList->new( |
11
|
|
|
|
|
|
|
$proto->{childNodes} || [ ] |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
} |
14
|
121
|
100
|
|
|
|
572
|
$proto->{attributes} = XML::DOM::Lite::NodeList->new([ ]) |
15
|
|
|
|
|
|
|
unless defined $proto->{attributes}; |
16
|
|
|
|
|
|
|
|
17
|
121
|
|
|
|
|
337
|
my $self = bless $proto, $class; |
18
|
121
|
|
|
|
|
379
|
return $self; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub childNodes { |
22
|
137
|
50
|
|
137
|
0
|
175
|
my $self = shift; $self->{childNodes} = shift if @_; |
|
137
|
|
|
|
|
270
|
|
23
|
137
|
|
|
|
|
549
|
return $self->{childNodes}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub parentNode { |
27
|
41
|
|
|
41
|
0
|
554
|
my $self = shift; |
28
|
41
|
100
|
|
|
|
85
|
if (@_) { |
29
|
1
|
|
|
|
|
10
|
weaken($self->{parentNode} = shift()); |
30
|
|
|
|
|
|
|
} else { |
31
|
40
|
|
|
|
|
166
|
return $self->{parentNode}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub documentElement { |
36
|
0
|
0
|
|
0
|
0
|
0
|
weaken($_[0]->{documentElement} = $_[1]) if $_[1]; $_[0]->{documentElement}; |
|
0
|
|
|
|
|
0
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub nodeType { |
40
|
153
|
50
|
|
153
|
0
|
666
|
my $self = shift; $self->{nodeType} = shift if @_; |
|
153
|
|
|
|
|
338
|
|
41
|
153
|
|
|
|
|
528
|
$self->{nodeType}; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub nodeName { |
45
|
26
|
50
|
|
26
|
0
|
49
|
my $self = shift; $self->{nodeName} = shift if @_; |
|
26
|
|
|
|
|
58
|
|
46
|
26
|
|
|
|
|
136
|
$self->{nodeName}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub tagName { |
50
|
24
|
50
|
|
24
|
0
|
27
|
my $self = shift; $self->{tagName} = shift if @_; |
|
24
|
|
|
|
|
56
|
|
51
|
24
|
|
|
|
|
80
|
$self->{tagName}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub appendChild { |
55
|
78
|
|
|
78
|
0
|
116
|
my ($self, $node) = @_; |
56
|
78
|
100
|
|
|
|
177
|
if ($node->{parentNode}) { |
57
|
3
|
|
|
|
|
9
|
$node->{parentNode}->removeChild($node); |
58
|
|
|
|
|
|
|
} |
59
|
78
|
100
|
|
|
|
151
|
unless ($node->nodeType == DOCUMENT_FRAGMENT_NODE) { |
60
|
77
|
|
|
|
|
126
|
$node->{parentNode} = $self; |
61
|
77
|
|
|
|
|
229
|
$self->{childNodes}->insertNode($node); |
62
|
|
|
|
|
|
|
} else { |
63
|
1
|
|
|
|
|
3
|
while ($node->childNodes->length) { |
64
|
3
|
|
|
|
|
9
|
$self->appendChild($node->firstChild); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
78
|
|
|
|
|
200
|
return $node; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub previousSibling { |
72
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
73
|
3
|
50
|
|
|
|
8
|
if ($self->parentNode) { |
74
|
3
|
|
|
|
|
9
|
my $index = $self->parentNode->childNodes->nodeIndex($self); |
75
|
3
|
100
|
|
|
|
13
|
return undef if $index == 0; |
76
|
2
|
|
|
|
|
6
|
return $self->parentNode->childNodes->[$index - 1]; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub nextSibling { |
81
|
7
|
|
|
7
|
0
|
12
|
my $self = shift; |
82
|
7
|
50
|
|
|
|
19
|
if ($self->parentNode) { |
83
|
7
|
|
|
|
|
20
|
my $index = $self->parentNode->childNodes->nodeIndex($self); |
84
|
7
|
50
|
|
|
|
15
|
return undef if $index == @{$self->childNodes->length} - 1; |
|
7
|
|
|
|
|
18
|
|
85
|
7
|
|
|
|
|
21
|
return $self->parentNode->childNodes->[$index + 1]; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub removeChild { |
90
|
4
|
|
|
4
|
0
|
1374
|
my ($self, $node) = @_; |
91
|
4
|
50
|
|
|
|
13
|
if ($node->parentNode == $self) { |
92
|
4
|
|
|
|
|
9
|
undef($node->{parentNode}); |
93
|
4
|
|
|
|
|
12
|
return $self->childNodes->removeNode($node); |
94
|
|
|
|
|
|
|
} else { |
95
|
0
|
|
|
|
|
0
|
die "$node is not a child of $self"; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub insertBefore { |
100
|
1
|
|
|
1
|
0
|
3
|
my ($self, $node, $refNode) = @_; |
101
|
1
|
50
|
|
|
|
6
|
die "usage error" unless (scalar(@_) == 3); |
102
|
1
|
50
|
|
|
|
6
|
if ($node->parentNode) { |
103
|
0
|
|
|
|
|
0
|
$node->parentNode->removeChild($node); |
104
|
|
|
|
|
|
|
} |
105
|
1
|
50
|
|
|
|
6
|
if ($node->nodeType == DOCUMENT_FRAGMENT_NODE) { |
106
|
0
|
|
|
|
|
0
|
foreach my $c (@{$node->childNodes}) { |
|
0
|
|
|
|
|
0
|
|
107
|
0
|
|
|
|
|
0
|
$self->insertBefore($c, $refNode); |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
0
|
return; |
110
|
|
|
|
|
|
|
} |
111
|
1
|
|
|
|
|
4
|
$node->parentNode($self); |
112
|
1
|
|
|
|
|
3
|
my $index = $self->childNodes->nodeIndex($refNode); |
113
|
1
|
50
|
|
|
|
6
|
if (defined $index) { |
114
|
1
|
50
|
|
|
|
4
|
if ($index <= 0) { |
115
|
0
|
|
|
|
|
0
|
$self->childNodes->insertNode($node, 0); |
116
|
|
|
|
|
|
|
} else { |
117
|
1
|
|
|
|
|
4
|
$self->childNodes->insertNode($node, $index); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} else { |
120
|
0
|
|
|
|
|
0
|
die "$refNode is not a child of $self"; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub replaceChild { |
125
|
0
|
|
|
0
|
0
|
0
|
my ($self, $node, $refNode) = @_; |
126
|
0
|
0
|
|
|
|
0
|
die "usage error" unless (scalar(@_) == 3); |
127
|
0
|
|
|
|
|
0
|
$self->insertBefore($refNode, $node); |
128
|
0
|
|
|
|
|
0
|
$self->removeChild($refNode); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub nodeValue { |
132
|
18
|
50
|
|
18
|
0
|
24
|
my $self = shift; $self->{nodeValue} = shift if @_; |
|
18
|
|
|
|
|
52
|
|
133
|
18
|
|
|
|
|
75
|
$self->{nodeValue}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub attributes { |
137
|
23
|
50
|
|
23
|
0
|
1021
|
my $self = shift; $self->{attributes} = shift if @_; |
|
23
|
|
|
|
|
60
|
|
138
|
23
|
|
|
|
|
101
|
return $self->{attributes}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub getAttribute { |
142
|
66
|
|
|
66
|
0
|
516
|
my ($self, $attname) = @_; |
143
|
66
|
|
|
|
|
226
|
for (my $x = 0; $x < $self->{attributes}->length; $x++) { |
144
|
63
|
100
|
|
|
|
411
|
return $self->{attributes}->[$x]->{nodeValue} |
145
|
|
|
|
|
|
|
if ($self->{attributes}->[$x]->{nodeName} eq $attname); |
146
|
|
|
|
|
|
|
} |
147
|
39
|
|
|
|
|
164
|
return undef; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub setAttribute { |
151
|
1
|
|
|
1
|
0
|
2
|
my ($self, $attname, $value) = @_; |
152
|
1
|
|
|
|
|
4
|
for (my $x = 0; $x < $self->{attributes}->length; $x++) { |
153
|
0
|
0
|
|
|
|
0
|
if ($self->{attributes}->[$x]->{nodeName} eq $attname) { |
154
|
0
|
|
|
|
|
0
|
$self->{attributes}->[$x]->{nodeValue} = $value; |
155
|
0
|
|
|
|
|
0
|
return $value; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
1
|
|
|
|
|
2
|
push @{$self->{attributes}}, XML::DOM::Lite::Node->new({ |
|
1
|
|
|
|
|
7
|
|
159
|
|
|
|
|
|
|
nodeType => ATTRIBUTE_NODE, |
160
|
|
|
|
|
|
|
nodeName => $attname, |
161
|
|
|
|
|
|
|
nodeValue => $value |
162
|
|
|
|
|
|
|
}); |
163
|
1
|
|
|
|
|
5
|
return $value; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub firstChild { |
168
|
19
|
|
|
19
|
0
|
490
|
my ($self) = @_; |
169
|
19
|
|
|
|
|
62
|
return $self->childNodes->item(0); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
sub lastChild { |
173
|
7
|
|
|
7
|
0
|
17
|
my ($self) = @_; |
174
|
7
|
|
|
|
|
22
|
return $self->childNodes->[$#{$self->childNodes}]; |
|
7
|
|
|
|
|
25
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub ownerDocument { |
178
|
84
|
100
|
|
84
|
0
|
102
|
my $self = shift; weaken($self->{ownerDocument} = shift) if @_; |
|
84
|
|
|
|
|
357
|
|
179
|
84
|
|
|
|
|
194
|
$self->{ownerDocument}; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub getElementsByTagName { |
183
|
1
|
|
|
1
|
0
|
4
|
my ($self, $tag_name) = @_; |
184
|
1
|
|
|
|
|
5
|
my $nlist = XML::DOM::Lite::NodeList->new([ ]); |
185
|
1
|
|
|
|
|
2
|
my @stack = @{ $self->childNodes }; |
|
1
|
|
|
|
|
8
|
|
186
|
1
|
|
|
|
|
6
|
while (my $n = shift(@stack)) { |
187
|
17
|
100
|
|
|
|
31
|
if ($n->nodeType == ELEMENT_NODE) { |
188
|
8
|
100
|
|
|
|
17
|
if ($n->tagName eq $tag_name) { |
189
|
2
|
|
|
|
|
6
|
$nlist->insertNode($n); |
190
|
|
|
|
|
|
|
} |
191
|
8
|
|
|
|
|
15
|
push @stack, @{ $n->childNodes }; |
|
8
|
|
|
|
|
14
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
} |
194
|
1
|
|
|
|
|
4
|
return $nlist; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub cloneNode { |
198
|
0
|
|
|
0
|
0
|
|
my ($self, $deep) = @_; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
my $copy = { }; |
201
|
0
|
|
|
|
|
|
@copy{keys %$self} = values %$self; |
202
|
0
|
|
|
|
|
|
$copy->{childNodes} = XML::DOM::Lite::NodeList->new([ ]); |
203
|
0
|
|
|
|
|
|
$copy->{attributes} = XML::DOM::Lite::NodeList->new([@{$self->attributes}]); |
|
0
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
$copy->{tagName} = $self->tagName; |
205
|
0
|
|
|
|
|
|
$copy->{nodeName} = $self->nodeName; |
206
|
0
|
|
|
|
|
|
$copy->{nodeType} = $self->nodeType; |
207
|
0
|
|
|
|
|
|
$copy->{ownerDocument} = $self->ownerDocument; |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
bless $copy, ref($self); |
210
|
|
|
|
|
|
|
|
211
|
0
|
0
|
|
|
|
|
if ($deep) { |
212
|
0
|
|
|
|
|
|
foreach (@{$self->childNodes}) { |
|
0
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
$copy->childNodes->insertNode($_->cloneNode($deep)); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
0
|
|
|
|
|
|
return $copy; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub xml { |
220
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
221
|
0
|
|
|
|
|
|
require XML::DOM::Lite::Serializer; |
222
|
0
|
|
|
|
|
|
my $serializer = XML::DOM::Lite::Serializer->new(); |
223
|
0
|
|
|
|
|
|
return $serializer->serializeToString( $self ); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |
228
|
|
|
|
|
|
|
|