| 1 | # ABSTRACT: Install packages from the repository | ||||||||||||
| 2 | |||||||||||||
| 3 | package Pinto::Remote::Action::Install; | ||||||||||||
| 4 | |||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use MooseX::Types::Moose qw(Undef Bool HashRef ArrayRef Maybe Str); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | ▶ | use File::Temp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 1 | ▶ | use File::Which qw(which); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 1 | ▶ | use Pinto::Result; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 1 | ▶ | use Pinto::Util qw(throw); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | |||||||||||||
| 15 | #------------------------------------------------------------------------------ | ||||||||||||
| 16 | |||||||||||||
| 17 | 1 | our $VERSION = '0.14'; # VERSION | |||||||||||
| 18 | |||||||||||||
| 19 | #------------------------------------------------------------------------------ | ||||||||||||
| 20 | |||||||||||||
| 21 | 1 | extends qw( Pinto::Remote::Action ); | |||||||||||
| 22 | |||||||||||||
| 23 | #------------------------------------------------------------------------------ | ||||||||||||
| 24 | |||||||||||||
| 25 | has targets => ( | ||||||||||||
| 26 | isa => ArrayRef [Str], | ||||||||||||
| 27 | traits => ['Array'], | ||||||||||||
| 28 | handles => { targets => 'elements' }, | ||||||||||||
| 29 | 0 | ▶ | default => sub { $_[0]->args->{targets} || [] }, | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||
| 30 | 1 | lazy => 1, | |||||||||||
| 31 | ); | ||||||||||||
| 32 | |||||||||||||
| 33 | 1 | has do_pull => ( | |||||||||||
| 34 | is => 'ro', | ||||||||||||
| 35 | isa => Bool, | ||||||||||||
| 36 | default => 0, | ||||||||||||
| 37 | ); | ||||||||||||
| 38 | |||||||||||||
| 39 | 1 | has mirror_uri => ( | |||||||||||
| 40 | is => 'ro', | ||||||||||||
| 41 | isa => Str, | ||||||||||||
| 42 | builder => '_build_mirror_uri', | ||||||||||||
| 43 | lazy => 1, | ||||||||||||
| 44 | ); | ||||||||||||
| 45 | |||||||||||||
| 46 | #------------------------------------------------------------------------------ | ||||||||||||
| 47 | |||||||||||||
| 48 | 0 | ▶ | sub _build_mirror_uri { | ||||||||||
|
Subroutine
_build_mirror_uri: not called CC=3 SCAR=24.8
| |||||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||||
| 50 | |||||||||||||
| 51 | 0 | my $stack = $self->args->{stack}; | |||||||||||
| 52 | 0 | ▶ | my $stack_dir = defined $stack ? "/stacks/$stack" : ''; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 0 | my $mirror_uri = $self->root . $stack_dir; | |||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | if ( defined $self->password ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 56 | |||||||||||||
| 57 | # Squirt username and password into URI | ||||||||||||
| 58 | 0 | my $credentials = $self->username . ':' . $self->password; | |||||||||||
| 59 | 0 | $mirror_uri =~ s{^ (https?://) }{$1$credentials\@}mx; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 0 | return $mirror_uri; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | #------------------------------------------------------------------------------ | ||||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | around BUILDARGS => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 68 | 0 | my $orig = shift; | |||||||||||
| 69 | 0 | my $class = shift; | |||||||||||
| 70 | |||||||||||||
| 71 | 0 | my $args = $class->$orig(@_); | |||||||||||
| 72 | |||||||||||||
| 73 | # Intercept attributes from the action "args" hash | ||||||||||||
| 74 | 0 | ▶ | $args->{do_pull} = delete $args->{args}->{do_pull} || 0; | ||||||||||
|
Condition0%0/2
delete $args->{'args'}{'do_pull'} || 0
MC/DC0%0/1
delete $args->{'args'}{'do_pull'} || 0
delete $args->{'args'}{'do_pull'}
Truth table0%0/2
A
A= delete $args->{'args'}{'do_pull'}
| |||||||||||||
| 75 | 0 | ▶ | $args->{cpanm_options} = delete $args->{args}->{cpanm_options} || {}; | ||||||||||
|
Condition0%0/2
delete $args->{'args'}{'cpanm_options'} || {}
MC/DC0%0/1
delete $args->{'args'}{'cpanm_options'} || {}
delete $args->{'args'}{'cpanm_options'}
Truth table0%0/2
A
A= delete $args->{'args'}{'cpanm_options'}
| |||||||||||||
| 76 | |||||||||||||
| 77 | 0 | return $args; | |||||||||||
| 78 | 1 | }; | |||||||||||
| 79 | |||||||||||||
| 80 | #------------------------------------------------------------------------------ | ||||||||||||
| 81 | |||||||||||||
| 82 | 0 | ▶ | override execute => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||
| 83 | 0 | my ($self) = @_; | |||||||||||
| 84 | |||||||||||||
| 85 | 0 | my $result; | |||||||||||
| 86 | 0 | ▶ | if ( $self->do_pull ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | |||||||||||||
| 88 | 0 | my $request = $self->_make_request( name => 'pull' ); | |||||||||||
| 89 | 0 | $result = $self->_send_request( req => $request ); | |||||||||||
| 90 | |||||||||||||
| 91 | 0 | ▶ | throw 'Failed to pull packages' if not $result->was_successful; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 92 | } | ||||||||||||
| 93 | |||||||||||||
| 94 | # Pinto::Role::Installer will handle installation after execute() | ||||||||||||
| 95 | 0 | ▶ | return defined $result ? $result : Pinto::Result->new; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | 1 | }; | |||||||||||
| 97 | |||||||||||||
| 98 | #------------------------------------------------------------------------------ | ||||||||||||
| 99 | |||||||||||||
| 100 | 1 | with qw( Pinto::Role::Installer ); | |||||||||||
| 101 | |||||||||||||
| 102 | #------------------------------------------------------------------------------ | ||||||||||||
| 103 | |||||||||||||
| 104 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 105 | |||||||||||||
| 106 | #----------------------------------------------------------------------------- | ||||||||||||
| 107 | 1 | 1; | |||||||||||
| 108 | |||||||||||||
| 109 | __END__ | ||||||||||||