File Coverage

blib/lib/App/SmokeBrew/Plugin/CPANPLUS/YACSmoke.pm
Criterion Covered Total %
statement 55 134 41.0
branch 2 38 5.2
condition 0 2 0.0
subroutine 15 20 75.0
pod 1 1 100.0
total 73 195 37.4


line stmt bran cond sub pod time code
1             $App::SmokeBrew::Plugin::CPANPLUS::YACSmoke::VERSION = '1.02';
2             #ABSTRACT: A smokebrew plugin for CPANPLUS::YACSmoke based smokers
3              
4             use strict;
5 1     1   669 use warnings;
  1         2  
  1         24  
6 1     1   5 use App::SmokeBrew::Tools;
  1         1  
  1         20  
7 1     1   374 use File::Fetch;
  1         20  
  1         31  
8 1     1   6 use File::Spec;
  1         1  
  1         18  
9 1     1   6 use Cwd qw[realpath];
  1         2  
  1         19  
10 1     1   4 use File::Path qw[rmtree mkpath];
  1         2  
  1         41  
11 1     1   10 use File::pushd qw[pushd];
  1         15  
  1         49  
12 1     1   415 use IPC::Cmd qw[run can_run];
  1         949  
  1         51  
13 1     1   6 use Log::Message::Simple qw[msg error];
  1         1  
  1         44  
14 1     1   381  
  1         7030  
  1         52  
15             use Moose;
16 1     1   451  
  1         385259  
  1         6  
17             with 'App::SmokeBrew::PerlVersion', 'App::SmokeBrew::Plugin';
18              
19             has '_cpanplus' => (
20             is => 'ro',
21             isa => 'Str',
22             init_arg => undef,
23             lazy_build => 1,
24             );
25              
26             my $self = shift;
27             $self->builddir->mkpath;
28 1     1   2 my $default = 'B/BI/BINGOS/CPANPLUS-0.9168.tar.gz';
29 1         28 my $path;
30 1         78 my $ff = File::Fetch->new( uri => 'http://cpanidx.org/cpanidx/yaml/mod/CPANPLUS' );
31 1         2 my $stat = $ff->fetch( to => $self->builddir->absolute );
32 1         26 require Parse::CPAN::Meta;
33 1         9122 my ($doc) = eval { Parse::CPAN::Meta::LoadFile( $stat ) };
34 1         108647 return $default unless $doc;
35 1         3615 $path = $doc->[0]->{dist_file};
  1         12  
