line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::DumpXML::Parser; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
817
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
157
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
$VERSION = "1.01"; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require XML::Parser; |
9
|
|
|
|
|
|
|
@ISA=qw(XML::Parser); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new |
12
|
|
|
|
|
|
|
{ |
13
|
0
|
|
|
0
|
|
|
my($class, %arg) = @_; |
14
|
0
|
|
|
|
|
|
$arg{Style} = "Data::DumpXML::ParseStyle"; |
15
|
0
|
|
|
|
|
|
$arg{Namespaces} = 1; |
16
|
0
|
|
|
|
|
|
return $class->SUPER::new(%arg); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Data::DumpXML::ParseStyle; |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
1006
|
use Array::RefElem qw(av_push hv_store); |
|
1
|
|
|
|
|
2108
|
|
|
1
|
|
|
|
|
919
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub Init |
24
|
|
|
|
|
|
|
{ |
25
|
0
|
|
|
0
|
|
|
my $p = shift; |
26
|
0
|
|
|
|
|
|
$p->{dump_data} = []; |
27
|
0
|
|
|
|
|
|
push(@{$p->{stack}}, $p->{dump_data}); |
|
0
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub Start |
31
|
|
|
|
|
|
|
{ |
32
|
0
|
|
|
0
|
|
|
my($p, $tag, %attr) = @_; |
33
|
0
|
0
|
0
|
|
|
|
$p->{in_str}++ if $tag eq "str" || $tag eq "key"; |
34
|
0
|
|
|
|
|
|
my $obj = [\%attr]; |
35
|
0
|
|
|
|
|
|
push(@{$p->{stack}[-1]}, $obj); |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
push(@{$p->{stack}}, $obj); |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub Char |
40
|
|
|
|
|
|
|
{ |
41
|
0
|
|
|
0
|
|
|
my($p, $str) = @_; |
42
|
0
|
0
|
|
|
|
|
return unless $p->{in_str}; |
43
|
0
|
|
|
|
|
|
push(@{$p->{stack}[-1]}, $str); |
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub End |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
|
|
my($p, $tag) = @_; |
49
|
0
|
|
|
|
|
|
my $obj = pop(@{$p->{stack}}); |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $attr = shift(@$obj); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my $ref; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
0
|
|
|
|
if ($tag eq "str" || $tag eq "key") { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$p->{in_str}--; |
56
|
0
|
|
|
|
|
|
my $val = join("", @$obj); |
57
|
0
|
0
|
|
|
|
|
if (my $enc = $attr->{encoding}) { |
58
|
0
|
0
|
|
|
|
|
if ($enc eq "base64") { |
59
|
0
|
|
|
|
|
|
require MIME::Base64; |
60
|
0
|
|
|
|
|
|
$val = MIME::Base64::decode($val); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
0
|
|
|
|
|
|
warn "Unknown encoding '$enc'"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
$ref = \$val; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ($tag eq "ref") { |
69
|
0
|
|
|
|
|
|
my $val = $obj->[0]; |
70
|
0
|
|
|
|
|
|
$ref = \$val; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif ($tag eq "array" || $tag eq "data") { |
73
|
0
|
|
|
|
|
|
my @val; |
74
|
0
|
|
|
|
|
|
for (@$obj) { |
75
|
0
|
|
|
|
|
|
av_push(@val, $$_); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
$ref = \@val; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
elsif ($tag eq "hash") { |
80
|
0
|
|
|
|
|
|
my %val; |
81
|
0
|
|
|
|
|
|
while (@$obj) { |
82
|
0
|
|
|
|
|
|
my $keyref = shift @$obj; |
83
|
0
|
|
|
|
|
|
my $valref = shift @$obj; |
84
|
0
|
|
|
|
|
|
hv_store(%val, $$keyref, $$valref); |
85
|
|
|
|
|
|
|
} |
86
|
0
|
|
|
|
|
|
$ref = \%val; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif ($tag eq "undef") { |
89
|
0
|
|
|
|
|
|
my $val = undef; |
90
|
0
|
|
|
|
|
|
$ref = \$val; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
elsif ($tag eq "alias") { |
93
|
0
|
|
|
|
|
|
$ref = $p->{alias}{$attr->{ref}}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
0
|
|
|
|
|
|
my $val = "*** $tag ***"; |
97
|
0
|
|
|
|
|
|
$ref = \$val; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$p->{stack}[-1][-1] = $ref; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if (my $class = $attr->{class}) { |
103
|
0
|
0
|
|
|
|
|
if (exists $p->{Blesser}) { |
104
|
0
|
|
|
|
|
|
my $blesser = $p->{Blesser}; |
105
|
0
|
0
|
|
|
|
|
if (ref($blesser) eq "CODE") { |
106
|
0
|
|
|
|
|
|
&$blesser($ref, $class); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else { |
110
|
0
|
|
|
|
|
|
bless $ref, $class; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
if (my $id = $attr->{id}) { |
115
|
0
|
|
|
|
|
|
$p->{alias}->{$id} = $ref; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub Final |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
0
|
|
|
my $p = shift; |
122
|
0
|
|
|
|
|
|
my $data = $p->{dump_data}[0]; |
123
|
0
|
|
|
|
|
|
return $data; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |