Helm/Task/get.pm untested

filter: Statementstmt 0.0% 0 / 30 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 49 CC 3 SCAR 16.7
CC
3
Cov
0%
validate
12.0
help
2.0
execute
2.0
CRAP 5.3
1 package Helm::Task::get;
2 use strict;
3 use warnings;
4 use Moose;
5 use Net::OpenSSH;
6  
7 extends 'Helm::Task';
8  
9 sub validate {
10 my $self = shift;
11 my $helm = $self->helm;
12 my $extra_options = $helm->extra_options;
13  
14 # make sure we have local and remote options
15 $helm->die('Missing option: local') unless $extra_options->{local};
16 $helm->die('Missing option: remote') unless $extra_options->{remote};
17 }
18  
19 sub help {
20 my $self = shift;
21 return <<END;
22 Retrieve a file from a remote server. Takes the following required
23 options:
24  
25 --local
26 The (base) name of the new file after it's copied to the local
27 machine. This local name will have the server's name appended to it
28 to make it distinct from the files copied over from other servers.
29  
30 --remote
31 The full path to the file on the remote server(s).
32 END
33 }
34  
35 sub execute {
36 my ($self, %args) = @_;
37 my $server = $args{server};
38 my $ssh = $args{ssh};
39 my $helm = $self->helm;
40 my $options = $helm->extra_options;
41 my $local = $options->{local};
42 my $remote = $options->{remote};
43  
44 # get our file over here with a new name
45 $ssh->scp_get($remote, "$local.$server")
46 || $helm->die("Can't scp file ($remote) from server $server: " . $ssh->error);
47 $helm->log->info("File $server:$remote copied to $local.$server");
48 }
49  
50 __PACKAGE__->meta->make_immutable;
51  
52 1;