line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perl::ToPerl6::Statistics; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18
|
use 5.006001; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use English qw(-no_match_vars); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
1
|
|
|
1
|
1
|
3
|
my ( $class ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
4
|
my $self = bless {}, $class; |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
7
|
$self->{_modules} = 0; |
17
|
1
|
|
|
|
|
3
|
$self->{_subs} = 0; |
18
|
1
|
|
|
|
|
2
|
$self->{_statements} = 0; |
19
|
1
|
|
|
|
|
4
|
$self->{_lines} = 0; |
20
|
1
|
|
|
|
|
2
|
$self->{_transformations_by_transformer} = {}; |
21
|
1
|
|
|
|
|
3
|
$self->{_transformations_by_necessity} = {}; |
22
|
1
|
|
|
|
|
3
|
$self->{_total_transformations} = 0; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
4
|
return $self; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub accumulate { |
30
|
0
|
|
|
0
|
1
|
|
my ($self, $doc, $transformations) = @_; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
$self->{_modules}++; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $subs = $doc->find('PPI::Statement::Sub'); |
35
|
0
|
0
|
|
|
|
|
if ($subs) { |
36
|
0
|
|
|
|
|
|
foreach my $sub ( @{$subs} ) { |
|
0
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$self->{_subs}++; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $statements = $doc->find('PPI::Statement'); |
42
|
0
|
0
|
|
|
|
|
$self->{_statements} += $statements ? scalar @{$statements} : 0; |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my @lines = split /$INPUT_RECORD_SEPARATOR/, $doc->serialize(); |
45
|
|
|
|
|
|
|
## use mogrify |
46
|
0
|
|
|
|
|
|
$self->{_lines} += scalar @lines; |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
|
|
|
my ( $in_data, $in_pod ); |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
foreach ( @lines ) { |
50
|
0
|
0
|
0
|
|
|
|
if ( q{=} eq substr $_, 0, 1 ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$in_pod = not m/ \A \s* =cut \b /smx; |
52
|
|
|
|
|
|
|
} elsif ( $in_pod ) { |
53
|
|
|
|
|
|
|
} elsif ( q{__END__} eq $_ || q{__DATA__} eq $_ ) { |
54
|
0
|
|
|
|
|
|
$in_data = 1; |
55
|
|
|
|
|
|
|
} elsif ( $in_data ) { |
56
|
|
|
|
|
|
|
} elsif ( m/ \A \s* \# /smx ) { |
57
|
|
|
|
|
|
|
} else { |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
foreach my $transformation ( @{ $transformations } ) { |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$self->{_transformations_by_necessity}->{ $transformation->necessity() }++; |
64
|
0
|
|
|
|
|
|
$self->{_transformations_by_transformer}->{ $transformation->transformer() }++; |
65
|
0
|
|
|
|
|
|
$self->{_total_transformations}++; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub modules { |
74
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $self->{_modules}; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub subs { |
82
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
return $self->{_subs}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub statements { |
90
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self->{_statements}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub lines { |
98
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
return $self->{_lines}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub transformations_by_necessity { |
106
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->{_transformations_by_necessity}; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub transformations_by_transformer { |
114
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $self->{_transformations_by_transformer}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub total_transformations { |
122
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
return $self->{_total_transformations}; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub statements_other_than_subs { |
130
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return $self->statements() - $self->subs(); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub transformations_per_file { |
140
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
return if $self->modules() == 0; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
return $self->total_transformations() / $self->modules(); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub transformations_per_statement { |
150
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $statements = $self->statements_other_than_subs(); |
153
|
|
|
|
|
|
|
|
154
|
0
|
0
|
|
|
|
|
return if $statements == 0; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
return $self->total_transformations() / $statements; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
sub transformations_per_line_of_code { |
162
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
163
|
|
|
|
|
|
|
|
164
|
0
|
0
|
|
|
|
|
return if $self->lines() == 0; |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
return $self->total_transformations() / $self->lines(); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
__END__ |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=pod |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 NAME |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Perl::ToPerl6::Statistics - Compile stats on Perl::ToPerl6 transformations. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 DESCRIPTION |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This class accumulates statistics on Perl::ToPerl6 transformations across one or |
187
|
|
|
|
|
|
|
more files. NOTE: This class is experimental and subject to change. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 INTERFACE SUPPORT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
This is considered to be a non-public class. Its interface is subject |
193
|
|
|
|
|
|
|
to change without notice. |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 METHODS |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=over |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item C<new()> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Create a new instance of Perl::ToPerl6::Statistics. No arguments are supported |
203
|
|
|
|
|
|
|
at this time. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item C< accumulate( $doc, \@transformations ) > |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Accumulates statistics about the C<$doc> and the C<@transformations> that were |
209
|
|
|
|
|
|
|
found. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item C<modules()> |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
The number of chunks of code (usually files) that have been analyzed. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item C<subs()> |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
The total number of subroutines analyzed by this ToPerl6. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item C<statements()> |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
The total number of statements analyzed by this ToPerl6. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=item C<lines()> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
The total number of lines of code analyzed by this ToPerl6. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item C<transformations_by_necessity()> |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
The number of transformations of each necessity found by this ToPerl6 as a |
235
|
|
|
|
|
|
|
reference to a hash keyed by necessity. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=item C<transformations_by_transformer()> |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
The number of transformations of each transformer found by this ToPerl6 as a |
241
|
|
|
|
|
|
|
reference to a hash keyed by full transformer name. |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=item C<total_transformations()> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
The total number of transformations found by this ToPerl6. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=item C<statements_other_than_subs()> |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
The total number of statements minus the number of subroutines. |
252
|
|
|
|
|
|
|
Useful because a subroutine is considered a statement by PPI. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item C<transformations_per_file()> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
The total transformations divided by the number of modules. |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=item C<transformations_per_statement()> |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
The total transformations divided by the number statements minus |
263
|
|
|
|
|
|
|
subroutines. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item C<transformations_per_line_of_code()> |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
The total transformations divided by the lines of code. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=back |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=head1 AUTHOR |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
Elliot Shank C<< <perl@galumph.com> >> |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=head1 COPYRIGHT |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
Copyright (c) 2007-2011 Elliot Shank. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
284
|
|
|
|
|
|
|
it under the same terms as Perl itself. The full text of this license |
285
|
|
|
|
|
|
|
can be found in the LICENSE file included with this module. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=cut |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
############################################################################## |
290
|
|
|
|
|
|
|
# Local Variables: |
291
|
|
|
|
|
|
|
# mode: cperl |
292
|
|
|
|
|
|
|
# cperl-indent-level: 4 |
293
|
|
|
|
|
|
|
# fill-column: 78 |
294
|
|
|
|
|
|
|
# indent-tabs-mode: nil |
295
|
|
|
|
|
|
|
# c-indentation-style: bsd |
296
|
|
|
|
|
|
|
# End: |
297
|
|
|
|
|
|
|
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround : |