| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XML::DOM2::Element; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
19
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
102
|
|
|
4
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
95
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
XML::DOM2::Element - XML Element level control |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DISCRIPTION |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Element base class represents an element at the XML level. |
|
13
|
|
|
|
|
|
|
More specific element classes control the xml functionality which is abstracted from the xml. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 METHODS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
18
|
use base "XML::DOM2::DOM::Element"; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
2074
|
|
|
20
|
3
|
|
|
3
|
|
32
|
use Carp; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
216
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
19
|
use XML::DOM2::Attribute; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
85
|
|
|
23
|
3
|
|
|
3
|
|
2194
|
use XML::DOM2::Element::CDATA; |
|
|
3
|
|
|
|
|
9
|
|
|
|
3
|
|
|
|
|
3000
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 $element->new( $name, %options ) |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Create a new element object. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
|
30
|
|
|
|
|
|
|
sub new |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
32
|
|
|
32
|
1
|
99
|
my ($proto, $name, %opts) = @_; |
|
33
|
32
|
|
33
|
|
|
133
|
my $class = ref($proto) || $proto; |
|
34
|
|
|
|
|
|
|
|
|
35
|
32
|
|
|
|
|
83
|
my $self = bless \%opts, $class; |
|
36
|
32
|
|
|
|
|
506
|
$self->{'name'} = $name; |
|
37
|
|
|
|
|
|
|
|
|
38
|
32
|
|
|
|
|
122
|
return $self; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 $element->xmlify() |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns the element and all it's sub elements as a serialised xml string (serialisation) |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
|
46
|
|
|
|
|
|
|
sub xmlify |
|
47
|
|
|
|
|
|
|
{ |
|
48
|
10
|
|
|
10
|
1
|
34
|
my ($self, %p) = @_; |
|
49
|
10
|
|
|
|
|
23
|
my ($ns, $indent, $level, $sep) = @p{qw/namespace indent level seperator/}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
10
|
100
|
|
|
|
24
|
$indent = ' ' if not $indent; |
|
52
|
10
|
100
|
|
|
|
21
|
$level = 0 if not $level; |
|
53
|
|
|
|
|
|
|
|
|
54
|
10
|
|
|
|
|
13
|
my $xml = $sep; |
|
55
|
|
|
|
|
|
|
|
|
56
|
10
|
|
|
|
|
20
|
$xml .= $indent x $level; |
|
57
|
|
|
|
|
|
|
|
|
58
|
10
|
50
|
66
|
|
|
33
|
if($self->hasChildren or $self->hasCDATA) { |
|
59
|
10
|
|
|
|
|
25
|
$xml .= $self->_serialise_open_tag($ns); |
|
60
|
10
|
100
|
|
|
|
32
|
if($self->hasChildren()) { |
|
61
|
4
|
|
|
|
|
13
|
foreach my $child ($self->getChildren) { |
|
62
|
9
|
|
|
|
|
33
|
$xml .= $child->xmlify( |
|
63
|
|
|
|
|
|
|
indent => $indent, |
|
64
|
|
|
|
|
|
|
level => $level+1, |
|
65
|
|
|
|
|
|
|
seperator => $sep, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
4
|
|
|
|
|
13
|
$xml .= $sep.($indent x $level); |
|
69
|
|
|
|
|
|
|
} else { |
|
70
|
6
|
|
|
|
|
18
|
$xml .= $self->cdata->text(); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
10
|
|
|
|
|
28
|
$xml .= $self->_serialise_close_tag(); |
|
73
|
|
|
|
|
|
|
} else { |
|
74
|
0
|
|
|
|
|
0
|
$xml .= $self->_serialise_tag(); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
10
|
|
|
|
|
43
|
return $xml; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 $element->_element_handle() |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Inherited method, returns element which is the specific kind |
|
82
|
|
|
|
|
|
|
of child object required for this element. |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
|
85
|
|
|
|
|
|
|
sub _element_handle |
|
86
|
|
|
|
|
|
|
{ |
|
87
|
42
|
|
|
42
|
|
270
|
my ($self, $name, %opts) = @_; |
|
88
|
42
|
100
|
|
|
|
141
|
if(defined($self->getParent)) { |
|
|
|
50
|
|
|
|
|
|
|
89
|
24
|
|
|
|
|
132
|
$self->getParent->_element_handle($name, %opts); |
|
90
|
|
|
|
|
|
|
} elsif($self->document) { |
|
91
|
18
|
|
|
|
|
57
|
$self->document->createElement($name, %opts); |
|
92
|
|
|
|
|
|
|
} else { |
|
93
|
0
|
|
|
|
|
0
|
croak "Unable to create element, no document or parent node to create against"; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head2 $element->_attribute_handle() |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Inherited method, returns attribute as new object or undef. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$attribute = $element->_attribute_handle( $attribute_name, $ns ); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Used by XML::DOM2::DOM for auto attribute object handlers. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
|
106
|
|
|
|
|
|
|
sub _attribute_handle |
|
107
|
|
|
|
|
|
|
{ |
|
108
|
6
|
|
|
6
|
|
24
|
my ($self, $name, %opts) = @_; |
|
109
|
6
|
|
|
|
|
37
|
return XML::DOM2::Attribute->new( name => $name, owner => $self, %opts ); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 $element->_has_attribute() |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Inherited method, returns true if attribute has an object. |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Used by XML::DOM2::DOM for auto attribute object handlers. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
|
119
|
6
|
|
|
6
|
|
21
|
sub _has_attribute { 1 } |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 $element->_can_contain_elements() |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Inherited method, returns true if the element can contain sub elements |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
|
126
|
0
|
|
|
0
|
|
0
|
sub _can_contain_elements { 1 } |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 $element->_can_contain_attributes() |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Inherited method, returns true if the element can have attributes. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=cut |
|
134
|
6
|
|
|
6
|
|
23
|
sub _can_contain_attributes { 1 } |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head2 $element->_serialise_open_tag() |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
XML ELement serialisation, Open Tag. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
|
141
|
|
|
|
|
|
|
sub _serialise_open_tag |
|
142
|
|
|
|
|
|
|
{ |
|
143
|
10
|
|
|
10
|
|
14
|
my ($self) = @_; |
|
144
|
10
|
|
|
|
|
30
|
my $name = $self->name(); |
|
145
|
10
|
100
|
|
|
|
47
|
my $at = $self->hasAttributes() ? ' '.$self->_serialise_attributes() : ''; |
|
146
|
10
|
50
|
|
|
|
26
|
return '' if not defined $name; |
|
147
|
10
|
|
|
|
|
33
|
return "<$name$at>"; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 $element->_serialise_tag() |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
XML ELement serialisation, Self contained tag. |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=cut |
|
155
|
|
|
|
|
|
|
sub _serialise_tag |
|
156
|
|
|
|
|
|
|
{ |
|
157
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
|
158
|
0
|
|
|
|
|
0
|
my $name = $self->name(); |
|
159
|
0
|
0
|
|
|
|
0
|
my $at= $self->hasAttributes ? ' '.$self->_serialise_attributes : ''; |
|
160
|
0
|
|
|
|
|
0
|
return "<$name$at \/>"; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 $element->_serialise_close_tag() |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
XML ELement serialisation, Close Tag. |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=cut |
|
168
|
|
|
|
|
|
|
sub _serialise_close_tag |
|
169
|
|
|
|
|
|
|
{ |
|
170
|
10
|
|
|
10
|
|
12
|
my ($self) = @_; |
|
171
|
10
|
|
|
|
|
32
|
my $name = $self->name(); |
|
172
|
10
|
|
|
|
|
31
|
return "$name>"; |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 $element->_serialise_attributes() |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
XML ELement serialisation, Attributes. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
sub _serialise_attributes |
|
181
|
|
|
|
|
|
|
{ |
|
182
|
3
|
|
|
3
|
|
6
|
my ($self) = @_; |
|
183
|
3
|
|
|
|
|
12
|
return $self->getAttributes(3); |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 $element->error( $command, $error ) |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
Raise an error. |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
|
191
|
|
|
|
|
|
|
sub error ($$$) { |
|
192
|
0
|
|
|
0
|
1
|
|
my ($self,$command,$error)=@_; |
|
193
|
0
|
0
|
0
|
|
|
|
confess "Error requires both command and error" if not $command or not $error; |
|
194
|
0
|
0
|
|
|
|
|
if($self->document) { |
|
195
|
0
|
0
|
|
|
|
|
if ($self->document->{-raiseerror}) { |
|
|
|
0
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
die "$command: $error\n"; |
|
197
|
|
|
|
|
|
|
} elsif ($self->document->{-printerror}) { |
|
198
|
0
|
|
|
|
|
|
print STDERR "$command: $error\n"; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
0
|
|
|
|
|
|
$self->{errors}{$command}=$error; |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=head1 OVERLOADED |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head2 $object->auto_string() |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
|
210
|
0
|
0
|
|
0
|
1
|
|
sub auto_string { return $_[0]->hasCDATA() ? $_[0]->cdata() : '' } |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 $object->auto_eq( $string ) |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=cut |
|
215
|
0
|
|
|
0
|
1
|
|
sub auto_eq { return shift->auto_string() eq shift } |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=head2 BEGIN() |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
POD Catch, imagened method. |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head1 AUTHOR |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Martin Owens (Fork) |
|
224
|
|
|
|
|
|
|
Ronan Oger |
|
225
|
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
perl(1),L,L |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=cut |
|
231
|
|
|
|
|
|
|
1; |