line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SVG::DOM; |
2
|
25
|
|
|
25
|
|
168
|
use strict; |
|
25
|
|
|
|
|
50
|
|
|
25
|
|
|
|
|
734
|
|
3
|
25
|
|
|
25
|
|
117
|
use warnings; |
|
25
|
|
|
|
|
50
|
|
|
25
|
|
|
|
|
682
|
|
4
|
|
|
|
|
|
|
|
5
|
25
|
|
|
25
|
|
141
|
use Scalar::Util qw/weaken/; |
|
25
|
|
|
|
|
43
|
|
|
25
|
|
|
|
|
79700
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '2.86'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# this module extends SVG::Element |
10
|
|
|
|
|
|
|
package SVG::Element; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
#----------------- |
13
|
|
|
|
|
|
|
# sub getFirstChild |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub getFirstChild { |
16
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
5
|
if ( my @children = $self->getChildren ) { |
19
|
1
|
|
|
|
|
9
|
return $children[0]; |
20
|
|
|
|
|
|
|
} |
21
|
0
|
|
|
|
|
0
|
return; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#----------------- |
25
|
|
|
|
|
|
|
# sub getChildIndex |
26
|
|
|
|
|
|
|
# return the array index of this element in the parent |
27
|
|
|
|
|
|
|
# or the passed list (if there is one). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub getChildIndex { |
30
|
3
|
|
|
3
|
0
|
7
|
my ( $self, @children ) = @_; |
31
|
|
|
|
|
|
|
|
32
|
3
|
50
|
|
|
|
8
|
unless (@children) { |
33
|
0
|
|
|
|
|
0
|
my $parent = $self->getParent(); |
34
|
0
|
|
|
|
|
0
|
@children = $parent->getChildren(); |
35
|
0
|
0
|
|
|
|
0
|
return unless @children; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
8
|
for my $index ( 0 .. $#children ) { |
39
|
5
|
100
|
|
|
|
16
|
return $index if $children[$index] == $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
0
|
return; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#----------------- |
46
|
|
|
|
|
|
|
# sub getChildAtIndex |
47
|
|
|
|
|
|
|
# return the element at the specified index |
48
|
|
|
|
|
|
|
# (the index can be negative) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub getChildAtIndex { |
51
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $index, @children ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
0
|
unless (@children) { |
54
|
0
|
|
|
|
|
0
|
my $parent = $self->getParent(); |
55
|
0
|
|
|
|
|
0
|
@children = $parent->getChildren(); |
56
|
0
|
0
|
|
|
|
0
|
return unless @children; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
0
|
return $children[$index]; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#----------------- |
63
|
|
|
|
|
|
|
# sub getNextSibling |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub getNextSibling { |
66
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
67
|
|
|
|
|
|
|
|
68
|
2
|
50
|
|
|
|
4
|
if ( my $parent = $self->getParent ) { |
69
|
2
|
|
|
|
|
5
|
my @children = $parent->getChildren(); |
70
|
2
|
|
|
|
|
7
|
my $index = $self->getChildIndex(@children); |
71
|
2
|
50
|
33
|
|
|
24
|
if ( defined $index and scalar(@children) > $index ) { |
72
|
2
|
|
|
|
|
13
|
return $children[ $index + 1 ]; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#----------------- |
80
|
|
|
|
|
|
|
# sub getPreviousSibling |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub getPreviousSibling { |
83
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
1
|
50
|
|
|
|
4
|
if ( my $parent = $self->getParent ) { |
86
|
1
|
|
|
|
|
4
|
my @children = $parent->getChildren(); |
87
|
1
|
|
|
|
|
4
|
my $index = $self->getChildIndex(@children); |
88
|
1
|
50
|
|
|
|
3
|
if ($index) { |
89
|
1
|
|
|
|
|
5
|
return $children[ $index - 1 ]; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
#----------------- |
97
|
|
|
|
|
|
|
# sub getLastChild |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub getLastChild { |
100
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
101
|
|
|
|
|
|
|
|
102
|
1
|
50
|
|
|
|
4
|
if ( my @children = $self->getChildren ) { |
103
|
1
|
|
|
|
|
4
|
return $children[-1]; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
return; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
#----------------- |
110
|
|
|
|
|
|
|
# sub getChildren |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub getChildren { |
113
|
7
|
|
|
7
|
0
|
12
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
7
|
50
|
|
|
|
19
|
if ( $self->{-childs} ) { |
116
|
7
|
100
|
|
|
|
16
|
if (wantarray) { |
117
|
6
|
|
|
|
|
8
|
return @{ $self->{-childs} }; |
|
6
|
|
|
|
|
34
|
|
118
|
|
|
|
|
|
|
} |
119
|
1
|
|
|
|
|
2
|
return $self->{-childs}; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
0
|
return; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
*getChildElements = \&getChildren; |
125
|
|
|
|
|
|
|
*getChildNodes = \&getChildren; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#----------------- |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub hasChildren { |
130
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
1
|
50
|
|
|
|
4
|
if ( exists $self->{-childs} ) { |
133
|
1
|
50
|
|
|
|
2
|
if ( scalar @{ $self->{-childs} } ) { |
|
1
|
|
|
|
|
4
|
|
134
|
1
|
|
|
|
|
6
|
return 1; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
0
|
return 0; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
*hasChildElements = \&hasChildren; |
141
|
|
|
|
|
|
|
*hasChildNodes = \&hasChildren; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#----------------- |
144
|
|
|
|
|
|
|
# sub getParent / getParentElement |
145
|
|
|
|
|
|
|
# return the ref of the parent of the current node |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub getParent { |
148
|
8
|
|
|
8
|
0
|
14
|
my $self = shift; |
149
|
|
|
|
|
|
|
|
150
|
8
|
50
|
|
|
|
21
|
if ( $self->{-parent} ) { |
151
|
8
|
|
|
|
|
32
|
return $self->{-parent}; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
0
|
return; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
*getParentElement = \&getParent; |
157
|
|
|
|
|
|
|
*getParentNode = \&getParent; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
#----------------- |
160
|
|
|
|
|
|
|
# sub getParents / getParentElements |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub getParents { |
163
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
0
|
my $parent = $self->{-parent}; |
166
|
0
|
0
|
|
|
|
0
|
return unless $parent; |
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
0
|
my @parents; |
169
|
0
|
|
|
|
|
0
|
while ($parent) { |
170
|
0
|
|
|
|
|
0
|
push @parents, $parent; |
171
|
0
|
|
|
|
|
0
|
$parent = $parent->{-parent}; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
0
|
return @parents; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
*getParentElements = \&getParents; |
177
|
|
|
|
|
|
|
*getParentNodes = \&getParents; |
178
|
|
|
|
|
|
|
*getAncestors = \&getParents; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
#----------------- |
181
|
|
|
|
|
|
|
# sub isAncestor |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub isAncestor { |
184
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $descendant ) = @_; |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
0
|
my @parents = $descendant->getParents(); |
187
|
0
|
|
|
|
|
0
|
foreach my $parent (@parents) { |
188
|
0
|
0
|
|
|
|
0
|
return 1 if $parent == $self; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
0
|
return 0; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
#----------------- |
195
|
|
|
|
|
|
|
# sub isDescendant |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub isDescendant { |
198
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $ancestor ) = @_; |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
0
|
my @parents = $self->getParents(); |
201
|
0
|
|
|
|
|
0
|
foreach my $parent (@parents) { |
202
|
0
|
0
|
|
|
|
0
|
return 1 if $parent == $ancestor; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
0
|
return 0; |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
#----------------- |
209
|
|
|
|
|
|
|
# sub getSiblings |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub getSiblings { |
212
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
213
|
|
|
|
|
|
|
|
214
|
0
|
0
|
|
|
|
0
|
if ( my $parent = $self->getParent ) { |
215
|
0
|
|
|
|
|
0
|
return $parent->getChildren(); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
0
|
return; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
#----------------- |
222
|
|
|
|
|
|
|
# sub hasSiblings |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub hasSiblings { |
225
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
226
|
|
|
|
|
|
|
|
227
|
1
|
50
|
|
|
|
3
|
if ( my $parent = $self->getParent ) { |
228
|
1
|
|
|
|
|
5
|
my $siblings = scalar( $parent->getChildren ); |
229
|
1
|
50
|
|
|
|
19
|
return 1 if $siblings >= 2; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
0
|
return; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
#----------------- |
236
|
|
|
|
|
|
|
# sub getElementName / getType |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
sub getElementName { |
239
|
1
|
|
|
1
|
0
|
7
|
my $self = shift; |
240
|
|
|
|
|
|
|
|
241
|
1
|
50
|
|
|
|
3
|
if ( exists $self->{-name} ) { |
242
|
1
|
|
|
|
|
8
|
return $self->{-name}; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
0
|
|
|
|
|
0
|
return; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
*getType = \&getElementName; |
248
|
|
|
|
|
|
|
*getElementType = \&getElementName; |
249
|
|
|
|
|
|
|
*getTagName = \&getElementName; |
250
|
|
|
|
|
|
|
*getTagType = \&getElementName; |
251
|
|
|
|
|
|
|
*getNodeName = \&getElementName; |
252
|
|
|
|
|
|
|
*getNodeType = \&getElementName; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
#----------------- |
255
|
|
|
|
|
|
|
# sub getElements |
256
|
|
|
|
|
|
|
# get all elements of the specified type |
257
|
|
|
|
|
|
|
# if none is specified, get all elements in document. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub getElements { |
260
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $element ) = @_; |
261
|
|
|
|
|
|
|
|
262
|
2
|
50
|
|
|
|
7
|
return unless exists $self->{-docref}; |
263
|
2
|
50
|
|
|
|
4
|
return unless exists $self->{-docref}->{-elist}; |
264
|
|
|
|
|
|
|
|
265
|
2
|
|
|
|
|
4
|
my $elist = $self->{-docref}->{-elist}; |
266
|
2
|
50
|
|
|
|
5
|
if ( defined $element ) { |
267
|
2
|
50
|
|
|
|
5
|
if ( exists $elist->{$element} ) { |
268
|
2
|
50
|
|
|
|
54
|
return wantarray ? @{ $elist->{$element} } : $elist->{$element}; |
|
0
|
|
|
|
|
0
|
|
269
|
|
|
|
|
|
|
} |
270
|
0
|
|
|
|
|
0
|
return; |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
else { |
273
|
0
|
|
|
|
|
0
|
my @elements; |
274
|
0
|
|
|
|
|
0
|
foreach my $element_type ( keys %$elist ) { |
275
|
0
|
|
|
|
|
0
|
push @elements, @{ $elist->{$element_type} }; |
|
0
|
|
|
|
|
0
|
|
276
|
|
|
|
|
|
|
} |
277
|
0
|
0
|
|
|
|
0
|
return wantarray ? @elements : \@elements; |
278
|
|
|
|
|
|
|
} |
279
|
|
|
|
|
|
|
} |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
# forces the use of the second argument for element name |
282
|
|
|
|
|
|
|
sub getElementsByName { |
283
|
2
|
|
|
2
|
0
|
9
|
return shift->getElements(shift); |
284
|
|
|
|
|
|
|
} |
285
|
|
|
|
|
|
|
*getElementsByType = \&getElementsByName; |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
#----------------- |
288
|
|
|
|
|
|
|
sub getElementNames { |
289
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
290
|
|
|
|
|
|
|
|
291
|
1
|
|
|
|
|
2
|
my @types = keys %{ $self->{-docref}->{-elist} }; |
|
1
|
|
|
|
|
5
|
|
292
|
|
|
|
|
|
|
|
293
|
1
|
50
|
|
|
|
7
|
return wantarray ? @types : \@types; |
294
|
|
|
|
|
|
|
} |
295
|
|
|
|
|
|
|
*getElementTypes = \&getElementNames; |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
#----------------- |
298
|
|
|
|
|
|
|
# sub getElementID |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
sub getElementID { |
301
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
302
|
|
|
|
|
|
|
|
303
|
1
|
50
|
|
|
|
3
|
if ( exists $self->{id} ) { |
304
|
1
|
|
|
|
|
8
|
return $self->{id}; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
0
|
|
|
|
|
0
|
return; |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
#----------------- |
311
|
|
|
|
|
|
|
# sub getElementByID / getElementbyID |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
sub getElementByID { |
314
|
14
|
|
|
14
|
0
|
36
|
my ( $self, $id ) = @_; |
315
|
|
|
|
|
|
|
|
316
|
14
|
50
|
|
|
|
31
|
return unless defined($id); |
317
|
14
|
|
|
|
|
26
|
my $idlist = $self->{-docref}->{-idlist}; |
318
|
14
|
100
|
|
|
|
33
|
if ( exists $idlist->{$id} ) { |
319
|
3
|
|
|
|
|
12
|
return $idlist->{$id}; |
320
|
|
|
|
|
|
|
} |
321
|
|
|
|
|
|
|
|
322
|
11
|
|
|
|
|
35
|
return; |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
*getElementbyID = \&getElementByID; |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
#----------------- |
327
|
|
|
|
|
|
|
# sub getAttribute |
328
|
|
|
|
|
|
|
# see also SVG::attrib() |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
sub getAttribute { |
331
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $attr ) = @_; |
332
|
|
|
|
|
|
|
|
333
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{$attr} ) { |
334
|
0
|
|
|
|
|
0
|
return $self->{$attr}; |
335
|
|
|
|
|
|
|
} |
336
|
|
|
|
|
|
|
|
337
|
0
|
|
|
|
|
0
|
return; |
338
|
|
|
|
|
|
|
} |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
#----------------- |
341
|
|
|
|
|
|
|
# sub getAttributes |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
sub getAttributes { |
344
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
345
|
|
|
|
|
|
|
|
346
|
0
|
|
|
|
|
0
|
my $out = {}; |
347
|
0
|
|
|
|
|
0
|
foreach my $i ( keys %$self ) { |
348
|
0
|
0
|
|
|
|
0
|
$out->{$i} = $self->{$i} unless $i =~ /^-/; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
|
351
|
0
|
0
|
|
|
|
0
|
return wantarray ? %{$out} : $out; |
|
0
|
|
|
|
|
0
|
|
352
|
|
|
|
|
|
|
} |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
#----------------- |
355
|
|
|
|
|
|
|
# sub setAttribute |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub setAttributes { |
358
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $attr ) = @_; |
359
|
0
|
|
|
|
|
0
|
foreach my $i ( keys %$attr ) { |
360
|
0
|
|
|
|
|
0
|
$self->attrib( $i, $attr->{$i} ); |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
} |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
#----------------- |
365
|
|
|
|
|
|
|
# sub setAttribute |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub setAttribute { |
368
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $att, $val ) = @_; |
369
|
0
|
|
|
|
|
0
|
$self->attrib( $att, $val ); |
370
|
|
|
|
|
|
|
} |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
#----------------- |
373
|
|
|
|
|
|
|
# sub getCDATA / getCdata / getData |
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
sub getCDATA { |
376
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
377
|
|
|
|
|
|
|
|
378
|
0
|
0
|
|
|
|
0
|
if ( exists $self->{-cdata} ) { |
379
|
0
|
|
|
|
|
0
|
return $self->{-cdata}; |
380
|
|
|
|
|
|
|
} |
381
|
|
|
|
|
|
|
|
382
|
0
|
|
|
|
|
0
|
return; |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
*getCdata = \&getCDATA; |
385
|
|
|
|
|
|
|
*getData = \&getCDATA; |
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
# ---------------- |
388
|
|
|
|
|
|
|
# 2005-12-30 - Martin Owens, apply greater DOM specification (write) |
389
|
|
|
|
|
|
|
# http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
# ---------------- |
392
|
|
|
|
|
|
|
# sub document |
393
|
|
|
|
|
|
|
sub document { |
394
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
395
|
0
|
|
|
|
|
0
|
return $self->{-docref}; |
396
|
|
|
|
|
|
|
} |
397
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
# DOM specified method names |
399
|
|
|
|
|
|
|
*createElement = \&tag; |
400
|
|
|
|
|
|
|
*firstChild = \&getFirstChild; |
401
|
|
|
|
|
|
|
*lastChild = \&getLastChild; |
402
|
|
|
|
|
|
|
*previousSibling = \&getPreviousSibling; |
403
|
|
|
|
|
|
|
*nextSibling = \&getNextSibling; |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
# ---------------- |
406
|
|
|
|
|
|
|
# sub insertBefore |
407
|
|
|
|
|
|
|
sub insertBefore { |
408
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $newChild, $refChild ) = @_; |
409
|
0
|
0
|
|
|
|
0
|
return $self->appendElement($newChild) if not $refChild; |
410
|
0
|
|
|
|
|
0
|
my $index = $self->findChildIndex($refChild); |
411
|
0
|
0
|
|
|
|
0
|
return 0 if $index < 0; # NO_FOUND_ERR |
412
|
0
|
|
|
|
|
0
|
return $self->insertAtIndex( $newChild, $index ); |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
*insertChildBefore = \&insertBefore; |
415
|
|
|
|
|
|
|
*insertNodeBefore = \&insertBefore; |
416
|
|
|
|
|
|
|
*insertElementBefore = \&insertBefore; |
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
# ---------------- |
419
|
|
|
|
|
|
|
# sub insertAfter |
420
|
|
|
|
|
|
|
sub insertAfter { |
421
|
1
|
|
|
1
|
0
|
2
|
my ( $self, $newChild, $refChild ) = @_; |
422
|
1
|
50
|
|
|
|
4
|
return $self->appendElement($newChild) if not $refChild; |
423
|
1
|
|
|
|
|
4
|
my $index = $self->findChildIndex($refChild); |
424
|
1
|
50
|
|
|
|
3
|
return 0 if $index < 0; # NO_FOUND_ERR |
425
|
1
|
|
|
|
|
5
|
return $self->insertAtIndex( $newChild, $index + 1 ); |
426
|
|
|
|
|
|
|
} |
427
|
|
|
|
|
|
|
*insertChildAfter = \&insertAfter; |
428
|
|
|
|
|
|
|
*insertNodeAfter = \&insertAfter; |
429
|
|
|
|
|
|
|
*insertElementAfter = \&insertAfter; |
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
# ---------------- |
432
|
|
|
|
|
|
|
# sub insertSiblingAfter (Not in W3C DOM) |
433
|
|
|
|
|
|
|
sub insertSiblingAfter { |
434
|
1
|
|
|
1
|
0
|
4
|
my ( $self, $newChild ) = @_; |
435
|
1
|
50
|
|
|
|
4
|
return $self->getParent->insertAfter( $newChild, $self ) |
436
|
|
|
|
|
|
|
if $self->getParent; |
437
|
0
|
|
|
|
|
0
|
return 0; |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
# ---------------- |
441
|
|
|
|
|
|
|
# sub insertSiblingBefore (Not in W3C DOM) |
442
|
|
|
|
|
|
|
sub insertSiblingBefore { |
443
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $newChild ) = @_; |
444
|
0
|
0
|
|
|
|
0
|
return $self->getParent->insertBefore( $newChild, $self ) |
445
|
|
|
|
|
|
|
if $self->getParent; |
446
|
0
|
|
|
|
|
0
|
return 0; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
# ---------------- |
450
|
|
|
|
|
|
|
# sub replaceChild |
451
|
|
|
|
|
|
|
sub replaceChild { |
452
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $newChild, $oldChild ) = @_; |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
# Replace newChild if it is in this list of children already |
455
|
0
|
0
|
|
|
|
0
|
$self->removeChild($newChild) if $newChild->{-parent} eq $self; |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# We need the index of the node to replace |
458
|
0
|
|
|
|
|
0
|
my $index = $self->findChildIndex($oldChild); |
459
|
0
|
0
|
|
|
|
0
|
return 0 if ( $index < 0 ); # NOT_FOUND_ERR |
460
|
|
|
|
|
|
|
# Replace and bind new node with its family |
461
|
0
|
|
|
|
|
0
|
$self->removeChildAtIndex($index); |
462
|
0
|
|
|
|
|
0
|
$self->insertChildAtIndex($index); |
463
|
0
|
|
|
|
|
0
|
return $oldChild; |
464
|
|
|
|
|
|
|
} |
465
|
|
|
|
|
|
|
*replaceElement = \&replaceChild; |
466
|
|
|
|
|
|
|
*replaceNode = \&replaceChild; |
467
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
# ---------------- |
469
|
|
|
|
|
|
|
# sub removeChild |
470
|
|
|
|
|
|
|
sub removeChild { |
471
|
4
|
|
|
4
|
0
|
2541
|
my ( $self, $oldChild ) = @_; |
472
|
4
|
|
|
|
|
13
|
my $index = $self->findChildIndex($oldChild); |
473
|
4
|
100
|
|
|
|
55
|
return 0 if ( $index < 0 ); # NOT_FOUND_ERR |
474
|
3
|
|
|
|
|
11
|
return $self->removeChildAtIndex($index); |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
*removeElement = \&removeChild; |
477
|
|
|
|
|
|
|
*removeNode = \&removeChild; |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
# ---------------- |
480
|
|
|
|
|
|
|
# sub appendChild |
481
|
|
|
|
|
|
|
sub appendChild { |
482
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $element ) = @_; |
483
|
|
|
|
|
|
|
my $index |
484
|
0
|
|
0
|
|
|
0
|
= ( defined $self->{-childs} && scalar @{ $self->{-childs} } ) || 0; |
485
|
0
|
|
|
|
|
0
|
$self->insertAtIndex( $element, $index ); |
486
|
0
|
|
|
|
|
0
|
return 1; |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
*appendElement = \&appendChild; |
489
|
|
|
|
|
|
|
*appendNode = \&appendChild; |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
# ---------------- |
492
|
|
|
|
|
|
|
# sub cloneNode |
493
|
|
|
|
|
|
|
sub cloneNode { |
494
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $deep ) = @_; |
495
|
0
|
|
|
|
|
0
|
my $clone = new SVG::Element; |
496
|
0
|
|
|
|
|
0
|
foreach my $key ( keys( %{$self} ) ) { |
|
0
|
|
|
|
|
0
|
|
497
|
0
|
0
|
0
|
|
|
0
|
next if $key eq '-childs' or $key eq '-parent'; |
498
|
0
|
0
|
|
|
|
0
|
if ( $key eq '-docref' ) { |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
# need to forge a docref based on the docref of the template element |
501
|
0
|
|
|
|
|
0
|
foreach my $dockey ( keys( %{ $self->{-docref} } ) ) { |
|
0
|
|
|
|
|
0
|
|
502
|
|
|
|
|
|
|
next |
503
|
0
|
0
|
0
|
|
|
0
|
if $dockey eq '-childs' |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
504
|
|
|
|
|
|
|
or $dockey eq '-parent' |
505
|
|
|
|
|
|
|
or $dockey eq '-idlist' |
506
|
|
|
|
|
|
|
or $dockey eq '-elist' |
507
|
|
|
|
|
|
|
or $dockey eq '-document' |
508
|
|
|
|
|
|
|
or $dockey eq '-docref'; |
509
|
0
|
|
|
|
|
0
|
$clone->{-docref}->{$dockey} = $self->{-docref}->{$dockey}; |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
} |
512
|
|
|
|
|
|
|
else { |
513
|
0
|
|
|
|
|
0
|
$clone->{$key} = $self->{$key}; |
514
|
|
|
|
|
|
|
} |
515
|
|
|
|
|
|
|
} |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
# We need to clone the children if deep is specified. |
518
|
0
|
0
|
|
|
|
0
|
if ($deep) { |
519
|
0
|
|
|
|
|
0
|
foreach my $child ( @{ $self->{-childs} } ) { |
|
0
|
|
|
|
|
0
|
|
520
|
0
|
|
|
|
|
0
|
my $childClone = $child->cloneNode($deep); |
521
|
0
|
|
|
|
|
0
|
$clone->appendChild($childClone); |
522
|
|
|
|
|
|
|
} |
523
|
|
|
|
|
|
|
} |
524
|
|
|
|
|
|
|
|
525
|
0
|
|
|
|
|
0
|
return $clone; |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
*cloneElement = \&cloneNode; |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
# --------------------------------------- |
530
|
|
|
|
|
|
|
# NONE DOM Supporting methodss |
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
# ---------------- |
533
|
|
|
|
|
|
|
# sub findChildIndex |
534
|
|
|
|
|
|
|
sub findChildIndex { |
535
|
8
|
|
|
8
|
0
|
15
|
my ( $self, $refChild ) = @_; |
536
|
|
|
|
|
|
|
|
537
|
8
|
|
|
|
|
13
|
my $index = 0; |
538
|
8
|
|
|
|
|
13
|
foreach my $child ( @{ $self->{-childs} } ) { |
|
8
|
|
|
|
|
21
|
|
539
|
7
|
100
|
|
|
|
23
|
if ( $child eq $refChild ) { |
540
|
5
|
|
|
|
|
19
|
return $index; # Child found |
541
|
|
|
|
|
|
|
} |
542
|
2
|
|
|
|
|
5
|
$index++; |
543
|
|
|
|
|
|
|
} |
544
|
|
|
|
|
|
|
|
545
|
3
|
|
|
|
|
9
|
return -1; # Child not found |
546
|
|
|
|
|
|
|
} |
547
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
# --------------- |
549
|
|
|
|
|
|
|
# sub insertAtIndex |
550
|
|
|
|
|
|
|
sub insertAtIndex { |
551
|
2
|
|
|
2
|
0
|
7
|
my ( $self, $newChild, $index ) = @_; |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
# add child |
554
|
2
|
|
|
|
|
4
|
splice @{ $self->{-childs} }, $index, 0, $newChild; |
|
2
|
|
|
|
|
6
|
|
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
# update parent and document reference |
557
|
2
|
|
|
|
|
5
|
$newChild->{-docref} = $self->{-docref}; |
558
|
2
|
|
|
|
|
9
|
weaken( $newChild->{-docref} ); |
559
|
2
|
|
|
|
|
4
|
$newChild->{-parent} = $self; |
560
|
2
|
|
|
|
|
7
|
weaken( $newChild->{-parent} ); |
561
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
# update ID and element list |
563
|
2
|
50
|
|
|
|
7
|
if ( defined( $newChild->{id} ) ) { |
564
|
0
|
|
|
|
|
0
|
$self->{-docref}->{-idlist}->{ $newChild->{id} } = $newChild; |
565
|
|
|
|
|
|
|
} |
566
|
|
|
|
|
|
|
$self->{-docref}->{-elist} = {} |
567
|
2
|
50
|
|
|
|
8
|
unless ( defined $self->{-docref}->{-elist} ); |
568
|
|
|
|
|
|
|
$self->{-docref}->{-elist}->{ $newChild->{-name} } = [] |
569
|
2
|
100
|
|
|
|
11
|
unless ( defined $self->{-docref}->{-elist}->{ $newChild->{-name} } ); |
570
|
2
|
|
|
|
|
4
|
unshift @{ $self->{-docref}->{-elist}->{ $newChild->{-name} } }, |
|
2
|
|
|
|
|
6
|
|
571
|
|
|
|
|
|
|
$newChild; |
572
|
|
|
|
|
|
|
|
573
|
2
|
|
|
|
|
6
|
return 1; |
574
|
|
|
|
|
|
|
} |
575
|
|
|
|
|
|
|
*insertChildAtIndex = \&insertAtIndex; |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
# ---------------- |
578
|
|
|
|
|
|
|
# sub removeChildAtIndex |
579
|
|
|
|
|
|
|
sub removeChildAtIndex { |
580
|
4
|
|
|
4
|
0
|
8
|
my ( $self, $index ) = @_; |
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
# remove child |
583
|
4
|
|
|
|
|
7
|
my $oldChild = splice @{ $self->{-childs} }, $index, 1; |
|
4
|
|
|
|
|
10
|
|
584
|
4
|
100
|
|
|
|
6
|
if ( not @{ $self->{-childs} } ) { |
|
4
|
|
|
|
|
12
|
|
585
|
2
|
|
|
|
|
4
|
delete $self->{-childs}; |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
|
588
|
|
|
|
|
|
|
# update parent and document reference |
589
|
4
|
|
|
|
|
9
|
$oldChild->{-docref} = undef; |
590
|
4
|
|
|
|
|
6
|
$oldChild->{-parent} = undef; |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
# update ID and element list |
593
|
4
|
50
|
33
|
|
|
12
|
if ( defined( $oldChild->{id} ) |
594
|
|
|
|
|
|
|
&& exists $self->{-docref}->{-idlist}->{ $oldChild->{id} } ) |
595
|
|
|
|
|
|
|
{ |
596
|
0
|
|
|
|
|
0
|
delete $self->{-docref}->{-idlist}->{ $oldChild->{id} }; |
597
|
|
|
|
|
|
|
} |
598
|
4
|
100
|
|
|
|
27
|
if ( exists $self->{-docref}->{-elist}->{ $oldChild->{-name} } ) { |
599
|
2
|
|
|
|
|
8
|
delete $self->{-docref}->{-elist}->{ $oldChild->{-name} }; |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
|
602
|
4
|
|
|
|
|
17
|
return $oldChild; |
603
|
|
|
|
|
|
|
} |
604
|
|
|
|
|
|
|
*removeAtIndex = \&removeChildAtIndex; |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
=pod |
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
=head1 NAME |
611
|
|
|
|
|
|
|
|
612
|
|
|
|
|
|
|
SVG::DOM - A library of DOM (Document Object Model) methods for SVG objects. |
613
|
|
|
|
|
|
|
|
614
|
|
|
|
|
|
|
=head1 SUMMARY |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
SVG::DOM provides a selection of methods for accessing and manipulating SVG |
617
|
|
|
|
|
|
|
elements through DOM-like methods such as getElements, getChildren, getNextSibling |
618
|
|
|
|
|
|
|
and so on. |
619
|
|
|
|
|
|
|
|
620
|
|
|
|
|
|
|
=head1 SYNOPSIS |
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
my $svg=SVG->new(id=>"svg_dom_synopsis", width=>"100", height=>"100"); |
623
|
|
|
|
|
|
|
my %attributes=$svg->getAttributes; |
624
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
my $group=$svg->group(id=>"group_1"); |
626
|
|
|
|
|
|
|
my $name=$group->getElementName; |
627
|
|
|
|
|
|
|
my $id=$group->getElementID; |
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
$group->circle(id=>"circle_1", cx=>20, cy=>20, r=>5, fill=>"red"); |
630
|
|
|
|
|
|
|
my $rect=$group->rect(id=>"rect_1", x=>10, y=>10, width=>20, height=>30); |
631
|
|
|
|
|
|
|
my $width=$rect->getAttribute("width"); |
632
|
|
|
|
|
|
|
|
633
|
|
|
|
|
|
|
my $has_children=$group->hasChildren(); |
634
|
|
|
|
|
|
|
my @children=$group->getChildren(); |
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
my $kid=$group->getFirstChild(); |
637
|
|
|
|
|
|
|
do { |
638
|
|
|
|
|
|
|
print $kid->xmlify(); |
639
|
|
|
|
|
|
|
} while ($kid=$kid->getNextSibling); |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
my @ancestors=$rect->getParents(); |
642
|
|
|
|
|
|
|
my $is_ancestor=$group->isAncestor($rect); |
643
|
|
|
|
|
|
|
my $is_descendant=$rect->isDescendant($svg); |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
my @rectangles=$svg->getElements("rect"); |
646
|
|
|
|
|
|
|
my $allelements_arrayref=$svg->getElements(); |
647
|
|
|
|
|
|
|
|
648
|
|
|
|
|
|
|
$group->insertBefore($newChild,$rect); |
649
|
|
|
|
|
|
|
$group->insertAfter($newChild,$rect); |
650
|
|
|
|
|
|
|
$rect = $group->replaceChild($newChild,$rect); |
651
|
|
|
|
|
|
|
$group->removeChild($newChild); |
652
|
|
|
|
|
|
|
my $newRect = $rect->cloneNode($deep); |
653
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
...and so on... |
655
|
|
|
|
|
|
|
|
656
|
|
|
|
|
|
|
=head1 METHODS |
657
|
|
|
|
|
|
|
|
658
|
|
|
|
|
|
|
=head2 @elements = $obj->getElements($element_name) |
659
|
|
|
|
|
|
|
|
660
|
|
|
|
|
|
|
Return a list of all elements with the specified name (i.e. type) in the document. If |
661
|
|
|
|
|
|
|
no element name is provided, returns a list of all elements in the document. |
662
|
|
|
|
|
|
|
In scalar context returns an array reference. |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
=head2 @children = $obj->getChildren() |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
Return a list of all children defined on the current node, or undef if there are no children. |
667
|
|
|
|
|
|
|
In scalar context returns an array reference. |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
Alias: getChildElements(), getChildNodes() |
670
|
|
|
|
|
|
|
|
671
|
|
|
|
|
|
|
=head2 @children = $obj->hasChildren() |
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
Return 1 if the current node has children, or 0 if there are no children. |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
Alias: hasChildElements, hasChildNodes() |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=head2 $ref = $obj->getFirstChild() |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
Return the first child element of the current node, or undef if there are no children. |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=head2 $ref = $obj->getLastChild() |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
Return the last child element of the current node, or undef if there are no children. |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
=head2 $ref = $obj->getSiblings() |
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
Return a list of all children defined on the parent node, containing the current node. |
688
|
|
|
|
|
|
|
|
689
|
|
|
|
|
|
|
=head2 $ref = $obj->getNextSibling() |
690
|
|
|
|
|
|
|
|
691
|
|
|
|
|
|
|
Return the next child element of the parent node, or undef if this is the last child. |
692
|
|
|
|
|
|
|
|
693
|
|
|
|
|
|
|
=head2 $ref = $obj->getPreviousSibling() |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
Return the previous child element of the parent node, or undef if this is the first child. |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
=head2 $index = $obj->getChildIndex() |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
Return the place of this element in the parent node's list of children, starting from 0. |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=head2 $element = $obj->getChildAtIndex($index) |
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
Returns the child element at the specified index in the parent node's list of children. |
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
=head2 $ref = $obj->getParentElement() |
706
|
|
|
|
|
|
|
|
707
|
|
|
|
|
|
|
Return the parent of the current node. |
708
|
|
|
|
|
|
|
|
709
|
|
|
|
|
|
|
Alias: getParent() |
710
|
|
|
|
|
|
|
|
711
|
|
|
|
|
|
|
=head2 @refs = $obj->getParentElements() |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
Return a list of the parents of the current node, starting from the immediate parent. The |
714
|
|
|
|
|
|
|
last member of the list should be the document element. |
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
Alias: getParents() |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
=head2 $name = $obj->getElementName() |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
Return a string containing the name (i.e. the type, not the ID) of an element. |
721
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
Alias: getType(), getTagName(), getNodeName() |
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
=head2 $ref = $svg->getElementByID($id) |
725
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
Alias: getElementbyID() |
727
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
Return a reference to the element which has ID $id, or undef if no element with this ID exists. |
729
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
=head2 $id = $obj->getElementID() |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
Return a string containing the ID of the current node, or undef if it has no ID. |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
=head2 $ref = $obj->getAttributes() |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
Return a hash reference of attribute names and values for the current node. |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
=head2 $value = $obj->getAttribute($name); |
739
|
|
|
|
|
|
|
|
740
|
|
|
|
|
|
|
Return the string value attribute value for an attribute of name $name. |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
=head2 $ref = $obj->setAttributes({name1=>$value1,name2=>undef,name3=>$value3}) |
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
Set a set of attributes. If $value is undef, deletes the attribute. |
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
=head2 $value = $obj->setAttribute($name,$value); |
747
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
Set attribute $name to $value. If $value is undef, deletes the attribute. |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=head2 $cdata = $obj->getCDATA() |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
Return the canonical data (i.e. textual content) of the current node. |
753
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
Alias: getCdata(), getData() |
755
|
|
|
|
|
|
|
|
756
|
|
|
|
|
|
|
=head2 $boolean = $obj->isAncestor($element) |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
Returns 1 if the current node is an ancestor of the specified element, otherwise 0. |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
=head2 $boolean = $obj->isDescendant($element) |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
Returns 1 if the current node is a descendant of the specified element, otherwise 0. |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
=head2 $boolean = $obj->insertBefore( $element, $child ); |
765
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
Returns 1 if $element was successfully inserted before $child in $obj |
767
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
=head2 $boolean = $obj->insertAfter( $element, $child ); |
769
|
|
|
|
|
|
|
|
770
|
|
|
|
|
|
|
Returns 1 if $element was successfully inserted after $child in $obj |
771
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
=head2 $boolean = $obj->insertSiblingBefore( $element ); |
773
|
|
|
|
|
|
|
|
774
|
|
|
|
|
|
|
Returns 1 if $element was successfully inserted before $obj |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
=head2 $boolean = $obj->insertSiblingAfter( $element ); |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
Returns 1 if $element was successfully inserted after $obj |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
=head2 $element = $obj->replaceChild( $element, $child ); |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
Returns $child if $element successfully replaced $child in $obj |
783
|
|
|
|
|
|
|
|
784
|
|
|
|
|
|
|
=head2 $element = $obj->removeChild( $child ); |
785
|
|
|
|
|
|
|
|
786
|
|
|
|
|
|
|
Returns $child if it was removed successfully from $obj |
787
|
|
|
|
|
|
|
|
788
|
|
|
|
|
|
|
=head2 $element = $obj->cloneNode( $deep ); |
789
|
|
|
|
|
|
|
|
790
|
|
|
|
|
|
|
Returns a new $element clone of $obj, without parents or children. If deep is set to 1, all children are included recursively. |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
=head1 AUTHOR |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
Ronan Oger, ronan@roitsystems.com |
795
|
|
|
|
|
|
|
Martin Owens, doctormo@postmaster.co.uk |
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
=head1 SEE ALSO |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
perl(1), L |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
L SVG at the W3C |
802
|
|
|
|
|
|
|
|
803
|
|
|
|
|
|
|
=cut |
804
|
|
|
|
|
|
|
|
805
|
|
|
|
|
|
|
1; |