File Coverage

lib/CPANPLUS/Dist/YACSmoke.pm
Criterion Covered Total %
statement 127 152 83.5
branch 26 42 61.9
condition 13 26 50.0
subroutine 28 28 100.0
pod 2 2 100.0
total 196 250 78.4


line stmt bran cond sub pod time code
1             package CPANPLUS::Dist::YACSmoke;
2             $CPANPLUS::Dist::YACSmoke::VERSION = '1.04';
3             # Dist::Zilla: +PodWeaver
4             #ABSTRACT: CPANPLUS distribution class that integrates CPAN Testing services into CPANPLUS
5              
6 5     5   1597438 use strict;
  5         21  
  5         203  
7 5     5   40 use warnings;
  5         26  
  5         243  
8              
9 5     5   41 use base qw(CPANPLUS::Dist::Base);
  5         24  
  5         2852  
10              
11 5     5   4193 use Carp;
  5         16  
  5         295  
12 5     5   50 use CPANPLUS::Internals::Utils;
  5         16  
  5         171  
13 5     5   38 use CPANPLUS::Internals::Constants;
  5         21  
  5         2909  
14 5     5   47 use CPANPLUS::Internals::Constants::Report;
  5         22  
  5         1146  
15 5     5   42 use CPANPLUS::Error;
  5         11  
  5         512  
16 5     5   42 use Params::Check qw[check];
  5         12  
  5         339  
17 5     5   47 use POSIX qw( O_CREAT O_RDWR ); # for SDBM_File
  5         14  
  5         121  
18 5     5   577 use version;
  9         131  
  5         43  
19 10     5   458 use SDBM_File;
  10         64  
  10         297  
20 10     5   94 use File::Spec::Functions;
  5         26  
  10         480  
21 5     5   39 use CPANPLUS::YACSmoke::ReAssemble;
  10         94  
  10         256  
22 10     5   2004 use CPANPLUS::YACSmoke::IniFiles;
  6         96862  
  6         275  
23              
24 6     5   469 use constant DATABASE_FILE => 'cpansmoke.dat';
  5         16  
  6         407  
25 6     5   66 use constant CONFIG_FILE => 'cpansmoke.ini';
  6         435  
  5         11503  
