File Coverage

blib/lib/App/SmokeBrew.pm
Criterion Covered Total %
statement 57 116 49.1
branch 0 38 0.0
condition 0 5 0.0
subroutine 18 21 85.7
pod 2 2 100.0
total 77 182 42.3


line stmt bran cond sub pod time code
1             package App::SmokeBrew;
2             $App::SmokeBrew::VERSION = '1.00';
3             #ABSTRACT: The guts of smokebrew
4              
5 1     1   628 use strict;
  1         1  
  1         24  
6 1     1   4 use warnings;
  1         2  
  1         20  
7 1     1   452 use Pod::Usage;
  1         41338  
  1         132  
8 1     1   500 use Log::Message::Simple qw[msg error];
  1         16383  
  1         58  
9 1     1   478 use Module::Load::Conditional qw[can_load];
  1         9696  
  1         52  
10 1     1   441 use App::SmokeBrew::IniFile;
  1         3  
  1         33  
11 1     1   443 use App::SmokeBrew::Tools;
  1         4  
  1         35  
12 1     1   420 use App::SmokeBrew::BuildPerl;
  1         4  
  1         39  
13 1     1   6 use Module::Pluggable search_path => 'App::SmokeBrew::Plugin';
  1         2  
  1         8  
14 1     1   88 use File::Spec;
  1         2  
  1         18  
15 1     1   4 use Cwd;
  1         1  
  1         77  
16 1     1   6 use Getopt::Long;
  1         1  
  1         8  
17              
18             my @mirrors = (
19             'http://www.cpan.org/',
20             'http://cpan.cpantesters.org/',
21             'http://cpan.hexten.net/',
22             'ftp://ftp.funet.fi/pub/CPAN/',
23             );
24              
25 1     1   131 use Moose;
  1         2  
  1         5  
26              
27             with 'MooseX::Getopt', 'MooseX::ConfigFromFile';
28              
29 1     1   5437 use App::SmokeBrew::Types qw[ArrayRefUri ArrayRefStr];
  1         2  
  1         15  
30              
31             sub get_config_from_file {
32 1     1 1 3366 my ($class,$file) = @_;
33 1         45 my $options_hashref = App::SmokeBrew::IniFile->read_file($file);
34 1         103 my $opts = delete $options_hashref->{_};
35             $opts->{_plugins}->{$_} = delete $options_hashref->{$_}
36 1         2 for keys %{ $options_hashref };
  1         4  
37 1         11 return $opts;
38             }
39              
40             has 'configfile' => (
41             is => 'ro',
42             default => sub {
43             my $file = File::Spec->catfile(
44             App::SmokeBrew::Tools->smokebrew_dir(),
45             '.smokebrew', 'smokebrew.cfg' );
46             return unless -e $file;
47             return $file;
48             },
49             );
50              
51 1     1   1132 use Moose::Util::TypeConstraints;
  1         1  
  1         7  
52 1     1   1803 use MooseX::Types::Path::Class qw[Dir File];
  1         2  
  1         7  
53 1     1   1704 use MooseX::Types::Email qw[EmailAddress];
  1         143174  
  1         16  
