| 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
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | my $cpanm_exe = which('cpanm') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my ($cpanm_version) = $cpanm_version_cmd_output =~ m{version ([\d.]+)} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
defined $opt_value and length $opt_value
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 94 | or throw "Installation failed. See the cpanm build log for details"; | ||||||||||||||||||||||||||||
| 95 | 3 | }; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 98 | 3 | 1; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||