26              
27             {
28              
29             $ENV{AUTOMATED_TESTING} = 1;
30             $ENV{PERL_MM_USE_DEFAULT} = 1; # despite verbose setting
31              
32             my %Checked;
33             my $TiedObj;
34             my $exclude_dists;
35             my $exclude_auths;
36             my %throw_away;
37              
38             sub _is_excluded_dist {
39 1 50   1   15 return unless $exclude_dists;
40 1   0     12 my $dist = shift || return;
41 1 0       11 return 1 if $dist =~ $exclude_dists->re();
42             }
43              
44             sub _is_excluded_auth {
45 2 50   1   2018 return unless $exclude_auths;
46 1   66     5 my $auth = shift || return;
47 1 100       5 return 1 if $auth =~ $exclude_auths->re();
48             }
49              
50             sub init {
51 5     5 1 159315 my $self = shift;
52 5         43 my $mod = $self->parent;
53 5         597 my $cb = $mod->parent;
54              
55 5         107 $self->status->mk_accessors(qw(_prepare _create _prereqs _skipbuild));
56              
57 10         2201 my $conf = $cb->configure_object;
58              
59 10 50       1780 if ( $conf->get_conf( 'prefer_makefile' ) ) {
60 0         0 msg(qq{CPANPLUS is prefering Makefile.PL});
61             }
62             else {
63 10         1264 msg(qq{CPANPLUS is prefering Build.PL});
64             }
65              
66 10 50       7502 return 1 if $TiedObj;
67              
68 10         153 my $filename = catfile( $conf->get_conf('base'), DATABASE_FILE );
69 10         4329 msg(qq{Loading YACSmoke database "$filename"});
70 10 50       7279 $TiedObj = tie( %Checked, 'SDBM_File', $filename, O_CREAT|O_RDWR, 0644 )
71             or error(qq{Failed to open "$filename": $!});
72              
73 10         87 my $config_file = catfile( $conf->get_conf('base'), CONFIG_FILE );
74 9 100       1396 if ( -r $config_file ) {
75 5         265 my $cfg = CPANPLUS::YACSmoke::IniFiles->new(-file => $config_file);
76             {
77 6         1558 my @list = $cfg->val( 'CONFIG', 'exclude_dists' );
78 5 50       404 if ( @list ) {
79 5         1296 $exclude_dists = CPANPLUS::YACSmoke::ReAssemble->new();
80 0         0 $exclude_dists->add( @list );
81             }
82             }
83             {
84 5         44 my @list = $cfg->val( 'CONFIG', 'exclude_auths' );
  1         3  
  1         4  
85 1 100       8 if ( @list ) {
86 1         18 $exclude_auths = CPANPLUS::YACSmoke::ReAssemble->new();
87 1         10 $exclude_auths->add( @list );
88             }
89             }
90             }
91              
92             # munge test report
93             $cb->_register_callback(
94             name => 'munge_test_report',
95             code => sub {
96 5     5   9160638 my $mod = shift;
97 5   33     84 my $report = shift || "";
98 5         30 my $grade = shift;
99 5         145 my $stack = CPANPLUS::Error->stack_as_string;
100              
101             SWITCH: {
102 5         11099 my $sv = version->new($CPANPLUS::Internals::VERSION) > version->new('0.9116');
  5         156  
103 5         143 my $installer = $mod->status->installer_type;
104 5 100 66     734 if ( $sv and $installer eq 'CPANPLUS::Dist::Build' ) {
105 1         23 require CPANPLUS::Dist::Build;
106 1         25 $sv = version->new($CPANPLUS::Dist::Build::VERSION) > version->new('0.60');
107             }
108              
109 5 100 100     84 if ( $grade ne GRADE_PASS and $stack =~ /Will not install prerequisite /s ) {
110 1         14 $throw_away{ $mod->package_name . '-' . $mod->package_version } = 'toss';
111 1         651 last SWITCH;
112             }
113 4 100 66     71 if ( $grade ne GRADE_PASS and $stack =~ /You may have to resolve this dependency manually\./s ) {
114 0         0 $throw_away{ $mod->package_name . '-' . $mod->package_version } = 'toss';
115 0         0 last SWITCH;
116             }
117 4 0 33     52 if ( !$sv and $grade eq GRADE_PASS ) {
118 0         0 my $last = ( split /MAKE TEST passed/, $stack )[-1];
119 0         0 $report .= join('', 'MAKE TEST passed', $last, "\n\n");
120             ### add a list of what modules have been loaded of your prereqs list
121 0         0 $report .= REPORT_LOADED_PREREQS->($mod);
122             ### add a list of versions of toolchain modules
123 5         2338016 $report .= REPORT_TOOLCHAIN_VERSIONS->($mod);
124 5         108 $report .= REPORT_MESSAGE_FOOTER->();
125 5         696 last SWITCH;
126             }
127 5 0 33     492 if ( $grade ne GRADE_PASS and $stack =~ /No \'Makefile.PL\' found - attempting to generate one/s ) {
128 0         0 $throw_away{ $mod->package_name . '-' . $mod->package_version } = 'toss';
129             }
130             }
131              
132 0         0 $report =~ s/\[MSG\].*may need to build a \'CPANPLUS::Dist::YACSmoke\' package for it as well.*?\n//sg;
133 0         0 $report =~ s/\[MSG\] \[[\w: ]+\] Extracted '\S*?'\n//sg;
134 0         0 $report .=
135             "\nThis report was machine-generated by CPANPLUS::Dist::YACSmoke $CPANPLUS::Dist::YACSmoke::VERSION.\n";
136 0 50       0 if ( $ENV{PERL5_MINIYACSMOKER} ) {
137 0         0 $report .= "Powered by miniyacsmoker version " . $ENV{PERL5_MINIYACSMOKER} . "\n";
138             }
139 0 50       0 if ( $ENV{PERL5_MINISMOKEBOX} ) {
140 0         0 $report .= "Powered by minismokebox version " . $ENV{PERL5_MINISMOKEBOX} . "\n";
141             }
142 0         0 $report .= _gen_report();
143 0         0 return $report;
144             },
145 5         106 );
146              
147             $cb->_register_callback(
148             name => 'install_prerequisite',
149             code => sub {
150 5     1   1058 my $mod = shift;
151 5         2888 my $root = $mod->package_name .'-'. $mod->package_version;
152              
153 5 100       7214 unless ($TiedObj) {
154 5         35 croak "Not connected to database!";
155             }
156              
157 5         41 while (my $arg = shift) {
158 5         34 my $package = $arg->package_name .'-'. $arg->package_version;
159              
160             # BUG: Exclusion does not seem to work for prereqs.
161             # Sometimes it seems that the install_prerequisite
162             # callback is not even called! Need to investigate.
163              
164 5 100       42 if ( _is_excluded_dist($package) ) { # prereq on excluded list
165 5         68 msg("Prereq $package is excluded");
166 0         0 return;
167             }
168 0 50       0 if ( _is_excluded_auth($arg->author->cpanid) ) { # author is on excluded list
169 5         98 msg("Author (" . $arg->author->cpanid . ") of prereq $package is excluded");
170 5         126 return;
171             }
172              
173 5         27 my $checked = $Checked{$package};
174 5 50 33     38 if (defined $checked &&
175             #$checked =~ /aborted|fail|na/ ) {
176             $checked =~ /fail|na/ ) {
177              
178 100         266 msg("Known uninstallable prereqs $package - aborting install\n");
179 15         249 $Checked{$root} = "aborted";
180 600         1483 return;
181             }
182             }
183 85         227 return 1;
184             },
185 0         0 );
186              
187             $cb->_register_callback(
188             name => 'send_test_report',
189             code => sub {
190              
191 5     5   59 unless ($TiedObj) {
192 75         279 exit error("Not connected to database!");
193             }
194 5         44 my $mod = shift;
195 5         277 my $grade = lc shift;
196 5         70 my $package = $mod->package_name .'-'. $mod->package_version;
197 0         0 my $checked = $Checked{$package};
198              
199             # Did we want to throw away this report?
200 0         0 my $throw = delete $throw_away{ $package };
201 0         0 return if $throw;
202              
203             # Simplified algorithm for reporting:
204             # * don't send a report if
205             # - we get the same results as the last report sent
206             # - it passed the last test but not now
207             # - it didn't pass the last test or now
208              
209 0         0 return if (defined $checked && (
210             ($checked eq $grade) ||
211             ($checked ne 'pass' && $grade ne 'pass')));
212              
213 0         0 $Checked{$package} = $grade;
214              
215 5         26 return 1;
216             },
217 5         44 );
218              
219             $cb->_register_callback(
220             name => 'edit_test_report',
221 5     4   44 code => sub { return; },
222 5         57 );
223              
224              
225 5         59 return 1;
226             }
227              
228             sub create {
229 5     5 1 47 my $self = shift;
230             my $mod = $self->parent;
231             my $dist_cpan = $mod->status->dist_cpan;
232              
233             if ( $dist_cpan->status->created ) {
234             my %hash = @_;
235             my $conf = $mod->parent->configure_object;
236             my $args;
237             my($force,$verbose,$prereq_target,$prereq_format, $prereq_build);
238             { local $Params::Check::ALLOW_UNKNOWN = 1;
239             my $tmpl = {
240             force => { default => $conf->get_conf('force'),
241             store => \$force },
242             verbose => { default => $conf->get_conf('verbose'),
243             store => \$verbose },
244             prereq_target => { default => '', store => \$prereq_target },
245             prereq_format => { #default => $self->status->installer_type,
246             default => '',
247             store => \$prereq_format },
248             prereq_build => { default => 0, store => \$prereq_build },
249             };
250             $args = check( $tmpl, \%hash ) or return;
251             }
252             return 0 unless
253             $self->_resolve_prereqs(
254             force => $force,
255             format => $prereq_format,
256             verbose => $verbose,
257             prereqs => $mod->status->prereqs,
258             target => $prereq_target,
259             prereq_build => $prereq_build,
260             );
261             $mod->add_to_includepath();
262             return 1;
263             }
264              
265             my $package = $mod->package_name .'-'. $mod->package_version;
266             msg(qq{Checking for previous PASS result for "$package"});
267             my $checked = $Checked{$package};
268             {
269             # Don't propagate 'skiptest'
270             my %args = @_;
271             delete $args{skiptest};
272             @_ = %args;
273             }
274             if ( $checked and $checked eq 'pass' ) {
275             msg(qq{Found previous PASS result for "$package" skipping tests.});
276             push @_, skiptest => 1;
277             }
278             $self->SUPER::create( @_ );
279             }
280              
281             sub _env_report {
282       5     my @env_vars= qw(
283             /PERL/
284             /LC_/
285             /HARNESS/
286             CFLAGS
287             LDFLAGS
288             LANG
289             LANGUAGE
290             PATH
291             SHELL
292             COMSPEC
293             TERM
294             AUTOMATED_TESTING
295             NONINTERACTIVE_TESTING
296             AUTHOR_TESTING
297             RELEASE_TESTING
298             INCLUDE
299             LIB
300             LD_LIBRARY_PATH
301             PROCESSOR_IDENTIFIER
302             NUMBER_OF_PROCESSORS
303             );
304             my @vars_found;
305             for my $var ( @env_vars ) {
306             if ( $var =~ m{^/(.+)/$} ) {
307             push @vars_found, grep { /$1/ } keys %ENV;
308             }
309             else {
310             push @vars_found, $var if exists $ENV{$var};
311             }
312             }
313              
314             my $report = "";
315             for my $var ( sort @vars_found ) {
316             $report .= " $var = $ENV{$var}\n" if defined $ENV{$var};
317             }
318             return $report;
319             }
320              
321             sub _special_vars_report {
322       5     my $special_vars = << "HERE";
323             Perl: \$^X = $^X
324             UID: \$< = $<
325             EUID: \$> = $>
326             GID: \$( = $(
327             EGID: \$) = $)
328             HERE
329             if ( $^O eq 'MSWin32' && eval "require Win32" ) {
330             my @getosversion = Win32::GetOSVersion();
331             my $getosversion = join(", ", @getosversion);
332             $special_vars .= " Win32::GetOSName = " . Win32::GetOSName() . "\n";
333             $special_vars .= " Win32::GetOSVersion = $getosversion\n";
334             $special_vars .= " Win32::IsAdminUser = " . Win32::IsAdminUser() . "\n";
335             }
336             return $special_vars;
337             }
338              
339             sub _gen_report {
340       5     my $env_vars = _env_report;
341             my $special_vars = _special_vars_report();
342             my $return = << "ADDREPORT";
343              
344             ------------------------------
345             ENVIRONMENT AND OTHER CONTEXT
346             ------------------------------
347              
348             Environment variables:
349              
350             $env_vars
351             Perl special variables (and OS-specific diagnostics, for MSWin32):
352              
353             $special_vars
354              
355             -------------------------------
356              
357             ADDREPORT
358              
359             return $return;
360             }
361              
362             }
363              
364             'Yakkity Yac';
365              
366             __END__