File Coverage

blib/lib/Pinto/Remote.pm
Criterion Covered Total %
statement 33 52 63.4
branch 0 6 0.0
condition 0 3 0.0
subroutine 11 16 68.7
pod n/a
total 44 77 57.1


line stmt bran cond sub pod time code
1             # ABSTRACT: Interact with a remote Pinto repository
2              
3             package Pinto::Remote;
4              
5 5     5   952506 use Moose;
  5         1946869  
  5         34  
6 5     5   34860 use MooseX::StrictConstructor;
  5         111112  
  5         22  
7 5     5   48775 use MooseX::MarkAsMethods ( autoclean => 1 );
  5         40770  
  5         34  
8 5     5   43821 use MooseX::Types::Moose qw(Maybe Str);
  5         232331  
  5         52  
9              
10 5     5   21627 use Try::Tiny;
  5         10  
  5         317  
11 5     5   1631 use LWP::UserAgent;
  5         87698  
  5         179  
12              
13 5     5   2010 use Pinto::Chrome::Term;
  5         18  
  5         224  
14 5     5   1998 use Pinto::Remote::Action;
  5         18  
  5         263  
15 5     5   40 use Pinto::Constants qw(:server);
  5         9  
  5         396  
16 5     5   504 use Pinto::Util qw(throw current_username);
  5         12  
  5         239  
17 5     5   26 use Pinto::Types qw(Uri);
  5         10  
  5         41  
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             sub run {
68 0     0     my ( $self, $action_name, @args ) = @_;
69              
70             # Divert all warnings through our chrome
71 0     0     local $SIG{__WARN__} = sub { $self->warning($_) for @_ };
  0            
72              
73 0 0 0       my $action_args = ( @args == 1 and ref $args[0] eq 'HASH' ) ? $args[0] : {@args};
74              
75             my $result = try {
76              
77 0     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             catch {
91 0     0     $self->error($_);
92 0           Pinto::Result->new->failed( because => $_ );
93 0           };
94              
95 0           return $result;
96             }
97              
98             #------------------------------------------------------------------------------
99              
100             sub load_class_for_action {
101 0     0     my ( $self, %args ) = @_;
102              
103             my $action_name = $args{name}
104 0 0         or throw 'Must specify an action name';
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 0         my $action_class = $subclass_did_load ? $action_subclass : $action_baseclass;
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__
126              
127             =pod
128              
129             =encoding UTF-8
130              
131             =for :stopwords Jeffrey Ryan Thalhammer
132              
133             =head1 NAME
134              
135             Pinto::Remote - Interact with a remote Pinto repository
136              
137             =head1 VERSION
138              
139             version 0.14
140              
141             =head1 SYNOPSIS
142              
143             See L<pinto> to create and manage a Pinto repository.
144              
145             See L<pintod> to allow remote access to your Pinto repository.
146              
147             See L<Pinto::Manual> for more information about the Pinto tools.
148              
149             =head1 DESCRIPTION
150              
151             Pinto::Remote is the cousin of L<Pinto>. It provides the same API,
152             but instead of running Actions against a local repository, it just
153             sends the Action parameters to a L<pintod> server that invokes Pinto
154             on the remote host.
155              
156             If you are using the L<pinto> application, it will automatically load
157             either Pinto or Pinto::Remote depending on whether your repository
158             root looks like a local directory path or a remote URI.
159              
160             =head1 METHODS
161              
162             =head2 run( $action_name => %action_args )
163              
164             Loads the Action subclass for the given C<$action_name> and constructs
165             an object using the given C<$action_args>. If the subclass
166             C<Pinto::Remote::Action::$action_name> does not exist, then it falls
167             back to the L<Pinto::Remote::Action> base class.
168              
169             =head1 AUTHOR
170              
171             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
172              
173             =head1 COPYRIGHT AND LICENSE
174              
175             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
176              
177             This is free software; you can redistribute it and/or modify it under
178             the same terms as the Perl 5 programming language system itself.
179              
180             =cut