line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PYX::Hist; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
217690
|
use strict; |
|
6
|
|
|
|
|
48
|
|
|
6
|
|
|
|
|
169
|
|
4
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
174
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
1959
|
use Class::Utils qw(set_params); |
|
6
|
|
|
|
|
37349
|
|
|
6
|
|
|
|
|
166
|
|
7
|
6
|
|
|
6
|
|
270
|
use Error::Pure qw(err); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
209
|
|
8
|
6
|
|
|
6
|
|
55
|
use List::Util qw(reduce); |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
288
|
|
9
|
6
|
|
|
6
|
|
2824
|
use PYX::Parser; |
|
6
|
|
|
|
|
76618
|
|
|
6
|
|
|
|
|
3619
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = 0.07; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Constructor. |
14
|
|
|
|
|
|
|
sub new { |
15
|
12
|
|
|
12
|
1
|
19793
|
my ($class, @params) = @_; |
16
|
12
|
|
|
|
|
32
|
my $self = bless {}, $class; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Output handler. |
19
|
12
|
|
|
|
|
44
|
$self->{'output_handler'} = \*STDOUT; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Process params. |
22
|
12
|
|
|
|
|
55
|
set_params($self, @params); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# PYX::Parser object. |
25
|
|
|
|
|
|
|
$self->{'_pyx_parser'} = PYX::Parser->new( |
26
|
|
|
|
|
|
|
'callbacks' => { |
27
|
|
|
|
|
|
|
'end_element' => \&_end_element, |
28
|
|
|
|
|
|
|
'final' => \&_final, |
29
|
|
|
|
|
|
|
'start_element' => \&_start_element, |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
'non_parser_options' => { |
32
|
|
|
|
|
|
|
'hist' => {}, |
33
|
|
|
|
|
|
|
'stack' => [], |
34
|
|
|
|
|
|
|
}, |
35
|
10
|
|
|
|
|
155
|
'output_handler' => $self->{'output_handler'}, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Object. |
39
|
10
|
|
|
|
|
569
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Parse pyx text or array of pyx text. |
43
|
|
|
|
|
|
|
sub parse { |
44
|
3
|
|
|
3
|
1
|
1859
|
my ($self, $pyx, $out) = @_; |
45
|
3
|
|
|
|
|
12
|
$self->{'_pyx_parser'}->parse($pyx, $out); |
46
|
1
|
|
|
|
|
6
|
return; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# Parse file with pyx text. |
50
|
|
|
|
|
|
|
sub parse_file { |
51
|
3
|
|
|
3
|
1
|
1610
|
my ($self, $file, $out) = @_; |
52
|
3
|
|
|
|
|
10
|
$self->{'_pyx_parser'}->parse_file($file, $out); |
53
|
1
|
|
|
|
|
23
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Parse from handler. |
57
|
|
|
|
|
|
|
sub parse_handler { |
58
|
3
|
|
|
3
|
1
|
1870
|
my ($self, $input_file_handler, $out) = @_; |
59
|
3
|
|
|
|
|
11
|
$self->{'_pyx_parser'}->parse_handler($input_file_handler, $out); |
60
|
1
|
|
|
|
|
6
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# End of element. |
64
|
|
|
|
|
|
|
sub _end_element { |
65
|
12
|
|
|
12
|
|
876
|
my ($pyx_parser_obj, $elem) = @_; |
66
|
12
|
|
|
|
|
68
|
my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'}; |
67
|
12
|
100
|
|
|
|
42
|
if ($stack_ar->[-1] eq $elem) { |
68
|
9
|
|
|
|
|
15
|
pop @{$stack_ar}; |
|
9
|
|
|
|
|
17
|
|
69
|
|
|
|
|
|
|
} else { |
70
|
3
|
|
|
|
|
16
|
err 'Bad end of element.', |
71
|
|
|
|
|
|
|
'Element', $elem; |
72
|
|
|
|
|
|
|
} |
73
|
9
|
|
|
|
|
19
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Finalize. |
77
|
|
|
|
|
|
|
sub _final { |
78
|
6
|
|
|
6
|
|
117
|
my $pyx_parser_obj = shift; |
79
|
6
|
|
|
|
|
13
|
my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'}; |
80
|
6
|
100
|
|
|
|
6
|
if (@{$stack_ar} > 0) { |
|
6
|
|
|
|
|
37
|
|
81
|
3
|
|
|
|
|
14
|
err 'Stack has some elements.'; |
82
|
|
|
|
|
|
|
} |
83
|
3
|
|
|
|
|
11
|
my $hist_hr = $pyx_parser_obj->{'non_parser_options'}->{'hist'}; |
84
|
3
|
50
|
|
3
|
|
23
|
my $max_len = length reduce { length($a) > length($b) ? $a : $b } |
85
|
3
|
|
|
|
|
31
|
keys %{$hist_hr}; |
|
3
|
|
|
|
|
35
|
|
86
|
3
|
|
|
|
|
16
|
my $out = $pyx_parser_obj->{'output_handler'}; |
87
|
3
|
|
|
|
|
6
|
foreach my $key (sort keys %{$hist_hr}) { |
|
3
|
|
|
|
|
18
|
|
88
|
6
|
|
|
|
|
15
|
printf {$out} "[ %-${max_len}s ] %s\n", $key, $hist_hr->{$key}; |
|
6
|
|
|
|
|
273
|
|
89
|
|
|
|
|
|
|
} |
90
|
3
|
|
|
|
|
20
|
return; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Start of element. |
94
|
|
|
|
|
|
|
sub _start_element { |
95
|
18
|
|
|
18
|
|
1848
|
my ($pyx_parser_obj, $elem) = @_; |
96
|
18
|
|
|
|
|
37
|
my $stack_ar = $pyx_parser_obj->{'non_parser_options'}->{'stack'}; |
97
|
18
|
|
|
|
|
21
|
push @{$stack_ar}, $elem; |
|
18
|
|
|
|
|
44
|
|
98
|
18
|
100
|
|
|
|
47
|
if (! $pyx_parser_obj->{'non_parser_options'}->{'hist'}->{$elem}) { |
99
|
15
|
|
|
|
|
40
|
$pyx_parser_obj->{'non_parser_options'}->{'hist'}->{$elem} = 1; |
100
|
|
|
|
|
|
|
} else { |
101
|
3
|
|
|
|
|
8
|
$pyx_parser_obj->{'non_parser_options'}->{'hist'}->{$elem}++; |
102
|
|
|
|
|
|
|
} |
103
|
18
|
|
|
|
|
38
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |