App/SmokeBrew.pm

filter: Statementstmt 59.8% 94 / 157 Branchbran 5.2% 2 / 38 Conditioncond 29.4% 5 / 17 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 81.4% 22 / 27 Podpod 100% 2 / 2 totaltotal 50.7% 128 / 252 CC 28 SCAR 42.0
CC
28
Cov
48%
run
210.0
_build__perls
72.0
_perl_exe
12.0
CRAP 66.7
« App/SmokeBrew/Plugin/CPANPLUS/YACSmoke.pm ↑ Summary App/SmokeBrew/BuildPerl.pm »
1 package App::SmokeBrew;
2 2 $App::SmokeBrew::VERSION = '1.06';
3 #ABSTRACT: The guts of smokebrew
4  
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Pod::Usage;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Log::Message::Simple qw[msg error];
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Module::Load::Conditional qw[can_load];
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use App::SmokeBrew::IniFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use App::SmokeBrew::Tools;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use App::SmokeBrew::BuildPerl;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Module::Pluggable search_path => 'App::SmokeBrew::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Getopt::Long;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 my @mirrors = (
19 'http://www.cpan.org/',
20 'http://cpan.cpantesters.org/',
21 );
22  
23 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 with 'MooseX::Getopt', 'MooseX::ConfigFromFile';
26  
27 2 ▶use App::SmokeBrew::Types qw[ArrayRefUri ArrayRefStr];
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶sub get_config_from_file {
Subroutine get_config_from_file: called CC=2 SCAR=6.9
Pod documented
30 1 my ($class,$file) = @_;
31 1 my $options_hashref = App::SmokeBrew::IniFile->read_file($file);
32 1 my $opts = delete $options_hashref->{_};
33 $opts->{_plugins}->{$_} = delete $options_hashref->{$_}
34 1 for keys %{ $options_hashref };
35 1 return $opts;
36 }
37  
38 has 'configfile' => (
39 is => 'ro',
40 0 ▶ default => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
41 0 my $file = File::Spec->catfile(
42 App::SmokeBrew::Tools->smokebrew_dir(),
43 '.smokebrew', 'smokebrew.cfg' );
44 0 ▶ return unless -e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
45 0 return $file;
46 },
47 2 );
48  
49 2 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 ▶use MooseX::Types::Path::Class qw[Dir File];
Subroutine BEGIN: called CC=1 SCAR=0.0
51 2 ▶use MooseX::Types::Email qw[EmailAddress];
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 # Mandatory
54  
55 2 has 'builddir' => (
56 is => 'ro',
57 isa => Dir,
58 required => 1,
59 coerce => 1,
60 );
61  
62 2 has 'prefix' => (
63 is => 'ro',
64 isa => Dir,
65 required => 1,
66 coerce => 1,
67 );
68  
69 2 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 2 ▶ where {
Subroutine __ANON__: called CC=2 SCAR=6.9
80 2 my $plugin = $_;
81 2 ▶ return grep { $plugin eq $_ or /\Q$plugin\E$/ } __PACKAGE__->plugins;
Condition100%3/3
$plugin eq $_ || /\Q$plugin\E$/
l!l&&r!l&&!r
112
MC/DC100%2/2
$plugin eq $_ || /\Q$plugin\E$/
$plugin eq $_ /\Q$plugin\E$/
Truth table100%3/3
A || B
A= $plugin eq $_B= /\Q$plugin\E$/
ABresult
1X1
011
000
82 },
83 0 ▶ message { "($_) is not a valid plugin" }
Subroutine __ANON__: not called CC=1 SCAR=6.9
84 ),
85 required => 1,
86 writer => '_set_plugin',
87 2 ▶ trigger => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
88 2 my ($self,$plugin,$old) = @_;
89 2 ▶ return if $old;
Branch: 1 branch
BranchTrueFalseTotal
if $old 1 1 2
90 1 ▶ $self->_set_plugin( grep { $plugin eq $_ or /\Q$plugin\E$/ } __PACKAGE__->plugins );
Condition66%2/3
$plugin eq $_ || /\Q$plugin\E$/
l!l&&r!l&&!r
011
MC/DC50%1/2
$plugin eq $_ || /\Q$plugin\E$/
$plugin eq $_ /\Q$plugin\E$/
Truth table66%2/3
A || B
A= $plugin eq $_B= /\Q$plugin\E$/
ABresult
1X1
011
000
91 },
92 2 );
93  
94 # Multiple
95  
96 has 'mirrors' => (
97 is => 'ro',
98 isa => 'ArrayRefUri',
99 1 ▶ default => sub { \@mirrors },
Subroutine __ANON__: called CC=1 SCAR=0.0
100 2 coerce => 1,
101 );
102  
103 2 has 'perlargs' => (
104 is => 'ro',
105 isa => 'ArrayRefStr',
106 coerce => 1,
107 );
108  
109 # Optional
110  
111 2 has 'mx' => (
112 is => 'ro',
113 isa => 'Str',
114 );
115  
116 2 has 'noclean' => (
117 is => 'ro',
118 isa => 'Bool',
119 default => 0,
120 );
121  
122 2 has 'nozapman' => (
123 is => 'ro',
124 isa => 'Bool',
125 default => 0,
126 );
127  
128 2 has 'verbose' => (
129 is => 'ro',
130 isa => 'Bool',
131 default => 0,
132 );
133  
134 2 has 'skiptest' => (
135 is => 'ro',
136 isa => 'Bool',
137 default => 0,
138 );
139  
140 2 has 'forcecfg' => (
141 is => 'ro',
142 isa => 'Bool',
143 default => 0,
144 );
145  
146 2 has 'force' => (
147 is => 'ro',
148 isa => 'Bool',
149 default => 0,
150 );
151  
152 2 has 'make' => (
153 is => 'ro',
154 isa => 'Str',
155 );
156  
157 2 has 'jobs' => (
158 is => 'ro',
159 isa => 'Int',
160 );
161  
162 # What perl versions to install
163  
164 2 has 'stable' => (
165 is => 'ro',
166 isa => 'Bool',
167 );
168  
169 2 has 'devel' => (
170 is => 'ro',
171 isa => 'Bool',
172 );
173  
174 2 has 'recent' => (
175 is => 'ro',
176 isa => 'Bool',
177 );
178  
179 2 has 'modern' => (
180 is => 'ro',
181 isa => 'Bool',
182 );
183  
184 2 has 'latest' => (
185 is => 'ro',
186 isa => 'Bool',
187 );
188  
189 2 has 'install' => (
190 is => 'ro',
191 isa => 'Str',
192 );
193  
194 # Internal
195  
196 2 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 1 ▶ default => sub { { } },
Subroutine __ANON__: called CC=1 SCAR=0.0
208 2 );
209  
210 0 ▶sub _build__perls {
Subroutine _build__perls: not called CC=8 SCAR=42.8
211 0 my $self = shift;
212 0 my $arg;
213 0 ▶ $arg = 'rel' if $self->stable;
Branch: 1 branch
BranchTrueFalseTotal
if $self->stable 0 0 0
214 0 ▶ $arg = 'dev' if $self->devel;
Branch: 1 branch
BranchTrueFalseTotal
if $self->devel 0 0 0
215 0 ▶ $arg = 'recent' if $self->recent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->recent 0 0 0
216 0 ▶ $arg = 'modern' if $self->modern;
Branch: 1 branch
BranchTrueFalseTotal
if $self->modern 0 0 0
217 0 ▶ $arg = 'latest' if $self->latest;
Branch: 1 branch
BranchTrueFalseTotal
if $self->latest 0 0 0
218 0 ▶ $arg = $self->install if $self->install;
Branch: 1 branch
BranchTrueFalseTotal
if $self->install 0 0 0
219 0 ▶ return [ grep { $_ ne '5.6.0' and $_ ne '5.8.0' } App::SmokeBrew::Tools->perls( $arg ) ];
Condition0%0/3
$_ ne '5.6.0' && $_ ne '5.8.0'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne '5.6.0' && $_ ne '5.8.0'
$_ ne '5.6.0' $_ ne '5.8.0'
Truth table0%0/3
A && B
A= $_ ne '5.6.0'B= $_ ne '5.8.0'
ABresult
0X0
100
111
220 }
221  
222 0 ▶sub run {
Subroutine run: not called CC=14 SCAR=53.5
Pod documented
223 0 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 ▶ unless ( -e $self->_perl_exe( $perl ) and !$self->force ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->_perl_exe($perl) and not $self->force) { } 0 0 0
Condition0%0/3
-e $self->_perl_exe($perl) and not $self->force
!ll&&!rl&&r
000
MC/DC0%0/2
-e $self->_perl_exe($perl) and not $self->force
-e $self->_perl_exe($perl) not $self->force
Truth table0%0/3
A and not(B)
A= -e $self->_perl_exe($perl)B= not $self->force
ABresult
0X0
100
111
228 my $build = App::SmokeBrew::BuildPerl->new(
229 version => $perl,
230 0 map { ( $_ => $self->$_ ) }
231 0 grep { defined $self->$_ }
232 qw(builddir prefix verbose noclean nozapman skiptest perlargs mirrors make jobs),
233 );
234 0 ▶ unless ( $build ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($build) 0 0 0
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 ▶ unless ( $location ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($location) 0 0 0
240 0 error( "Could not build perl ($perl)", $self->verbose );
241 0 next PERL;
242 }
243 $perl_exe =
244 0 ▶ File::Spec->catfile( $location, 'bin', ( App::SmokeBrew::Tools->devel_perl( $perl ) ? "perl$perl" : 'perl' ) );
Branch: 1 branch
BranchTrueFalseTotal
'App::SmokeBrew::Tools'->devel_perl($perl) ? : 0 0 0
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 ▶ next PERL unless $self->forcecfg;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->forcecfg 0 0 0
250 0 $perl_exe = $self->_perl_exe( $perl );
251 }
252 0 msg( "Configuring (" . $self->plugin .")", $self->verbose );
253 0 ▶ unless ( can_load( modules => { $self->plugin, '0.0' } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (can_load("modules", {$self->plugin, "0.0"})) 0 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;
260 0 my $plugin = $self->plugin;
261 0 ▶ ($plugopts) = grep { $plugin eq $_ or $plugin =~ /\Q$_\E$/ } keys %{ $self->_plugins };
Condition0%0/3
$plugin eq $_ || $plugin =~ /\Q$_\E$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$plugin eq $_ || $plugin =~ /\Q$_\E$/
$plugin eq $_ $plugin =~ /\Q$_\E$/
Truth table0%0/3
A || B
A= $plugin eq $_B= $plugin =~ /\Q$_\E$/
ABresult
1X1
011
000
262 0 @plugopts = map { ( $_ => $self->_plugins->{ $plugopts }->{$_} ) }
263 0 grep { defined $self->_plugins->{ $plugopts }->{$_} }
264 0 ▶ keys %{ $self->_plugins->{ $plugopts } } if $plugopts;
Branch: 1 branch
BranchTrueFalseTotal
if $plugopts 0 0 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->$_ }
271 qw(builddir prefix verbose noclean mirrors email mx)
272 ),
273 @plugopts,
274 );
275 0 ▶ unless ( $plugin ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin) 0 0 0
276 0 error( "Could not make plugin (" . $self->plugin . ")", $self->verbose );
277 0 next PERL;
278 }
279 0 ▶ unless ( $plugin->configure ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin->configure) 0 0 0
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 ▶ $self->builddir->rmtree() unless $self->noclean();
Branch: 1 branch
BranchTrueFalseTotal
unless $self->noclean 0 0 0
286 }
287  
288 0 ▶sub _perl_exe {
Subroutine _perl_exe: not called CC=3 SCAR=24.8
289 0 my $self = shift;
290 0 ▶ my $perl = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
291 return
292 0 ▶ File::Spec->catfile(
Branch: 1 branch
BranchTrueFalseTotal
'App::SmokeBrew::Tools'->devel_perl($perl) ? : 0 0 0
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 2 q[Smokebrew, look what's inside of you];
300  
301 __END__
« App/SmokeBrew/Plugin/CPANPLUS/YACSmoke.pm ↑ Summary App/SmokeBrew/BuildPerl.pm »