line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::DOM::Lite::Serializer; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
498
|
use XML::DOM::Lite::Constants qw(:all); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
4797
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
sub new { |
6
|
1
|
|
|
1
|
0
|
11
|
my $class = shift; |
7
|
1
|
|
|
|
|
4
|
return bless { }, $class; |
8
|
|
|
|
|
|
|
} |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub serializeToString { |
11
|
9
|
|
|
9
|
0
|
19
|
my ($self, $node) = @_; |
12
|
9
|
50
|
|
|
|
19
|
unless (ref $self) { |
13
|
0
|
|
|
|
|
0
|
$self = __PACKAGE__->new; |
14
|
|
|
|
|
|
|
} |
15
|
9
|
100
|
|
|
|
32
|
if ($node->nodeType == DOCUMENT_NODE) { |
16
|
1
|
|
|
|
|
9
|
$node = $node->firstChild; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
9
|
100
|
|
|
|
28
|
$self->{_indent_level} = 0 unless defined $self->{_indent_level}; |
20
|
|
|
|
|
|
|
|
21
|
9
|
|
|
|
|
12
|
my $out = ""; |
22
|
9
|
100
|
|
|
|
73
|
if ($node->nodeType == ELEMENT_NODE) { |
|
|
50
|
|
|
|
|
|
23
|
6
|
|
|
|
|
14
|
$out .= "\n".$self->_mkIndent()."<".$node->tagName; |
24
|
6
|
|
|
|
|
10
|
foreach my $att (@{$node->attributes}) { |
|
6
|
|
|
|
|
26
|
|
25
|
3
|
|
|
|
|
12
|
$out .= " $att->{nodeName}=\"".$att->{nodeValue}."\""; |
26
|
|
|
|
|
|
|
} |
27
|
6
|
100
|
|
|
|
16
|
if ($node->childNodes->length) { |
28
|
5
|
|
|
|
|
7
|
$out .= ">"; |
29
|
5
|
|
|
|
|
13
|
$self->{_indent_level}++; |
30
|
5
|
|
|
|
|
5
|
foreach my $n (@{$node->childNodes}) { |
|
5
|
|
|
|
|
11
|
|
31
|
8
|
|
|
|
|
30
|
$out .= $self->serializeToString($n); |
32
|
|
|
|
|
|
|
} |
33
|
5
|
|
|
|
|
8
|
$self->{_indent_level}--; |
34
|
5
|
|
|
|
|
11
|
$out .= "\n".$self->_mkIndent()."".$node->tagName.">"; |
35
|
|
|
|
|
|
|
} else { |
36
|
1
|
|
|
|
|
3
|
$out .= " />"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ($node->nodeType == TEXT_NODE) { |
40
|
3
|
|
|
|
|
7
|
$out .= "\n".$self->_mkIndent().$node->nodeValue; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
9
|
|
|
|
|
30
|
return $out; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _mkIndent { |
47
|
14
|
|
|
14
|
|
18
|
my ($self) = @_; |
48
|
14
|
|
|
|
|
67
|
return (" " x (2 * $self->{_indent_level})); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
1; |