line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MyCPAN::Indexer::Reporter::Base; |
2
|
1
|
|
|
1
|
|
643
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use parent qw(MyCPAN::Indexer::Component); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
52
|
use vars qw($VERSION $logger); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
67
|
|
7
|
|
|
|
|
|
|
$VERSION = '1.28_12'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use Carp qw(croak confess); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
80
|
|
10
|
1
|
|
|
1
|
|
6
|
use File::Basename qw(basename); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
11
|
1
|
|
|
1
|
|
6
|
use File::Spec::Functions; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
94
|
|
12
|
1
|
|
|
1
|
|
7
|
use Log::Log4perl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
1
|
|
|
1
|
|
67
|
$logger = Log::Log4perl->get_logger( 'Reporter' ); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 NAME |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
MyCPAN::Indexer::Reporter::Base - Common bits for MyCPAN reporter classes |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Use this as a base class in you reporter classes. Extend or override the |
25
|
|
|
|
|
|
|
parts that you need. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
This is a base class for MyCPAN reporters. It mostly deals with file |
30
|
|
|
|
|
|
|
and directory names that it composes from configuration and run details. |
31
|
|
|
|
|
|
|
Most things should just use what is already there. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
There is one abstract method that a subclass must implement on its own. |
34
|
|
|
|
|
|
|
The C methods allows each reporter to have |
35
|
|
|
|
|
|
|
a unique extension by which it can recognize its own reports. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 Methods |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item component_type |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
This returns the C. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
1
|
|
sub component_type { $_[0]->reporter_type } |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item get_report_path( $info, $Notes ) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns the path of the file that stores the run results. It puts |
52
|
|
|
|
|
|
|
together the configuration for the C<{success|error}_report_subdir>, |
53
|
|
|
|
|
|
|
the distribution name, and the distribution extension. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
You should probably leave this alone. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub get_report_path |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
1
|
|
my( $self, $info ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
catfile( |
64
|
0
|
|
|
|
|
|
map { $self->$_( $info ) } qw( |
65
|
|
|
|
|
|
|
get_report_subdir |
66
|
|
|
|
|
|
|
get_report_filename |
67
|
|
|
|
|
|
|
) |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item get_report_subdir |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Return the subdirectory under the C for the report, depending |
74
|
|
|
|
|
|
|
on the success of the indexing. |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub get_report_subdir |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
0
|
1
|
|
my( $self, $info ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
$logger->warn( "Argument doesn't know how to run_info!" ) |
83
|
0
|
0
|
|
|
|
|
unless eval { $info->can( 'run_info' ) }; |
|
0
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $config = $self->get_config; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
my $dir_key = $info->run_info( 'completed' ) |
88
|
|
|
|
|
|
|
? |
89
|
|
|
|
|
|
|
$self->get_success_report_subdir |
90
|
|
|
|
|
|
|
: |
91
|
|
|
|
|
|
|
$self->get_error_report_subdir; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
$dir_key = $self->get_error_report_subdir |
94
|
0
|
0
|
|
|
|
|
if grep { $info->run_info($_) } qw(error fatal_error); |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
$config->get( "${dir_key}_report_subdir" ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item get_report_filename |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the filename portion of the report path based on the examined |
102
|
|
|
|
|
|
|
distribution name. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
You should probably leave this alone. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_report_filename |
109
|
|
|
|
|
|
|
{ |
110
|
0
|
|
|
0
|
1
|
|
my( $self, $arg ) = @_; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $dist_file = do { |
113
|
0
|
0
|
|
|
|
|
if( ref $arg ) { $arg->{dist_info}{dist_file} } |
|
0
|
0
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
elsif( defined $arg ) { $arg } |
115
|
|
|
|
|
|
|
}; |
116
|
0
|
0
|
|
|
|
|
$logger->logcroak( "Did not get a distribution file name!" ) |
117
|
|
|
|
|
|
|
unless $dist_file; |
118
|
|
|
|
|
|
|
|
119
|
1
|
|
|
1
|
|
372
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
536
|
|
120
|
0
|
|
|
|
|
|
( my $basename = basename( $dist_file ) ) =~ s/\.(tgz|tar\.gz|zip)$//; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $rel_path = $self->get_dist_report_subdir( |
123
|
|
|
|
|
|
|
join '.', $basename, $self->get_report_file_extension |
124
|
|
|
|
|
|
|
); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item get_dist_report_subdir( FILENAME ) |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Creates a subdirectory path from a report name. There are 150,000 |
130
|
|
|
|
|
|
|
distributions so we shouldn't put all of those in one directory. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
For a report such as F, the subdirectory path is |
133
|
|
|
|
|
|
|
F. The method is fairly dumb about it since |
134
|
|
|
|
|
|
|
it does not care what the first two characters are. If the report name |
135
|
|
|
|
|
|
|
is F<-0.01.yml> (yep, there really is), the path is F<-/-0/-0.01.yml>. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub get_dist_report_subdir |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
|
|
0
|
1
|
|
my( $self, $filename ) = @_; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
catfile( |
144
|
|
|
|
|
|
|
substr( $filename, 0, 1 ), |
145
|
|
|
|
|
|
|
substr( $filename, 0, 2 ), |
146
|
|
|
|
|
|
|
$filename |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item get_report_file_extension |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Returns the filename portion of the report path based on the examined |
153
|
|
|
|
|
|
|
distribution name. This is an abstract method which you must override. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Every reporter should chose their own extension. This allows each |
156
|
|
|
|
|
|
|
reporter to recognize their previous results. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=cut |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub get_report_file_extension |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
|
|
0
|
1
|
|
$logger->logcroak( |
163
|
|
|
|
|
|
|
'You must implement get_report_file_extension in a derived class!' |
164
|
|
|
|
|
|
|
); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item get_successful_report_path( DIST ) |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Returns the filename for a successful report. This is slightly |
170
|
|
|
|
|
|
|
different from C which might also return the |
171
|
|
|
|
|
|
|
filename for an success report. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=cut |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub get_successful_report_path |
176
|
|
|
|
|
|
|
{ |
177
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
catfile( |
180
|
0
|
|
|
|
|
|
map { $self->$_( @_ ) } qw( |
181
|
|
|
|
|
|
|
get_success_report_dir |
182
|
|
|
|
|
|
|
get_report_filename |
183
|
|
|
|
|
|
|
) |
184
|
|
|
|
|
|
|
); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item get_error_report_path( DIST ) |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Returns the filename for a error report. This is slightly different |
190
|
|
|
|
|
|
|
from C which might also return the |
191
|
|
|
|
|
|
|
filename for an error report. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub get_error_report_path |
196
|
|
|
|
|
|
|
{ |
197
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
catfile( |
200
|
0
|
|
|
|
|
|
map { $self->$_( @_ ) } qw( |
201
|
|
|
|
|
|
|
get_error_report_dir |
202
|
|
|
|
|
|
|
get_report_filename |
203
|
|
|
|
|
|
|
) |
204
|
|
|
|
|
|
|
); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item get_success_report_subdir |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item get_error_report_subdir |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Returns the subdirectory name for a report. This is just the subdirectory, |
212
|
|
|
|
|
|
|
not the full path. |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
The defaults are F and F. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=cut |
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
0
|
1
|
|
sub get_success_report_subdir { 'success' } |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
0
|
1
|
|
sub get_error_report_subdir { 'error' } |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item get_success_report_dir |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=item get_error_report_dir |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Returns the path to the report directory. This combines the subdirectory |
227
|
|
|
|
|
|
|
name and the report path. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=cut |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub get_success_report_dir |
232
|
|
|
|
|
|
|
{ |
233
|
0
|
|
|
0
|
1
|
|
catfile( |
234
|
|
|
|
|
|
|
$_[0]->get_config->report_dir, |
235
|
|
|
|
|
|
|
$_[0]->get_success_report_subdir |
236
|
|
|
|
|
|
|
); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub get_error_report_dir |
240
|
|
|
|
|
|
|
{ |
241
|
0
|
|
|
0
|
1
|
|
catfile( |
242
|
|
|
|
|
|
|
$_[0]->get_config->report_dir, |
243
|
|
|
|
|
|
|
$_[0]->get_error_report_subdir |
244
|
|
|
|
|
|
|
); |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=item check_for_previous_successful_result( $dist ) |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Returns false (!) if it looks like there is already a successful report |
250
|
|
|
|
|
|
|
for the noted distribution. If there is not a successful report, |
251
|
|
|
|
|
|
|
it returns the filename it expected to find. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub check_for_previous_successful_result |
256
|
|
|
|
|
|
|
{ |
257
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
258
|
|
|
|
|
|
|
|
259
|
0
|
|
|
|
|
|
my $path = $self->get_successful_report_path( @_ ); |
260
|
0
|
0
|
|
|
|
|
return if -e $path; |
261
|
|
|
|
|
|
|
|
262
|
0
|
|
|
|
|
|
basename( $path ); |
263
|
|
|
|
|
|
|
} |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item check_for_previous_error_result( $dist ) |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Return the report filename if there was an error report for $dist, |
268
|
|
|
|
|
|
|
and false otherwise. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=cut |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
sub check_for_previous_error_result |
273
|
|
|
|
|
|
|
{ |
274
|
0
|
|
|
0
|
1
|
|
my( $self, $dist ) = @_; |
275
|
0
|
|
|
|
|
|
my $path = $self->get_error_report_path( $dist ); |
276
|
0
|
0
|
|
|
|
|
return -e $path ? basename( $path ) : (); |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=back |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=head1 SOURCE AVAILABILITY |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
This code is in Github: |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
git://github.com/briandfoy/mycpan-indexer.git |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=head1 AUTHOR |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
brian d foy, C<< >> |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Copyright (c) 2008-2013, brian d foy, All Rights Reserved. |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
You may redistribute this under the same terms as Perl itself. |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=cut |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
1; |