Indexer/Reporter/Base.pm

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