36 1 50       11087 unlink( $stat );
37 1         5 return $path if $path;
38 1         67 return $default;
39 1 50       87 }
40 0            
41             my $self = shift;
42             $self->builddir->mkpath;
43             msg("Fetching '" . $self->_cpanplus . "'", $self->verbose);
44 0     0 1   my $loc = 'authors/id/' . $self->_cpanplus;
45 0           my $fetch = App::SmokeBrew::Tools->fetch( $loc, $self->builddir->absolute, $self->mirrors );
46 0           if ( $fetch ) {
47 0           msg("Fetched to '$fetch'", $self->verbose );
48 0           }
49 0 0         else {
50 0           error("Could not fetch '$loc'", $self->verbose );
51             return;
52             }
53 0           return unless $fetch;
54 0           msg("Extracting '$fetch'", $self->verbose);
55             my $extract = App::SmokeBrew::Tools->extract( $fetch, $self->builddir->absolute );
56 0 0         if ( $extract ) {
57 0           msg("Extracted to '$extract'", $self->verbose );
58 0           }
59 0 0         else {
60 0           error("Could not extract '$fetch'");
61             return;
62             }
63 0           return unless $extract;
64 0           unlink( $fetch ) unless $self->noclean();
65             my $perl = can_run( $self->perl_exe->absolute );
66 0 0         unless ( $perl ) {
67 0 0         error("Could not execute '" . $self->perl_exe->absolute . "'", $self->verbose );
68 0           return;
69 0 0         }
70 0           {
71 0           my $CWD = pushd( $extract );
72             use IO::Handle;
73             open my $boxed, '>', 'bin/boxer' or die "$!\n";
74 0           $boxed->autoflush(1);
  0            
75 1     1   6546 print $boxed $self->_boxed;
  1         2  
  1         175  
76 0 0         close $boxed;
77 0           my $cmd = [ $perl, 'bin/boxer' ];
78 0           local $ENV{PERL_MM_USE_DEFAULT} = 1;
79 0           return unless scalar run( command => $cmd, verbose => 1 );
80 0           }
81 0           rmtree( $extract ) unless $self->noclean();
82 0 0         my $conf = File::Spec->catdir( $self->prefix->absolute, 'conf', $self->perl_version );
83             mkpath( $conf );
84 0 0         {
85 0           local $ENV{APPDATA} = $conf;
86 0           my $cpconf = $self->_cpconf();
87             my $CWD = pushd( $self->builddir->absolute );
88 0           use IO::Handle;
  0            
89 0           open my $boxed, '>', 'cpconf.pl' or die "$!\n";
90 0           $boxed->autoflush(1);
91 1     1   6 print $boxed $cpconf;
  1         3  
  1         527  
92 0 0         close $boxed;
93 0           my $cmd = [ $perl, 'cpconf.pl', '--email', $self->email ];
94 0           push @$cmd, ( '--mx', $self->mx ) if $self->mx;
95 0           return unless scalar run( command => $cmd, verbose => 1 );
96 0           unlink( 'cpconf.pl' ) unless $self->noclean();
97 0 0         # Setup symlinks
98 0 0         if ( eval { symlink("",""); 1 } ) {
99 0 0         my $parent = realpath( File::Spec->catdir( $self->prefix->absolute, '..' ) );
100             my $authors = File::Spec->catdir( $parent, 'authors' );
101 0 0         my $smokeini = File::Spec->catfile( $parent, 'cpansmoke.ini' );
  0            
  0            
102 0           unless ( -e $smokeini ) {
103 0           open my $ini, '>', $smokeini or die "$!\n";
104 0           $ini->autoflush(1);
105 0 0         print $ini $self->_cpansmokeini;
106 0 0         close $ini;
107 0           }
108 0           mkpath( $authors ) unless -d $authors;
109 0           symlink( $authors, File::Spec->catdir( $conf, '.cpanplus', 'authors' ) );
110             symlink( $smokeini, File::Spec->catdir( $conf, '.cpanplus', 'cpansmoke.ini' ) );
111 0 0         }
112 0           }
113 0           return 1;
114             }
115              
116 0           my $self = shift;
117             return q+
118             BEGIN {
119             use strict;
120 0     0     use warnings;
121 0            
122             use Config;
123             use FindBin;
124             use File::Spec;
125             use File::Spec::Unix;
126              
127             use vars qw[@RUN_TIME_INC $LIB_DIR $BUNDLE_DIR $BASE $PRIV_LIB];
128             $LIB_DIR = File::Spec->catdir( $FindBin::Bin, qw[.. lib] );
129             $BUNDLE_DIR = File::Spec->catdir( $FindBin::Bin, qw[.. inc bundle] );
130              
131             my $who = getlogin || getpwuid($<) || $<;
132             $BASE = File::Spec->catfile(
133             $FindBin::Bin, '..', '.cpanplus', $who);
134             $PRIV_LIB = File::Spec->catfile( $BASE, 'lib' );
135              
136             @RUN_TIME_INC = ($PRIV_LIB, @INC);
137             unshift @INC, $LIB_DIR, $BUNDLE_DIR;
138              
139             $ENV{'PERL5LIB'} = join $Config{'path_sep'}, grep { defined }
140             $PRIV_LIB, # to find the boxed config
141             $LIB_DIR, # the CPANPLUS libs
142             $ENV{'PERL5LIB'}; # original PERL5LIB
143              
144             }
145              
146             use FindBin;
147             use File::Find qw[find];
148             use CPANPLUS::Error;
149             use CPANPLUS::Configure;
150             use CPANPLUS::Internals::Constants;
151             use CPANPLUS::Internals::Utils;
152              
153             { for my $dir ( ($BUNDLE_DIR, $LIB_DIR) ) {
154             my $base_re = quotemeta $dir;
155              
156             find( sub { my $file = $File::Find::name;
157             return unless -e $file && -f _ && -s _;
158              
159             return if $file =~ /\._/; # osx temp files
160              
161             $file =~ s/^$base_re(\W)?//;
162              
163             return if $INC{$file};
164              
165             my $unixfile = File::Spec::Unix->catfile(
166             File::Spec->splitdir( $file )
167             );
168             my $pm = join '::', File::Spec->splitdir( $file );
169             $pm =~ s/\.pm$//i or return; # not a .pm file
170              
171             #return if $pm =~ /(?:IPC::Run::)|(?:File::Spec::)/;
172              
173             eval "require $pm ; 1";
174              
175             if( $@ ) {
176             push @failures, $unixfile;
177             }
178             }, $dir );
179             }
180              
181             delete $INC{$_} for @failures;
182              
183             @INC = @RUN_TIME_INC;
184             }
185              
186              
187             my $ConfObj = CPANPLUS::Configure->new;
188             my $Config = CONFIG_BOXED;
189             my $Util = 'CPANPLUS::Internals::Utils';
190             my $ConfigFile = $ConfObj->_config_pm_to_file( $Config => $PRIV_LIB );
191              
192             { ### no base dir even, set it up
193             unless( IS_DIR->( $BASE ) ) {
194             $Util->_mkdir( dir => $BASE ) or die CPANPLUS::Error->stack_as_string;
195             }
196              
197             unless( -e $ConfigFile ) {
198             $ConfObj->set_conf( base => $BASE ); # new base dir
199             $ConfObj->set_conf( verbose => 1 ); # be verbose
200             $ConfObj->set_conf( prereqs => 1 ); # install prereqs
201             $ConfObj->set_conf( prefer_makefile => 1 ); # prefer Makefile.PL because of v5.10.0
202             $ConfObj->set_conf( enable_custom_sources => 0 ); # install prereqs
203             $ConfObj->set_conf( hosts => + . $self->_mirrors . q+ );
204             $ConfObj->set_program( sudo => undef );
205             $ConfObj->save( $Config => $PRIV_LIB ); # save the pm in that dir
206             }
207             }
208              
209             {
210             $Module::Load::Conditional::CHECK_INC_HASH = 1;
211             use CPANPLUS::Backend;
212             my $cb = CPANPLUS::Backend->new( $ConfObj );
213             my $su = $cb->selfupdate_object;
214              
215             $cb->parse_module( module => 'http://backpan.perl.org/authors/id/J/JP/JPEACOCK/version-0.82.tar.gz' )->install();
216              
217             $cb->module_tree( 'Module::Build' )->install(); # Move this here because perl-5.10.0 is icky
218              
219             $su->selfupdate( update => 'dependencies', latest => 1 );
220             $cb->module_tree( $_ )->install() for
221             qw(
222             CPANPLUS
223             File::Temp
224             Compress::Raw::Bzip2
225             Compress::Raw::Zlib
226             Compress::Zlib
227             ExtUtils::CBuilder
228             ExtUtils::ParseXS
229             ExtUtils::Manifest
230             ExtUtils::MakeMaker
231             Log::Message::Simple
232             CPANPLUS::YACSmoke
233             );
234             $_->install() for map { $su->modules_for_feature( $_ ) } qw(prefer_makefile md5 storable cpantest);
235             }
236             +;
237             }
238              
239             my $self = shift;
240             my $cpconf = q+
241             use strict;
242             use warnings;
243             use Getopt::Long;
244 0     0     use CPANPLUS::Configure;
245 0            
246             my $mx;
247             my $email;
248              
249             GetOptions( 'mx=s', \$mx, 'email=s', \$email );
250              
251             my $conf = CPANPLUS::Configure->new();
252             $conf->set_conf( verbose => 1 );
253             $conf->set_conf( cpantest => 'dont_cc' );
254             $conf->set_conf( cpantest_mx => $mx ) if $mx;
255             $conf->set_conf( email => $email );
256             $conf->set_conf( makeflags => 'UNINST=1' );
257             $conf->set_conf( buildflags => 'uninst=1' );
258             $conf->set_conf( enable_custom_sources => 0 );
259             $conf->set_conf( show_startup_tip => 0 );
260             $conf->set_conf( write_install_logs => 0 );
261             $conf->set_conf( hosts => +;
262             $cpconf .= $self->_mirrors() . ');';
263             $cpconf .= q+
264             $conf->set_program( sudo => undef );
265             $conf->save();
266             exit 0;
267 0           +;
268 0           return $cpconf;
269             }
270              
271             return q+
272             [CONFIG]
273 0           exclude_dists=<<HERE
274             mod_perl
275             ^OpenResty
276             ^Prima-
277 0     0     ^Router-Generic-
278             ^Net-TDMA-
279             ^PLUTO-
280             HERE
281             +;
282             }
283              
284             my $self = shift;
285             my $mirrors = q{[ };
286             foreach my $uri ( $self->mirrors ) {
287             my $scheme = $uri->scheme;
288             my $host = $uri->host;
289             my $path = $uri->path || '/';
290             $mirrors .= qq!{ scheme => '$scheme', host => '$host', path => '$path' }, !;
291 0     0     }
292 0           $mirrors .= q{ ] };
293 0           return $mirrors;
294 0           }
295 0            
296 0   0       no Moose;
297 0            
298             __PACKAGE__->meta->make_immutable;
299 0            
300 0           qq[Smokin'];
301              
302              
303 1     1   7 =pod
  1         2  
  1         6  
304              
305             =encoding UTF-8
306              
307             =head1 NAME
308              
309             App::SmokeBrew::Plugin::CPANPLUS::YACSmoke - A smokebrew plugin for CPANPLUS::YACSmoke based smokers
310              
311             =head1 VERSION
312              
313             version 1.02
314              
315             =head1 SYNOPSIS
316              
317             smokebrew --plugin App::SmokeBrew::Plugin::CPANPLUS::YACSmoke
318              
319             =head1 DESCRIPTION
320              
321             App::SmokeBrew::Plugin::CPANPLUS::YACSmoke is a L<App::SmokeBrew::Plugin> for L<smokebrew> which
322             configures the built perl installations for CPAN Testing with L<CPANPLUS::YACSmoke>.
323              
324             It will set up the L<CPANPLUS> / L<CPANPLUS::YACSmoke> base locations to be in the C<conf> directory
325             under the given C<prefix> directory with a directory for each perl version.
326              
327             =head1 METHODS
328              
329             =over
330              
331             =item C<configure>
332              
333             Called by L<smokebrew> to perform the CPAN Testing configuration.
334              
335             =back
336              
337             =head1 SEE ALSO
338              
339             L<App::SmokeBrew::Plugin>
340              
341             L<smokebrew>
342              
343             L<CPANPLUS>
344              
345             L<CPANPLUS::YACSmoke>
346              
347             =head1 AUTHOR
348              
349             Chris Williams <chris@bingosnet.co.uk>
350              
351             =head1 COPYRIGHT AND LICENSE
352              
353             This software is copyright (c) 2022 by Chris Williams.
354              
355             This is free software; you can redistribute it and/or modify it under
356             the same terms as the Perl 5 programming language system itself.
357              
358             =cut