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