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