54              
55             # Mandatory
56              
57             has 'builddir' => (
58             is => 'ro',
59             isa => Dir,
60             required => 1,
61             coerce => 1,
62             );
63              
64             has 'prefix' => (
65             is => 'ro',
66             isa => Dir,
67             required => 1,
68             coerce => 1,
69             );
70              
71             has 'email' => (
72             is => 'ro',
73             isa => EmailAddress,
74             required => 1,
75             );
76              
77             has 'plugin' => (
78             is => 'ro',
79             isa => subtype(
80             as 'Str',
81             where {
82             my $plugin = $_;
83             return grep { $plugin eq $_ or /\Q$plugin\E$/ } __PACKAGE__->plugins;
84             },
85             message { "($_) is not a valid plugin" }
86             ),
87             required => 1,
88             writer => '_set_plugin',
89             trigger => sub {
90             my ($self,$plugin,$old) = @_;
91             return if $old;
92             $self->_set_plugin( grep { $plugin eq $_ or /\Q$plugin\E$/ } __PACKAGE__->plugins );
93             },
94             );
95              
96             # Multiple
97              
98             has 'mirrors' => (
99             is => 'ro',
100             isa => 'ArrayRefUri',
101             default => sub { \@mirrors },
102             coerce => 1,
103             );
104              
105             has 'perlargs' => (
106             is => 'ro',
107             isa => 'ArrayRefStr',
108             coerce => 1,
109             );
110              
111             # Optional
112              
113             has 'mx' => (
114             is => 'ro',
115             isa => 'Str',
116             );
117              
118             has 'noclean' => (
119             is => 'ro',
120             isa => 'Bool',
121             default => 0,
122             );
123              
124             has 'nozapman' => (
125             is => 'ro',
126             isa => 'Bool',
127             default => 0,
128             );
129              
130             has 'verbose' => (
131             is => 'ro',
132             isa => 'Bool',
133             default => 0,
134             );
135              
136             has 'skiptest' => (
137             is => 'ro',
138             isa => 'Bool',
139             default => 0,
140             );
141              
142             has 'forcecfg' => (
143             is => 'ro',
144             isa => 'Bool',
145             default => 0,
146             );
147              
148             has 'force' => (
149             is => 'ro',
150             isa => 'Bool',
151             default => 0,
152             );
153              
154             has 'make' => (
155             is => 'ro',
156             isa => 'Str',
157             );
158              
159             has 'jobs' => (
160             is => 'ro',
161             isa => 'Int',
162             );
163              
164             # What perl versions to install
165              
166             has 'stable' => (
167             is => 'ro',
168             isa => 'Bool',
169             );
170              
171             has 'devel' => (
172             is => 'ro',
173             isa => 'Bool',
174             );
175              
176             has 'recent' => (
177             is => 'ro',
178             isa => 'Bool',
179             );
180              
181             has 'modern' => (
182             is => 'ro',
183             isa => 'Bool',
184             );
185              
186             has 'latest' => (
187             is => 'ro',
188             isa => 'Bool',
189             );
190              
191             has 'install' => (
192             is => 'ro',
193             isa => 'Str',
194             );
195              
196             # Internal
197              
198             has '_perls' => (
199             is => 'ro',
200             isa => 'ArrayRef[Str]',
201             init_arg => undef,
202             lazy_build => 1,
203             auto_deref => 1,
204             );
205              
206             has '_plugins' => (
207             is => 'ro',
208             isa => 'HashRef',
209             default => sub { { } },
210             );
211              
212             sub _build__perls {
213 0     0     my $self = shift;
214 0           my $arg;
215 0 0         $arg = 'rel' if $self->stable;
216 0 0         $arg = 'dev' if $self->devel;
217 0 0         $arg = 'recent' if $self->recent;
218 0 0         $arg = 'modern' if $self->modern;
219 0 0         $arg = 'latest' if $self->latest;
220 0 0         $arg = $self->install if $self->install;
221 0 0         return [ grep { $_ ne '5.6.0' and $_ ne '5.8.0' } App::SmokeBrew::Tools->perls( $arg ) ];
  0            
222             }
223              
224             sub run {
225 0     0 1   my $self = shift;
226 0           PERL: foreach my $perl ( $self->_perls ) {
227 0           msg( "Building perl ($perl)", $self->verbose );
228 0           my $perl_exe;
229 0 0 0       unless ( -e $self->_perl_exe( $perl ) and !$self->force ) {
230             my $build = App::SmokeBrew::BuildPerl->new(
231             version => $perl,
232 0           map { ( $_ => $self->$_ ) }
233 0           grep { defined $self->$_ }
  0            
234             qw(builddir prefix verbose noclean nozapman skiptest perlargs mirrors make jobs),
235             );
236 0 0         unless ( $build ) {
237 0           error( "Could not create a build object for ($perl)", $self->verbose );
238 0           next PERL;
239             }
240 0           my $location = $build->build_perl();
241 0 0         unless ( $location ) {
242 0           error( "Could not build perl ($perl)", $self->verbose );
243 0           next PERL;
244             }
245             $perl_exe =
246 0 0         File::Spec->catfile( $location, 'bin', ( App::SmokeBrew::Tools->devel_perl( $perl ) ? "perl$perl" : 'perl' ) );
247 0           msg( "Successfully built ($perl_exe)", $self->verbose );
248             }
249             else {
250 0           msg("The perl exe already exists skipping build", $self->verbose);
251 0 0         next PERL unless $self->forcecfg;
252 0           $perl_exe = $self->_perl_exe( $perl );
253             }
254 0           msg( "Configuring (" . $self->plugin .")", $self->verbose );
255 0 0         unless ( can_load( modules => { $self->plugin, '0.0' } ) ) {
256 0           error( "Could not load plugin (" . $self->plugin . ")", $self->verbose );
257 0           next PERL;
258             }
259 0           my @plugopts;
260             {
261 0           my $plugopts;
  0            
262 0           my $plugin = $self->plugin;
263 0 0         ($plugopts) = grep { $plugin eq $_ or $plugin =~ /\Q$_\E$/ } keys %{ $self->_plugins };
  0            
  0            
264 0           @plugopts = map { ( $_ => $self->_plugins->{ $plugopts }->{$_} ) }
265 0           grep { defined $self->_plugins->{ $plugopts }->{$_} }
266 0 0         keys %{ $self->_plugins->{ $plugopts } } if $plugopts;
  0            
267             }
268             my $plugin = $self->plugin->new(
269             version => $perl,
270             perl_exe => $perl_exe,
271 0           ( map { ( $_ => $self->$_ ) }
272 0           grep { defined $self->$_ }
  0            
273             qw(builddir prefix verbose noclean mirrors email mx)
274             ),
275             @plugopts,
276             );
277 0 0         unless ( $plugin ) {
278 0           error( "Could not make plugin (" . $self->plugin . ")", $self->verbose );
279 0           next PERL;
280             }
281 0 0         unless ( $plugin->configure ) {
282 0           error( "Could not configure plugin (" . $self->plugin . ")", $self->verbose );
283 0           next PERL;
284             }
285 0           msg( "Finished build and configuration for perl ($perl)", $self->verbose );
286             }
287 0 0         $self->builddir->rmtree() unless $self->noclean();
288             }
289              
290             sub _perl_exe {
291 0     0     my $self = shift;
292 0   0       my $perl = shift || return;
293             return
294 0 0         File::Spec->catfile(
295             $self->prefix->absolute,
296             App::SmokeBrew::Tools->perl_version($perl),
297             'bin',
298             ( App::SmokeBrew::Tools->devel_perl( $perl ) ? "perl$perl" : 'perl' ) )
299             }
300              
301             q[Smokebrew, look what's inside of you];
302              
303             __END__
304              
305             =pod
306              
307             =encoding UTF-8
308              
309             =head1 NAME
310              
311             App::SmokeBrew - The guts of smokebrew
312              
313             =head1 VERSION
314              
315             version 1.00
316              
317             =head1 SYNOPSIS
318              
319             use strict;
320             use warnings;
321             use App::SmokeBrew;
322              
323             App::SmokeBrew->new_with_options()->run();
324              
325             =head2 C<new_with_options>
326              
327             Create a new App::SmokeBrew object
328              
329             =head2 C<run>
330              
331             This method is called by L<smokebrew> to do all the work.
332              
333             =head2 C<get_config_from_file>
334              
335             This method is required by L<MooseX::ConfigFromFile> to load the C<configfile>.
336              
337             =head1 SEE ALSO
338              
339             L<smokebrew>
340              
341             =head1 AUTHOR
342              
343             Chris Williams <chris@bingosnet.co.uk>
344              
345             =head1 COPYRIGHT AND LICENSE
346              
347             This software is copyright (c) 2020 by Chris Williams.
348              
349             This is free software; you can redistribute it and/or modify it under
350             the same terms as the Perl 5 programming language system itself.
351              
352             =cut