| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PYX::XMLNorm; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
301142
|
use strict; |
|
|
6
|
|
|
|
|
13
|
|
|
|
6
|
|
|
|
|
262
|
|
|
4
|
6
|
|
|
6
|
|
44
|
use warnings; |
|
|
6
|
|
|
|
|
17
|
|
|
|
6
|
|
|
|
|
494
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
2759
|
use Class::Utils qw(set_params); |
|
|
6
|
|
|
|
|
44104
|
|
|
|
6
|
|
|
|
|
319
|
|
|
7
|
6
|
|
|
6
|
|
322
|
use Error::Pure qw(err); |
|
|
6
|
|
|
|
|
19
|
|
|
|
6
|
|
|
|
|
368
|
|
|
8
|
6
|
|
|
6
|
|
3616
|
use PYX qw(end_element); |
|
|
6
|
|
|
|
|
69417
|
|
|
|
6
|
|
|
|
|
174
|
|
|
9
|
6
|
|
|
6
|
|
4420
|
use PYX::Parser; |
|
|
6
|
|
|
|
|
151706
|
|
|
|
6
|
|
|
|
|
8563
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.05; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Constructor. |
|
14
|
|
|
|
|
|
|
sub new { |
|
15
|
7
|
|
|
7
|
1
|
1519001
|
my ($class, @params) = @_; |
|
16
|
7
|
|
|
|
|
29
|
my $self = bless {}, $class; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Flush stack on finalization. |
|
19
|
7
|
|
|
|
|
43
|
$self->{'flush_stack'} = 0; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Output handler. |
|
22
|
7
|
|
|
|
|
23
|
$self->{'output_handler'} = \*STDOUT; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# XML normalization rules. |
|
25
|
7
|
|
|
|
|
39
|
$self->{'rules'} = {}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Process params. |
|
28
|
7
|
|
|
|
|
39
|
set_params($self, @params); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Check to rules. |
|
31
|
5
|
100
|
|
|
|
66
|
if (! keys %{$self->{'rules'}}) { |
|
|
5
|
|
|
|
|
33
|
|
|
32
|
1
|
|
|
|
|
4
|
err 'Cannot exist XML normalization rules.'; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# PYX::Parser object. |
|
36
|
|
|
|
|
|
|
$self->{'pyx_parser'} = PYX::Parser->new( |
|
37
|
|
|
|
|
|
|
'callbacks' => { |
|
38
|
|
|
|
|
|
|
'data' => \&_end_element_simple, |
|
39
|
|
|
|
|
|
|
'end_element' => \&_end_element, |
|
40
|
|
|
|
|
|
|
'final' => \&_final, |
|
41
|
|
|
|
|
|
|
'start_element' => \&_start_element, |
|
42
|
|
|
|
|
|
|
}, |
|
43
|
|
|
|
|
|
|
'non_parser_options' => { |
|
44
|
|
|
|
|
|
|
'flush_stack' => $self->{'flush_stack'}, |
|
45
|
|
|
|
|
|
|
'rules' => $self->{'rules'}, |
|
46
|
|
|
|
|
|
|
'stack' => [], |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
4
|
|
|
|
|
84
|
'output_handler' => $self->{'output_handler'}, |
|
49
|
|
|
|
|
|
|
'output_rewrite' => 1, |
|
50
|
|
|
|
|
|
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Object. |
|
53
|
4
|
|
|
|
|
369
|
return $self; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Parse pyx text or array of pyx text. |
|
57
|
|
|
|
|
|
|
sub parse { |
|
58
|
1
|
|
|
1
|
1
|
2148
|
my ($self, $pyx, $out) = @_; |
|
59
|
1
|
|
|
|
|
10
|
$self->{'pyx_parser'}->parse($pyx, $out); |
|
60
|
1
|
|
|
|
|
8
|
return; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Parse file with pyx text. |
|
64
|
|
|
|
|
|
|
sub parse_file { |
|
65
|
7
|
|
|
7
|
1
|
17543
|
my ($self, $file) = @_; |
|
66
|
7
|
|
|
|
|
42
|
$self->{'pyx_parser'}->parse_file($file); |
|
67
|
7
|
|
|
|
|
165
|
return; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# Parse from handler. |
|
71
|
|
|
|
|
|
|
sub parse_handler { |
|
72
|
1
|
|
|
1
|
1
|
1189
|
my ($self, $input_file_handler, $out) = @_; |
|
73
|
1
|
|
|
|
|
5
|
$self->{'pyx_parser'}->parse_handler($input_file_handler, $out); |
|
74
|
1
|
|
|
|
|
3
|
return; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# Process start of element. |
|
78
|
|
|
|
|
|
|
sub _start_element { |
|
79
|
55
|
|
|
55
|
|
5756
|
my ($pyx_parser, $tag) = @_; |
|
80
|
55
|
|
|
|
|
107
|
my $out = $pyx_parser->{'output_handler'}; |
|
81
|
55
|
|
|
|
|
110
|
my $rules = $pyx_parser->{'non_parser_options'}->{'rules'}; |
|
82
|
55
|
|
|
|
|
106
|
my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; |
|
83
|
55
|
50
|
|
|
|
146
|
if (exists $rules->{'*'}) { |
|
84
|
55
|
|
|
|
|
83
|
foreach my $tmp (@{$rules->{'*'}}) { |
|
|
55
|
|
|
|
|
137
|
|
|
85
|
275
|
100
|
100
|
|
|
753
|
if (@{$stack} > 0 && lc($stack->[-1]) eq $tmp) { |
|
|
275
|
|
|
|
|
1019
|
|
|
86
|
15
|
|
|
|
|
25
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
15
|
|
|
|
|
47
|
|
|
|
15
|
|
|
|
|
62
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
55
|
100
|
|
|
|
319
|
if (exists $rules->{lc($tag)}) { |
|
91
|
21
|
|
|
|
|
38
|
foreach my $tmp (@{$rules->{lc($tag)}}) { |
|
|
21
|
|
|
|
|
77
|
|
|
92
|
34
|
100
|
100
|
|
|
122
|
if (@{$stack} > 0 && lc($stack->[-1]) eq $tmp) { |
|
|
34
|
|
|
|
|
156
|
|
|
93
|
7
|
|
|
|
|
13
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
27
|
|
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
55
|
|
|
|
|
233
|
push @{$stack}, $tag; |
|
|
55
|
|
|
|
|
198
|
|
|
98
|
55
|
|
|
|
|
90
|
print {$out} $pyx_parser->line, "\n"; |
|
|
55
|
|
|
|
|
214
|
|
|
99
|
55
|
|
|
|
|
2084
|
return; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# Add implicit end_element. |
|
103
|
|
|
|
|
|
|
sub _end_element_simple { |
|
104
|
11
|
|
|
11
|
|
1062
|
my $pyx_parser = shift; |
|
105
|
11
|
|
|
|
|
27
|
my $rules = $pyx_parser->{'non_parser_options'}->{'rules'}; |
|
106
|
11
|
|
|
|
|
21
|
my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; |
|
107
|
11
|
|
|
|
|
16
|
my $out = $pyx_parser->{'output_handler'}; |
|
108
|
11
|
50
|
|
|
|
62
|
if (exists $rules->{'*'}) { |
|
109
|
11
|
|
|
|
|
18
|
foreach my $tmp (@{$rules->{'*'}}) { |
|
|
11
|
|
|
|
|
26
|
|
|
110
|
55
|
100
|
100
|
|
|
157
|
if (@{$stack} && lc $stack->[-1] eq $tmp) { |
|
|
55
|
|
|
|
|
191
|
|
|
111
|
2
|
|
|
|
|
5
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
9
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
11
|
|
|
|
|
20
|
print {$out} $pyx_parser->line, "\n"; |
|
|
11
|
|
|
|
|
39
|
|
|
116
|
11
|
|
|
|
|
476
|
return; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Process end of element |
|
120
|
|
|
|
|
|
|
sub _end_element { |
|
121
|
14
|
|
|
14
|
|
1026
|
my ($pyx_parser, $tag) = @_; |
|
122
|
14
|
|
|
|
|
54
|
my $out = $pyx_parser->{'output_handler'}; |
|
123
|
14
|
|
|
|
|
29
|
my $rules = $pyx_parser->{'non_parser_options'}->{'rules'}; |
|
124
|
14
|
|
|
|
|
29
|
my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; |
|
125
|
14
|
50
|
|
|
|
72
|
if (exists $rules->{'*'}) { |
|
126
|
14
|
|
|
|
|
22
|
foreach my $tmp (@{$rules->{'*'}}) { |
|
|
14
|
|
|
|
|
36
|
|
|
127
|
70
|
100
|
100
|
|
|
456
|
if (lc($tag) ne $tmp && lc($stack->[-1]) eq $tmp) { |
|
128
|
7
|
|
|
|
|
12
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
25
|
|
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
# XXX Myslim, ze tenhle blok je spatne. |
|
133
|
14
|
100
|
|
|
|
46
|
if (exists $rules->{$tag}) { |
|
134
|
8
|
|
|
|
|
16
|
foreach my $tmp (@{$rules->{$tag}}) { |
|
|
8
|
|
|
|
|
33
|
|
|
135
|
11
|
100
|
66
|
|
|
192
|
if (lc($tag) ne $tmp && lc($stack->[-1]) eq $tmp) { |
|
136
|
10
|
|
|
|
|
19
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
10
|
|
|
|
|
26
|
|
|
|
10
|
|
|
|
|
42
|
|
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
} |
|
140
|
14
|
50
|
|
|
|
202
|
if (lc($stack->[-1]) eq lc($tag)) { |
|
141
|
14
|
|
|
|
|
21
|
pop @{$stack}; |
|
|
14
|
|
|
|
|
37
|
|
|
142
|
|
|
|
|
|
|
} |
|
143
|
14
|
|
|
|
|
41
|
print {$out} $pyx_parser->line, "\n"; |
|
|
14
|
|
|
|
|
59
|
|
|
144
|
14
|
|
|
|
|
390
|
return; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Process final. |
|
148
|
|
|
|
|
|
|
sub _final { |
|
149
|
9
|
|
|
9
|
|
172
|
my $pyx_parser = shift; |
|
150
|
9
|
|
|
|
|
21
|
my $stack = $pyx_parser->{'non_parser_options'}->{'stack'}; |
|
151
|
9
|
|
|
|
|
19
|
my $out = $pyx_parser->{'output_handler'}; |
|
152
|
9
|
50
|
|
|
|
15
|
if (@{$stack} > 0) { |
|
|
9
|
|
|
|
|
47
|
|
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# If set, than flush stack. |
|
155
|
0
|
0
|
|
|
|
0
|
if ($pyx_parser->{'non_parser_options'}->{'flush_stack'}) { |
|
156
|
0
|
|
|
|
|
0
|
foreach my $tmp (reverse @{$stack}) { |
|
|
0
|
|
|
|
|
0
|
|
|
157
|
0
|
|
|
|
|
0
|
print {$out} end_element($tmp), "\n"; |
|
|
0
|
|
|
|
|
0
|
|
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
} |
|
161
|
9
|
|
|
|
|
20
|
return; |
|
162
|
|
|
|
|
|
|
} |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
1; |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
__END__ |