| 1 | # ABSTRACT: Interact with a remote Pinto repository | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Remote; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use MooseX::Types::Moose qw(Maybe Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Try::Tiny; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Pinto::Chrome::Term; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use Pinto::Remote::Action; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use Pinto::Constants qw(:server); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 6 | ▶ | use Pinto::Util qw(throw current_username); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use Pinto::Types qw(Uri); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | our $VERSION = '0.14'; # VERSION | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | with qw(Pinto::Role::Plated Pinto::Role::UserAgent); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has root => ( | ||||||||||||||||||||||||||||
| 30 | is => 'ro', | ||||||||||||||||||||||||||||
| 31 | isa => Uri, | ||||||||||||||||||||||||||||
| 32 | default => $ENV{PINTO_REPOSITORY_ROOT}, | ||||||||||||||||||||||||||||
| 33 | coerce => 1, | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | has username => ( | ||||||||||||||||||||||||||||
| 37 | is => 'ro', | ||||||||||||||||||||||||||||
| 38 | isa => Str, | ||||||||||||||||||||||||||||
| 39 | default => current_username, | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | has password => ( | ||||||||||||||||||||||||||||
| 43 | is => 'ro', | ||||||||||||||||||||||||||||
| 44 | isa => Maybe [Str], | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | around BUILDARGS => sub { | ||||||||||||||||||||||||||||
| 50 | my $orig = shift; | ||||||||||||||||||||||||||||
| 51 | my $class = shift; | ||||||||||||||||||||||||||||
| 52 | my $args = $class->$orig(@_); | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Grrr. Gotta avoid passing undefs to Moose | ||||||||||||||||||||||||||||
| 55 | my @chrome_attrs = qw(verbose quiet color); | ||||||||||||||||||||||||||||
| 56 | my %chrome_args = map { $_ => delete $args->{$_} } | ||||||||||||||||||||||||||||
| 57 | grep { exists $args->{$_} } @chrome_attrs; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | $args->{chrome} ||= Pinto::Chrome::Term->new(%chrome_args); | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | return $args; | ||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 68 | 0 | my ( $self, $action_name, @args ) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Divert all warnings through our chrome | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | local $SIG{__WARN__} = sub { $self->warning($_) for @_ }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my $action_args = ( @args == 1 and ref $args[0] eq 'HASH' ) ? $args[0] : {@args}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC0%0/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table0%0/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | my $result = try { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my $action_class = $self->load_class_for_action( name => $action_name ); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $action = $action_class->new( | |||||||||||||||||||||||||||
| 80 | name => $action_name, | ||||||||||||||||||||||||||||
| 81 | args => $action_args, | ||||||||||||||||||||||||||||
| 82 | root => $self->root, | ||||||||||||||||||||||||||||
| 83 | username => $self->username, | ||||||||||||||||||||||||||||
| 84 | password => $self->password, | ||||||||||||||||||||||||||||
| 85 | chrome => $self->chrome, | ||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | $action->execute; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | 0 | ▶ | catch { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 91 | 0 | $self->error($_); | |||||||||||||||||||||||||||
| 92 | 0 | Pinto::Result->new->failed( because => $_ ); | |||||||||||||||||||||||||||
| 93 | 0 | }; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | return $result; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub load_class_for_action { | ||||||||||||||||||||||||||
|
Subroutine
load_class_for_action: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 101 | 0 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | my $action_name = $args{name} | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | or throw 'Must specify an action name'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $action_baseclass = __PACKAGE__ . '::Action'; | |||||||||||||||||||||||||||
| 107 | 0 | my $action_subclass = __PACKAGE__ . '::Action::' . ucfirst $action_name; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | my $subclass_did_load = Class::Load::try_load_class($action_subclass); | |||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $action_class = $subclass_did_load ? $action_subclass : $action_baseclass; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | Class::Load::load_class($action_class); | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | return $action_class; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | __PACKAGE__->meta->make_immutable; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 1; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||