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