blib/lib/Pinto/Remote/SelfContained/Action/Install.pm

filter: Statementstmt 97.0% 65 / 67 Branchbran 65.0% 13 / 20 Conditioncond 57.1% 8 / 14 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 92.8% 13 / 14 Podpod n/a totaltotal 82.1% 101 / 123 CC 18 SCAR 16.1
CC
18
Cov
85%
_build_cpanm_exe
10.1
__ANON__
7.4
_build_mirror_uri
3.0
CRAP 5.0
« blib/lib/Pinto/Remote/SelfContained/Chrome.pm ↑ Summary blib/lib/Pinto/Remote/SelfContained.pm »
1 package
2 Pinto::Remote::SelfContained::Action::Install; # hide from PAUSE
3 # ABSTRACT: Install packages from the repository
4  
5 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MooX::HandlesVia;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Pinto::Remote::SelfContained::Util qw(mask_uri_passwords);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Types::Standard qw(ArrayRef Bool HashRef Maybe Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use constant PINTO_MINIMUM_CPANM_VERSION => '1.6920';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = '1.999'; # TRIAL VERSION
18  
19 1 extends qw(Pinto::Remote::SelfContained::Action);
20  
21 has cpanm_options => (
22 is => 'lazy',
23 isa => HashRef[ Maybe[Str] ],
24 0 ▶ default => sub { +{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 1 );
26  
27 has cpanm_exe => (
28 is => 'lazy',
29 isa => Str,
30 1 ▶ builder => sub {
Subroutine _build_cpanm_exe: called CC=7 SCAR=23.2
31 return "$ENV{PINTO_HOME}/sbin/cpanm"
32 if defined $ENV{PINTO_HOME}
33 1 ▶ && -x "$ENV{PINTO_HOME}/sbin/cpanm";
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"PINTO_HOME"} and -x qq[$ENV{"PINTO_HOME"}/sbin/cpanm] 0 1 1
Condition33%1/3
defined $ENV{"PINTO_HOME"} and -x qq[$ENV{"PINTO_HOME"}/sbin/cpanm]
!ll&&!rl&&r
100
MC/DC0%0/2
defined $ENV{"PINTO_HOME"} and -x qq[$ENV{"PINTO_HOME"}/sbin/cpanm]
defined $ENV{"PINTO_HOME"} -x qq[$ENV{"PINTO_HOME"}/sbin/cpanm]
Truth table33%1/3
A and B
A= defined $ENV{"PINTO_HOME"}B= -x qq[$ENV{"PINTO_HOME"}/sbin/cpanm]
ABresult
0X0
100
111
34  
35 1 ▶ my $output = `cpanm --version`
Condition50%1/2
`cpanm --version` // croak("Could not learn version of cpanm")
l!l
10
MC/DC0%0/1
`cpanm --version` // croak("Could not learn version of cpanm")
`cpanm --version`
Truth table50%1/2
A
A= `cpanm --version`
Aresult
11
00
36 // croak("Could not learn version of cpanm");
37  
38 1 ▶ croak("Could not learn version of cpanm")
Branch: 1 branch
BranchTrueFalseTotal
if $output eq "" 0 1 1
39 if $output eq '';
40  
41 1 ▶ my ($cpanm_version) = $output =~ m{version ([0-9.]+)}
Branch: 1 branch
BranchTrueFalseTotal
my($cpanm_version) = $output =~ /version ([0-9.]+)/ or croak("Could not parse cpanm version number from $output") 1 0 1
42 or croak("Could not parse cpanm version number from $output");
43  
44 0 ▶ croak("Your cpanm ($cpanm_version) is too old. Must have @{[PINTO_MINIMUM_CPANM_VERSION]} or newer")
Branch: 1 branch
BranchTrueFalseTotal
if $cpanm_version < "1.6920" 0 1 1
45 if $cpanm_version < PINTO_MINIMUM_CPANM_VERSION;
46  
47 1 return 'cpanm';
48 },
49 1 );
50  
51 has targets => (
52 is => 'bare',
53 lazy => 1,
54 isa => ArrayRef[Str],
55 handles_via => 'Array',
56 handles => { targets => 'elements' },
57 4 ▶ builder => sub { shift->args->{targets} // [] },
Subroutine _build_targets: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->args->{"targets"} // []
l!l
04
MC/DC0%0/1
+(shift())->args->{"targets"} // []
+(shift())->args->{"targets"}
Truth table50%1/2
A
A= +(shift())->args->{"targets"}
Aresult
11
00
58 1 );
59  
60 1 has do_pull => (is => 'ro', isa => Bool, default => 0);
61  
62 has mirror_uri => (
63 is => 'lazy',
64 isa => Str,
65 6 ▶ builder => sub {
Subroutine _build_mirror_uri: called CC=3 SCAR=11.0
66 6 my ($self) = @_;
67  
68 6 my $stack = $self->args->{stack};
69 6 ▶ my $mirror_uri = join '',
Branch: 1 branch
BranchTrueFalseTotal
defined $stack ? : 1 5 6
70 $self->root, defined $stack ? "/stacks/$stack" : '';
71  
72 6 ▶ if (defined $self->password) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->password) 2 4 6
73 2 my $credentials = $self->username . ':' . $self->password;
74 2 $mirror_uri =~ s{^ https?:// \K}{$credentials\@}mx;
75 }
76  
77 6 return $mirror_uri;
78 },
79 1 );
80  
81 7 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
82 7 my ($orig, $class, @rest) = @_;
83 7 my $attrs = $class->$orig(@rest);
84  
85 # Intercept attributes from the action "args" hash
86 7 ▶ $attrs->{do_pull} = delete $attrs->{args}{do_pull} // 0;
Condition100%2/2
delete $attrs->{"args"}{"do_pull"} // 0
l!l
25
MC/DC100%1/1
delete $attrs->{"args"}{"do_pull"} // 0
delete $attrs->{"args"}{"do_pull"}
Truth table100%2/2
A
A= delete $attrs->{"args"}{"do_pull"}
Aresult
11
00
87 7 ▶ $attrs->{cpanm_options} = delete $attrs->{args}{cpanm_options} // {};
Condition100%2/2
delete $attrs->{"args"}{"cpanm_options"} // {}
l!l
16
MC/DC100%1/1
delete $attrs->{"args"}{"cpanm_options"} // {}
delete $attrs->{"args"}{"cpanm_options"}
Truth table100%2/2
A
A= delete $attrs->{"args"}{"cpanm_options"}
Aresult
11
00
88  
89 7 return $attrs;
90 1 };
91  
92 4 ▶around execute => sub {
Subroutine __ANON__: called CC=7 SCAR=20.1
93 4 my (undef, $self, $streaming_callback) = @_;
94  
95 4 ▶ if ($self->do_pull) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->do_pull) 2 2 4
96 2 my $request = $self->_make_request('pull');
97 2 my $response = $self->_send_request($request, $streaming_callback);
98 2 ▶ croak('Failed to pull packages') if !$response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $response->{"success"} 0 2 2
99 }
100  
101 # Wire cpanm to our repo
102 4 my @opts = ('--mirror', $self->mirror_uri, '--mirror-only');
103  
104 # Process other cpanm options
105 4 my $cpanm_options = $self->cpanm_options;
106 4 for my $opt (sort keys %$cpanm_options) {
107 1 ▶ my $dash = length $opt == 1 ? '-' : '--';
Branch: 1 branch
BranchTrueFalseTotal
length $opt == 1 ? : 0 1 1
108 1 ▶ push @opts, "$dash$opt", grep defined && length, $cpanm_options->{$opt}
Condition33%1/3
defined $_ && length $_
!ll&&!rl&&r
010
MC/DC0%0/2
defined $_ && length $_
defined $_ length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
ABresult
0X0
100
111
109 }
110  
111 # Scrub passwords from the command so they don't appear in the logs
112 4 my @sanitized = map mask_uri_passwords($_), @opts;
113 4 $self->chrome->info( join ' ', 'Running:', $self->cpanm_exe, @sanitized, $self->targets );
114  
115 # Run cpanm
116 4 ▶ system($self->cpanm_exe, @opts, $self->targets) == 0
Branch: 1 branch
BranchTrueFalseTotal
system($self->cpanm_exe, @opts, $self->targets) == 0 or croak("Installation failed. See the cpanm build log for details") 4 0 4
117 or croak("Installation failed. See the cpanm build log for details");
118 1 };
119  
120 1 1;
121  
122 __END__
« blib/lib/Pinto/Remote/SelfContained/Chrome.pm ↑ Summary blib/lib/Pinto/Remote/SelfContained.pm »