blib/lib/Pinto/Role/Installer.pm

filter: Statementstmt 50.9% 28 / 55 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod n/a totaltotal 40.7% 35 / 86 CC 11 SCAR 32.4
CC
11
Cov
38%
_build_cpanm_exe
42.0
__ANON__
42.0
__ANON__
2.0
CRAP 25.6
« blib/lib/Pinto/Action/Revert.pm ↑ Summary blib/lib/Pinto/Locator/Stratopan.pm »
1 # ABSTRACT: Something that installs packages
2  
3 package Pinto::Role::Installer;
4  
5 3 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use MooseX::Types::Moose qw(Str HashRef Maybe);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Path::Class qw(dir);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Which qw(which);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Pinto::Util qw(throw mask_uri_passwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Pinto::Constants qw($PINTO_MINIMUM_CPANM_VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 #-----------------------------------------------------------------------------
16  
17 3 our $VERSION = '0.14'; # VERSION
18  
19 #-----------------------------------------------------------------------------
20  
21 has cpanm_options => (
22 is => 'ro',
23 isa => HashRef [ Maybe [Str] ],
24 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 3 lazy => 1,
26 );
27  
28 3 has cpanm_exe => (
29 is => 'ro',
30 isa => Str,
31 builder => '_build_cpanm_exe',
32 lazy => 1,
33 );
34  
35 #-----------------------------------------------------------------------------
36  
37 3 requires qw( execute targets mirror_uri );
38  
39 #-----------------------------------------------------------------------------
40  
41 3 with qw( Pinto::Role::Plated );
42  
43 #-----------------------------------------------------------------------------
44  
45 0 ▶sub _build_cpanm_exe {
Subroutine _build_cpanm_exe: not called CC=6 SCAR=37.4
46 0 my ($self) = @_;
47  
48 return dir( $ENV{PINTO_HOME} )->subdir('sbin')->file('cpanm')->stringify
49 0 ▶ if $ENV{PINTO_HOME};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PINTO_HOME"} 0 0 0
50  
51 0 ▶ my $cpanm_exe = which('cpanm')
Branch: 1 branch
BranchTrueFalseTotal
my $cpanm_exe = which("cpanm") or throw("Could not find cpanm in PATH") 0 0 0
52 or throw 'Could not find cpanm in PATH';
53  
54 0 my $cpanm_version_cmd = "$cpanm_exe --version";
55 0 my $cpanm_version_cmd_output = qx{$cpanm_version_cmd}; ## no critic qw(Backtick)
56 0 ▶ throw "Could not learn version of cpanm: $!" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 0 0
57  
58 0 ▶ my ($cpanm_version) = $cpanm_version_cmd_output =~ m{version ([\d.]+)}
Branch: 1 branch
BranchTrueFalseTotal
my($cpanm_version) = $cpanm_version_cmd_output =~ /version ([\d.]+)/ or throw("Could not parse cpanm version number from $cpanm_version_cmd_output") 0 0 0
59 or throw "Could not parse cpanm version number from $cpanm_version_cmd_output";
60  
61 0 ▶ if ( $cpanm_version < $PINTO_MINIMUM_CPANM_VERSION ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cpanm_version < $Pinto::Role::Installer::PINTO_MINIMUM_CPANM_VERSION) 0 0 0
62 0 throw "Your cpanm ($cpanm_version) is too old. Must have $PINTO_MINIMUM_CPANM_VERSION or newer";
63 }
64  
65 0 return $cpanm_exe;
66 }
67  
68 #-----------------------------------------------------------------------------
69  
70 0 ▶after execute => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
71 0 my ($self) = @_;
72  
73 # Wire cpanm to our repo
74 0 my $opts = $self->cpanm_options;
75 0 $opts->{mirror} = $self->mirror_uri;
76 0 $opts->{'mirror-only'} = '';
77  
78 # Process other cpanm options
79 0 my @cpanm_opts;
80 0 for my $opt ( keys %{$opts} ) {
81 0 ▶ my $dashes = ( length $opt == 1 ) ? '-' : '--';
Branch: 1 branch
BranchTrueFalseTotal
length $opt == 1 ? : 0 0 0
82 0 my $dashed_opt = $dashes . $opt;
83 0 my $opt_value = $opts->{$opt};
84 0 push @cpanm_opts, $dashed_opt;
85 0 ▶ push @cpanm_opts, $opt_value if defined $opt_value && length $opt_value;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opt_value and length $opt_value 0 0 0
Condition0%0/3
defined $opt_value and length $opt_value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opt_value and length $opt_value
defined $opt_value length $opt_value
Truth table0%0/3
A and B
A= defined $opt_valueB= length $opt_value
ABresult
0X0
100
111
86 }
87  
88 # Scrub passwords from the command so they don't appear in the logs
89 0 my @sanitized_cpanm_opts = map { mask_uri_passwords($_) } @cpanm_opts;
90 0 $self->info( join ' ', 'Running:', $self->cpanm_exe, @sanitized_cpanm_opts );
91  
92 # Run cpanm
93 0 ▶ 0 == system( $self->cpanm_exe, @cpanm_opts, $self->targets )
Branch: 1 branch
BranchTrueFalseTotal
0 == system($self->cpanm_exe, @cpanm_opts, $self->targets) or throw("Installation failed. See the cpanm build log for details") 0 0 0
94 or throw "Installation failed. See the cpanm build log for details";
95 3 };
96  
97 #-----------------------------------------------------------------------------
98 3 1;
99  
100 __END__
« blib/lib/Pinto/Action/Revert.pm ↑ Summary blib/lib/Pinto/Locator/Stratopan.pm »