| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PYX::XMLNorm; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
|
4
|
7
|
|
|
7
|
|
211635
|
use strict; |
|
|
7
|
|
|
|
|
14
|
|
|
|
7
|
|
|
|
|
270
|
|
|
5
|
7
|
|
|
7
|
|
30
|
use warnings; |
|
|
7
|
|
|
|
|
12
|
|
|
|
7
|
|
|
|
|
259
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Modules. |
|
8
|
7
|
|
|
7
|
|
2339
|
use Class::Utils qw(set_params); |
|
|
7
|
|
|
|
|
93454
|
|
|
|
7
|
|
|
|
|
220
|
|
|
9
|
7
|
|
|
7
|
|
289
|
use Error::Pure qw(err); |
|
|
7
|
|
|
|
|
9
|
|
|
|
7
|
|
|
|
|
266
|
|
|
10
|
7
|
|
|
7
|
|
3813
|
use PYX qw(end_element); |
|
|
7
|
|
|
|
|
155031
|
|
|
|
7
|
|
|
|
|
146
|
|
|
11
|
7
|
|
|
7
|
|
5174
|
use PYX::Parser; |
|
|
7
|
|
|
|
|
9905
|
|
|
|
7
|
|
|
|
|
418
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Version. |
|
14
|
|
|
|
|
|
|
our $VERSION = 0.02; |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Global variables. |
|
17
|
7
|
|
|
7
|
|
58
|
use vars qw($stack $rules $flush_stack); |
|
|
7
|
|
|
|
|
9
|
|
|
|
7
|
|
|
|
|
7467
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Constructor. |
|
20
|
|
|
|
|
|
|
sub new { |
|
21
|
6
|
|
|
6
|
1
|
4288
|
my ($class, @params) = @_; |
|
22
|
6
|
|
|
|
|
19
|
my $self = bless {}, $class; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Flush stack on finalization. |
|
25
|
6
|
|
|
|
|
27
|
$self->{'flush_stack'} = 0; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Output handler. |
|
28
|
6
|
|
|
|
|
17
|
$self->{'output_handler'} = \*STDOUT; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# XML normalization rules. |
|
31
|
6
|
|
|
|
|
15
|
$self->{'rules'} = {}; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Process params. |
|
34
|
6
|
|
|
|
|
28
|
set_params($self, @params); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Check to rules. |
|
37
|
4
|
100
|
|
|
|
39
|
if (! keys %{$self->{'rules'}}) { |
|
|
4
|
|
|
|
|
25
|
|
|
38
|
1
|
|
|
|
|
4
|
err 'Cannot exist XML normalization rules.'; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# PYX::Parser object. |
|
42
|
3
|
|
|
|
|
50
|
$self->{'pyx_parser'} = PYX::Parser->new( |
|
43
|
|
|
|
|
|
|
'callbacks' => { |
|
44
|
|
|
|
|
|
|
'data' => \&_end_element_simple, |
|
45
|
|
|
|
|
|
|
'end_element' => \&_end_element, |
|
46
|
|
|
|
|
|
|
'final' => \&_final, |
|
47
|
|
|
|
|
|
|
'start_element' => \&_start_element, |
|
48
|
|
|
|
|
|
|
}, |
|
49
|
|
|
|
|
|
|
'output_handler' => $self->{'output_handler'}, |
|
50
|
|
|
|
|
|
|
'output_rewrite' => 1, |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Tag values. |
|
54
|
3
|
|
|
|
|
167
|
$stack = []; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Rules. |
|
57
|
3
|
|
|
|
|
11
|
$rules = $self->{'rules'}; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Flush stack. |
|
60
|
3
|
|
|
|
|
7
|
$flush_stack = $self->{'flush_stack'}; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Object. |
|
63
|
3
|
|
|
|
|
10
|
return $self; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Parse pyx text or array of pyx text. |
|
67
|
|
|
|
|
|
|
sub parse { |
|
68
|
1
|
|
|
1
|
1
|
1554
|
my ($self, $pyx, $out) = @_; |
|
69
|
1
|
|
|
|
|
8
|
$self->{'pyx_parser'}->parse($pyx, $out); |
|
70
|
1
|
|
|
|
|
5
|
return; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Parse file with pyx text. |
|
74
|
|
|
|
|
|
|
sub parse_file { |
|
75
|
0
|
|
|
0
|
1
|
0
|
my ($self, $file) = @_; |
|
76
|
0
|
|
|
|
|
0
|
$self->{'pyx_parser'}->parse_file($file); |
|
77
|
0
|
|
|
|
|
0
|
return; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Parse from handler. |
|
81
|
|
|
|
|
|
|
sub parse_handler { |
|
82
|
1
|
|
|
1
|
1
|
1582
|
my ($self, $input_file_handler, $out) = @_; |
|
83
|
1
|
|
|
|
|
8
|
$self->{'pyx_parser'}->parse_handler($input_file_handler, $out); |
|
84
|
1
|
|
|
|
|
4
|
return; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Process start of element. |
|
88
|
|
|
|
|
|
|
sub _start_element { |
|
89
|
16
|
|
|
16
|
|
511
|
my ($pyx_parser, $tag) = @_; |
|
90
|
16
|
|
|
|
|
25
|
my $out = $pyx_parser->{'output_handler'}; |
|
91
|
16
|
50
|
|
|
|
51
|
if (exists $rules->{'*'}) { |
|
92
|
16
|
|
|
|
|
15
|
foreach my $tmp (@{$rules->{'*'}}) { |
|
|
16
|
|
|
|
|
37
|
|
|
93
|
80
|
100
|
100
|
|
|
146
|
if (@{$stack} > 0 && lc($stack->[-1]) eq $tmp) { |
|
|
80
|
|
|
|
|
379
|
|
|
94
|
6
|
|
|
|
|
10
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
32
|
|
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
16
|
100
|
|
|
|
90
|
if (exists $rules->{lc($tag)}) { |
|
99
|
2
|
|
|
|
|
5
|
foreach my $tmp (@{$rules->{lc($tag)}}) { |
|
|
2
|
|
|
|
|
9
|
|
|
100
|
2
|
50
|
33
|
|
|
10
|
if (@{$stack} > 0 && lc($stack->[-1]) eq $tmp) { |
|
|
2
|
|
|
|
|
12
|
|
|
101
|
0
|
|
|
|
|
0
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
} |
|
105
|
16
|
|
|
|
|
19
|
push @{$stack}, $tag; |
|
|
16
|
|
|
|
|
41
|
|
|
106
|
16
|
|
|
|
|
26
|
print {$out} $pyx_parser->line, "\n"; |
|
|
16
|
|
|
|
|
65
|
|
|
107
|
16
|
|
|
|
|
422
|
return; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Add implicit end_element. |
|
111
|
|
|
|
|
|
|
sub _end_element_simple { |
|
112
|
0
|
|
|
0
|
|
0
|
my $pyx_parser = shift; |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Output handler. |
|
115
|
0
|
|
|
|
|
0
|
my $out = $pyx_parser->{'output_handler'}; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# Process. |
|
118
|
0
|
0
|
|
|
|
0
|
if (exists $rules->{'*'}) { |
|
119
|
0
|
|
|
|
|
0
|
foreach my $tmp (@{$rules->{'*'}}) { |
|
|
0
|
|
|
|
|
0
|
|
|
120
|
0
|
0
|
|
|
|
0
|
if (lc $stack->[-1] eq $tmp) { |
|
121
|
0
|
|
|
|
|
0
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
0
|
|
|
|
|
0
|
|
|
|
0
|
|
|
|
|
0
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# Print line. |
|
127
|
0
|
|
|
|
|
0
|
print {$out} $pyx_parser->line, "\n"; |
|
|
0
|
|
|
|
|
0
|
|
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
return; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Process end of element |
|
133
|
|
|
|
|
|
|
sub _end_element { |
|
134
|
4
|
|
|
4
|
|
164
|
my ($pyx_parser, $tag) = @_; |
|
135
|
4
|
|
|
|
|
11
|
my $out = $pyx_parser->{'output_handler'}; |
|
136
|
4
|
50
|
|
|
|
16
|
if (exists $rules->{'*'}) { |
|
137
|
4
|
|
|
|
|
5
|
foreach my $tmp (@{$rules->{'*'}}) { |
|
|
4
|
|
|
|
|
12
|
|
|
138
|
20
|
100
|
66
|
|
|
177
|
if (lc($tag) ne $tmp && lc($stack->[-1]) eq $tmp) { |
|
139
|
4
|
|
|
|
|
6
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
16
|
|
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
# XXX Myslim, ze tenhle blok je spatne. |
|
144
|
4
|
100
|
|
|
|
16
|
if (exists $rules->{$tag}) { |
|
145
|
2
|
|
|
|
|
6
|
foreach my $tmp (@{$rules->{$tag}}) { |
|
|
2
|
|
|
|
|
8
|
|
|
146
|
2
|
50
|
33
|
|
|
26
|
if (lc($tag) ne $tmp && lc($stack->[-1]) eq $tmp) { |
|
147
|
2
|
|
|
|
|
4
|
print {$out} end_element(pop @{$stack}), "\n"; |
|
|
2
|
|
|
|
|
8
|
|
|
|
2
|
|
|
|
|
10
|
|
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
} |
|
151
|
4
|
50
|
|
|
|
51
|
if (lc($stack->[-1]) eq lc($tag)) { |
|
152
|
4
|
|
|
|
|
6
|
pop @{$stack}; |
|
|
4
|
|
|
|
|
8
|
|
|
153
|
|
|
|
|
|
|
} |
|
154
|
4
|
|
|
|
|
6
|
print {$out} $pyx_parser->line, "\n"; |
|
|
4
|
|
|
|
|
19
|
|
|
155
|
4
|
|
|
|
|
63
|
return; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# Process final. |
|
159
|
|
|
|
|
|
|
sub _final { |
|
160
|
2
|
|
|
2
|
|
32
|
my $pyx_parser = shift; |
|
161
|
2
|
|
|
|
|
6
|
my $out = $pyx_parser->{'output_handler'}; |
|
162
|
2
|
50
|
|
|
|
3
|
if (@{$stack} > 0) { |
|
|
2
|
|
|
|
|
10
|
|
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# If set, than flush stack. |
|
165
|
0
|
0
|
|
|
|
0
|
if ($flush_stack) { |
|
166
|
0
|
|
|
|
|
0
|
foreach my $tmp (reverse @{$stack}) { |
|
|
0
|
|
|
|
|
0
|
|
|
167
|
0
|
|
|
|
|
0
|
print {$out} end_element($tmp), "\n"; |
|
|
0
|
|
|
|
|
0
|
|
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
} |
|
171
|
2
|
|
|
|
|
6
|
return; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |