Any/SCP/Putter/Content.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 84 CC 3 SCAR 12.0
CC
3
Cov
0%
read_dir
6.0
read_file
6.0
_new
2.0
CRAP 3.3
1 package Net::SSH::Any::SCP::Putter::Content;
2  
3 use strict;
4 use warnings;
5 use Carp;
6  
7 use Net::SSH::Any::Util qw($debug _debug _debug_dump _first_defined _croak_bad_options);
8  
9 require Net::SSH::Any::SCP::Putter;
10 our @ISA = qw(Net::SSH::Any::SCP::Putter);
11  
12 sub _new {
13 @_ == 5 or croak 'Usage: $ssh->scp_put_content(\%opts, $target, $content)';
14 my ($class, $any, $opts, $target, $content) = @_;
15 my $perm = _first_defined delete $opts->{perm}, 0666;
16 my $atime = delete $opts->{atime};
17 my $mtime = delete $opts->{mtime};
18 _croak_bad_options %$opts;
19  
20 $opts->{send_time} = (defined $atime or defined $mtime);
21 my $p = $class->SUPER::_new($any, $opts, $target);
22 $p->{perm} = $perm;
23 $p->{content} = $content;
24 $p->{atime} = $atime // $mtime;
25 $p->{mtime} = $mtime // $atime;
26 $p;
27 }
28  
29 sub read_dir {
30 my ($p, $action) = @_;
31 if (defined (my $content = delete $p->{content})) {
32 my $file_part = (File::Spec->splitpath($p->{target}))[2];
33 return { type => 'file',
34 local_path => $file_part,
35 name => $file_part,
36 perm => $p->{perm},
37 size => length($content),
38 atime => delete $p->{atime},
39 mtime => delete $p->{mtime},
40 content => $content
41 };
42 }
43 ()
44 }
45  
46 sub open_file { 1 }
47  
48 sub read_file {
49 my ($p, $action, $fh, $len) = @_;
50 if ($len and not length($action->{content})) {
51 $p->set_local_error($action, "premature EOF reached");
52 return;
53 }
54 substr($action->{content}, 0, $len, '');
55 }
56  
57 sub close_file {
58 my ($action, $handle) = @_;
59 return $handle
60 }
61  
62 1;