| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package MyCPAN::Indexer::TestCensus; |
|
4
|
1
|
|
|
1
|
|
833
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
7
|
1
|
|
|
1
|
|
5
|
no warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
41
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
990
|
use subs qw(get_caller_info); |
|
|
1
|
|
|
|
|
32
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
1
|
|
|
1
|
|
46
|
use vars qw($VERSION $logger); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
58
|
|
|
11
|
1
|
|
|
1
|
|
1400
|
use parent qw(MyCPAN::Indexer); |
|
|
1
|
|
|
|
|
336
|
|
|
|
1
|
|
|
|
|
6
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '1.28_12'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
MyCPAN::Indexer::TestCensus - Count the Test modules used in test suites |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use MyCPAN::Indexer; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This module implements the indexer_class and reporter_class components |
|
26
|
|
|
|
|
|
|
to allow C to count the test modules used in the |
|
27
|
|
|
|
|
|
|
indexed distributions. |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
It runs through the indexing and prints a report at the end of the run. |
|
30
|
|
|
|
|
|
|
You probably |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use Carp qw(croak); |
|
35
|
|
|
|
|
|
|
use Cwd qw(cwd); |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use Log::Log4perl; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
BEGIN { |
|
40
|
|
|
|
|
|
|
$logger = Log::Log4perl->get_logger( __PACKAGE__ ); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__PACKAGE__->run( @ARGV ) unless caller; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 Indexer class |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over 4 |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item examine_dist |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Given a distribution, unpack it, look at it, and report the findings. |
|
52
|
|
|
|
|
|
|
It does everything except the looking right now, so it merely croaks. |
|
53
|
|
|
|
|
|
|
Most of this needs to move out of run and into this method. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
{ |
|
58
|
|
|
|
|
|
|
my @methods = ( |
|
59
|
|
|
|
|
|
|
# method error message fatal |
|
60
|
|
|
|
|
|
|
[ 'unpack_dist', "Could not unpack distribtion!", 1 ], |
|
61
|
|
|
|
|
|
|
[ 'find_dist_dir', "Did not find distro directory!", 1 ], |
|
62
|
|
|
|
|
|
|
[ 'find_tests', "Could not find tests!", 0 ], |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub examine_dist |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
|
|
|
|
|
|
# TRACE( sub { get_caller_info } ); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
foreach my $tuple ( @methods ) |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
|
|
|
|
|
|
my( $method, $error, $die_on_error ) = @$tuple; |
|
72
|
|
|
|
|
|
|
$logger->debug( "examine_dist calling $method" ); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
unless( $_[0]->$method() ) |
|
75
|
|
|
|
|
|
|
{ |
|
76
|
|
|
|
|
|
|
$logger->error( $error ); |
|
77
|
|
|
|
|
|
|
if( $die_on_error ) # only if failure is fatal |
|
78
|
|
|
|
|
|
|
{ |
|
79
|
|
|
|
|
|
|
ERROR( "Stopping: $error" ); |
|
80
|
|
|
|
|
|
|
$_[0]->set_run_info( 'fatal_error', $error ); |
|
81
|
|
|
|
|
|
|
return; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
{ |
|
87
|
|
|
|
|
|
|
my @file_info = (); |
|
88
|
|
|
|
|
|
|
foreach my $file ( @{ $_[0]->dist_info( 'tests' ) } ) |
|
89
|
|
|
|
|
|
|
{ |
|
90
|
|
|
|
|
|
|
$logger->debug( "Processing test $file" ); |
|
91
|
|
|
|
|
|
|
my $hash = $_[0]->get_test_info( $file ); |
|
92
|
|
|
|
|
|
|
push @file_info, $hash; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$_[0]->set_dist_info( 'test_info', [ @file_info ] ); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return 1; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item setup_run_info |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Like C in C, but it remembers fewer |
|
105
|
|
|
|
|
|
|
things. The test census really just cares about statements in the test |
|
106
|
|
|
|
|
|
|
files, so the details about the run aren't as interesting. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub setup_run_info |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
|
|
|
|
|
|
# TRACE( sub { get_caller_info } ); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
require Config; |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
my $perl = Probe::Perl->new; |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
$_[0]->set_run_info( 'root_working_dir', cwd() ); |
|
119
|
|
|
|
|
|
|
$_[0]->set_run_info( 'run_start_time', time ); |
|
120
|
|
|
|
|
|
|
$_[0]->set_run_info( 'completed', 0 ); |
|
121
|
|
|
|
|
|
|
$_[0]->set_run_info( 'pid', $$ ); |
|
122
|
|
|
|
|
|
|
$_[0]->set_run_info( 'ppid', $_[0]->getppid ); |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$_[0]->set_run_info( 'indexer', ref $_[0] ); |
|
125
|
|
|
|
|
|
|
$_[0]->set_run_info( 'indexer_versions', $_[0]->VERSION ); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
return 1; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item setup_dist_info |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Like C in C, but it remembers fewer |
|
134
|
|
|
|
|
|
|
things. The test census really just cares about statements in the test |
|
135
|
|
|
|
|
|
|
files, so the details about the distribution aren't as interesting. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub setup_dist_info |
|
140
|
|
|
|
|
|
|
{ |
|
141
|
|
|
|
|
|
|
# TRACE( sub { get_caller_info } ); |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my( $self, $dist ) = @_; |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
$logger->debug( "Setting dist [$dist]\n" ); |
|
146
|
|
|
|
|
|
|
$self->set_dist_info( 'dist_file', $dist ); |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
return 1; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=back |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 Reporter class |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=over 4 |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item get_reporter( $Notes ) |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
C sets the C key in the C<$Notes> hash reference. The |
|
160
|
|
|
|
|
|
|
value is a code reference that takes the information collected about a distribution |
|
161
|
|
|
|
|
|
|
and counts the modules used in the test files. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
See L for details about what C expects |
|
164
|
|
|
|
|
|
|
and should do. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=cut |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
{ |
|
170
|
|
|
|
|
|
|
sub get_reporter |
|
171
|
|
|
|
|
|
|
{ |
|
172
|
|
|
|
|
|
|
#TRACE( sub { get_caller_info } ); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
my( $self ) = @_; |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
unlink "/Users/brian/Desktop/test_use"; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
my $reporter = sub { |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
my( $info ) = @_; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
my $test_files = $info->{dist_info}{test_info}; |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
dbmopen my %DBM, "/Users/brian/Desktop/test_use", 0755 or die "$!"; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
foreach my $test_file ( @$test_files ) |
|
187
|
|
|
|
|
|
|
{ |
|
188
|
|
|
|
|
|
|
my $uses = $test_file->{uses}; |
|
189
|
|
|
|
|
|
|
$logger->debug( "Found test modules @$uses" ); |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
foreach my $used_module ( @$uses ) |
|
192
|
|
|
|
|
|
|
{ |
|
193
|
|
|
|
|
|
|
$DBM{$used_module}++; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
} |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
dbmclose %DBM; |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
}; |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
$self->set_note( 'reporter', $reporter ); |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub final_words |
|
209
|
|
|
|
|
|
|
{ |
|
210
|
|
|
|
|
|
|
$logger->debug( "Final words from the Reporter" ); |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
our %DBM; |
|
213
|
|
|
|
|
|
|
dbmopen %DBM, "/Users/brian/Desktop/test_use", undef; |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
print "Found modules:\n"; |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
foreach my $module ( |
|
218
|
|
|
|
|
|
|
sort { $DBM{$b} <=> $DBM{$a} || $a cmp $b } keys %DBM ) |
|
219
|
|
|
|
|
|
|
{ |
|
220
|
|
|
|
|
|
|
next unless $module =~ m/^Test\b/; |
|
221
|
|
|
|
|
|
|
printf "%6d %s\n", $DBM{$module}, $module; |
|
222
|
|
|
|
|
|
|
} |
|
223
|
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
dbmclose %DBM; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=pod |
|
228
|
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
foreach my $file ( glob "*.yml" ) |
|
230
|
|
|
|
|
|
|
{ |
|
231
|
|
|
|
|
|
|
my $yaml = LoadFile( $file ); |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
my $test_files = $yaml->{dist_info}{test_info}; |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
foreach my $test_file ( @$test_files ) |
|
236
|
|
|
|
|
|
|
{ |
|
237
|
|
|
|
|
|
|
my $uses = $test_file->{uses}; |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
foreach my $used_module ( @$uses ) |
|
240
|
|
|
|
|
|
|
{ |
|
241
|
|
|
|
|
|
|
$Seen{$used_module}++; |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
} |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=back |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 TO DO |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=over 4 |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item Count the lines in the files |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=item Code stats? Lines of code, lines of pod, lines of comments |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=back |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
|
261
|
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
This code is in Github: |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
git://github.com/briandfoy/mycpan-indexer.git |
|
265
|
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 AUTHOR |
|
267
|
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
brian d foy, C<< >> |
|
269
|
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
Copyright (c) 2008-2013, brian d foy, All Rights Reserved. |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
|
275
|
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
1; |