line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PYX::Stack; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
6
|
|
|
6
|
|
147996
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
168
|
|
5
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
192
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Modules. |
8
|
6
|
|
|
6
|
|
2355
|
use Class::Utils qw(set_params); |
|
6
|
|
|
|
|
79243
|
|
|
6
|
|
|
|
|
229
|
|
9
|
6
|
|
|
6
|
|
237
|
use Error::Pure qw(err); |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
248
|
|
10
|
6
|
|
|
6
|
|
5201
|
use PYX::Parser; |
|
6
|
|
|
|
|
8219
|
|
|
6
|
|
|
|
|
4049
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Version. |
13
|
|
|
|
|
|
|
our $VERSION = 0.04; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Constructor. |
16
|
|
|
|
|
|
|
sub new { |
17
|
15
|
|
|
15
|
1
|
28536
|
my ($class, @params) = @_; |
18
|
15
|
|
|
|
|
39
|
my $self = bless {}, $class; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Check bad end of element. |
21
|
15
|
|
|
|
|
51
|
$self->{'bad_end'} = 0; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Output handler. |
24
|
15
|
|
|
|
|
50
|
$self->{'output_handler'} = \*STDOUT; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Verbose. |
27
|
15
|
|
|
|
|
31
|
$self->{'verbose'} = 0; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Process params. |
30
|
15
|
|
|
|
|
57
|
set_params($self, @params); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# PYX::Parser object. |
33
|
|
|
|
|
|
|
$self->{'_pyx_parser'} = PYX::Parser->new( |
34
|
|
|
|
|
|
|
'callbacks' => { |
35
|
|
|
|
|
|
|
'end_element' => \&_end_element, |
36
|
|
|
|
|
|
|
'start_element' => \&_start_element, |
37
|
|
|
|
|
|
|
'final' => \&_final, |
38
|
|
|
|
|
|
|
}, |
39
|
|
|
|
|
|
|
'non_parser_options' => { |
40
|
|
|
|
|
|
|
'bad_end' => $self->{'bad_end'}, |
41
|
|
|
|
|
|
|
'stack' => [], |
42
|
|
|
|
|
|
|
'verbose' => $self->{'verbose'}, |
43
|
|
|
|
|
|
|
}, |
44
|
13
|
|
|
|
|
228
|
'output_handler' => $self->{'output_handler'}, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Object. |
48
|
13
|
|
|
|
|
665
|
return $self; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Parse pyx text or array of pyx text. |
52
|
|
|
|
|
|
|
sub parse { |
53
|
4
|
|
|
4
|
1
|
1125
|
my ($self, $pyx, $out) = @_; |
54
|
4
|
|
|
|
|
14
|
$self->{'_pyx_parser'}->parse($pyx, $out); |
55
|
1
|
|
|
|
|
5
|
return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Parse file with pyx text. |
59
|
|
|
|
|
|
|
sub parse_file { |
60
|
4
|
|
|
4
|
1
|
1156
|
my ($self, $file, $out) = @_; |
61
|
4
|
|
|
|
|
14
|
$self->{'_pyx_parser'}->parse_file($file, $out); |
62
|
1
|
|
|
|
|
13
|
return; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# Parse from handler. |
66
|
|
|
|
|
|
|
sub parse_handler { |
67
|
4
|
|
|
4
|
1
|
1642
|
my ($self, $input_file_handler, $out) = @_; |
68
|
4
|
|
|
|
|
21
|
$self->{'_pyx_parser'}->parse_handler($input_file_handler, $out); |
69
|
1
|
|
|
|
|
3
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# End of element. |
73
|
|
|
|
|
|
|
sub _end_element { |
74
|
15
|
|
|
15
|
|
515
|
my ($pyx_parser_obj, $elem) = @_; |
75
|
15
|
|
|
|
|
33
|
my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'}; |
76
|
15
|
100
|
|
|
|
57
|
if ($stack_ar->[-1] eq $elem) { |
|
|
100
|
|
|
|
|
|
77
|
9
|
|
|
|
|
14
|
pop @{$stack_ar}; |
|
9
|
|
|
|
|
19
|
|
78
|
|
|
|
|
|
|
} elsif ($pyx_parser_obj->{'non_parser_options'}->{'bad_end'}) { |
79
|
3
|
|
|
|
|
15
|
err 'Bad end of element.', |
80
|
|
|
|
|
|
|
'Element', $elem; |
81
|
|
|
|
|
|
|
} |
82
|
12
|
100
|
100
|
|
|
45
|
if ($pyx_parser_obj->{'non_parser_options'}->{'verbose'} |
83
|
9
|
|
|
|
|
51
|
&& @{$stack_ar} > 0) { |
84
|
|
|
|
|
|
|
|
85
|
6
|
|
|
|
|
11
|
my $out = $pyx_parser_obj->{'output_handler'}; |
86
|
6
|
|
|
|
|
12
|
print {$out} join('/', @{$stack_ar}), "\n"; |
|
6
|
|
|
|
|
25
|
|
|
6
|
|
|
|
|
73
|
|
87
|
|
|
|
|
|
|
} |
88
|
12
|
|
|
|
|
35
|
return; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Finalize. |
92
|
|
|
|
|
|
|
sub _final { |
93
|
9
|
|
|
9
|
|
117
|
my $pyx_parser_obj = shift; |
94
|
9
|
|
|
|
|
18
|
my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'}; |
95
|
9
|
100
|
|
|
|
20
|
if (@{$stack_ar} > 0) { |
|
9
|
|
|
|
|
40
|
|
96
|
6
|
|
|
|
|
26
|
err 'Stack has some elements.'; |
97
|
|
|
|
|
|
|
} |
98
|
3
|
|
|
|
|
10
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Start of element. |
102
|
|
|
|
|
|
|
sub _start_element { |
103
|
24
|
|
|
24
|
|
1043
|
my ($pyx_parser_obj, $elem) = @_; |
104
|
24
|
|
|
|
|
49
|
my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'}; |
105
|
24
|
|
|
|
|
40
|
my $out = $pyx_parser_obj->{'output_handler'}; |
106
|
24
|
|
|
|
|
35
|
push @{$stack_ar}, $elem; |
|
24
|
|
|
|
|
54
|
|
107
|
24
|
100
|
|
|
|
83
|
if ($pyx_parser_obj->{'non_parser_options'}->{'verbose'}) { |
108
|
9
|
|
|
|
|
13
|
print {$out} join('/', @{$stack_ar}), "\n"; |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
346
|
|
109
|
|
|
|
|
|
|
} |
110
|
24
|
|
|
|
|
73
|
return; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
__END__ |