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