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