Foreign/Compat.pm

filter: Statementstmt 39.5% 51 / 129 Branchbran 4.5% 2 / 44 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 29.6% 8 / 27 Podpod 55.5% 5 / 9 totaltotal 28.2% 66 / 234 CC 31 SCAR 27.8
CC
31
Cov
28%
get
56.0
ls
42.0
new
12.0
CRAP 16.2
« Foreign/Backend/Windows.pm ↑ Summary Foreign/Local.pm »
1 package Net::SFTP::Foreign::Compat;
2  
3 1 our $VERSION = '1.70_05';
4  
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 require Net::SFTP::Foreign;
10 1 require Net::SFTP::Foreign::Constants;
11 1 require Net::SFTP::Foreign::Attributes::Compat;
12  
13 1 our @ISA = qw(Net::SFTP::Foreign);
14  
15 1 my $supplant;
16  
17 2 ▶sub import {
Subroutine import: called CC=4 SCAR=14.2
18 2 for my $arg (@_[1..$#_]) {
19 1 ▶ if ($arg eq ':supplant') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq ':supplant') { } 1 0 1
20 # print STDERR "suplanting Net::SFTP...\n";
21 1 ▶ if (!$supplant) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($supplant) 1 0 1
22 1 $supplant = 1;
23  
24 1 @Net::SFTP::ISA = qw(Net::SFTP::Foreign::Compat);
25 1 @Net::SFTP::Attributes::ISA = qw(Net::SFTP::Foreign::Attributes::Compat);
26 1 @Net::SFTP::Constant::ISA = qw(Net::SFTP::Foreign::Constants);
27  
28 1 $INC{q(Net/SFTP.pm)} = $INC{q(Net/SFTP/Foreign/Compat.pm)};
29 1 $INC{q(Net/SFTP/Attributes.pm)} = $INC{q(Net/SFTP/Foreign/Compat.pm)};
30 1 $INC{q(Net/SFTP/Constants.pm)} = $INC{q(Net/SFTP/Foreign/Compat.pm)};
31  
32 }
33 }
34 else {
35 0 croak "invalid import tag '$arg'"
36 }
37 }
38 }
39  
40 1 our %DEFAULTS = ( put => [best_effort => 1],
41 get => [best_effort => 1],
42 ls => [],
43 new => [] );
44  
45 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=8.0
46 1 my @forbidden = qw( setcwd cwd open opendir sftpread sftpwrite
47 seek tell eof write flush read getc lstat stat
48 fstat remove rmdir mkdir setstat fsetstat
49 close closedir readdir realpath readlink
50 rename symlink abort get_content join glob
51 rremove rget rput error die_on_error );
52  
53 1 for my $method (@forbidden) {
54 37 my $super = "SUPER::$method";
55 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
56 37 ▶ *{$method} = sub {
Subroutine __ANON__: not called CC=2 SCAR=14.6
57 0 ▶ unless (index((caller)[0], "Net::SFTP::Foreign") == 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (index((caller)[0], "Net::SFTP::Foreign") == 0) 0 0 0
58 0 croak "Method '$method' is not available from " . __PACKAGE__
59 . ", use the real Net::SFTP::Foreign if you want it!";
60 }
61 0 shift->$super(@_);
62 37 };
63 }
64 }
65  
66 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
67 0 my ($class, $host, %opts) = @_;
68  
69 0 my $warn;
70 0 ▶ if (exists $opts{warn}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{'warn'}) { } 0 0 0
71 0 ▶ $warn = delete($opts{warn}) || sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
delete $opts{'warn'} || sub { }
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opts{'warn'} || sub { }
delete $opts{'warn'} sub { }
Truth table0%0/3
A || B
A= delete $opts{'warn'}B= sub { }
ABresult
1X1
011
000
72 }
73 else {
74 0 ▶ $warn = sub { warn(CORE::join '', @_, "\n") };
Subroutine __ANON__: not called CC=1 SCAR=6.9
75 }
76  
77 0 my $sftp = $class->SUPER::new($host, @{$DEFAULTS{new}}, %opts);
78  
79 0 $sftp->{_compat_warn} = $warn;
80  
81 0 return $sftp;
82  
83 }
84  
85 0 ▶sub _warn {
Subroutine _warn: not called CC=2 SCAR=17.9
86 0 my $sftp = shift;
87 0 ▶ if (my $w = $sftp->{_compat_warn}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $w = $sftp->{"_compat_warn"}) 0 0 0
88 0 $w->(@_);
89 }
90 }
91  
92 0 ▶sub _warn_error {
Subroutine _warn_error: not called CC=2 SCAR=17.9
93 0 my $sftp = shift;
94 0 ▶ if (my $e = $sftp->SUPER::error) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = $sftp->SUPER::error) 0 0 0
95 0 $sftp->_warn($e);
96 }
97 }
98  
99 0 ▶sub status {
Subroutine status: not called CC=2 SCAR=17.9
Pod documented
100 0 my $status = shift->SUPER::status;
101 0 ▶ return wantarray ? ($status + 0, "$status") : $status + 0;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
102 }
103  
104 0 ▶sub get {
Subroutine get: not called CC=7 SCAR=40.3
Pod documented
105 0 ▶ croak '$Usage: $sftp->get($local, $remote, $cb)' if @_ < 2 or @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 4 0 0 0
Condition0%0/3
@_ < 2 or @_ > 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 4
@_ < 2 @_ > 4
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 4
ABresult
1X1
011
000
106 0 my ($sftp, $remote, $local, $cb) = @_;
107  
108 0 my $save = defined(wantarray);
109 0 my @content;
110 my @cb;
111 0 ▶ if (defined $cb or $save) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cb or $save) 0 0 0
Condition0%0/3
defined $cb or $save
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $cb or $save
defined $cb $save
Truth table0%0/3
A or B
A= defined $cbB= $save
ABresult
1X1
011
000
112 0 ▶ @cb = ( callback => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
113 0 my ($sftp, $data, $off, $size) = @_;
114 0 ▶ $cb->($sftp, $data, $off, $size) if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 0 0 0
115 0 ▶ push @content, $data if $save
Branch: 1 branch
BranchTrueFalseTotal
if $save 0 0 0
116 0 });
117 }
118  
119 $sftp->SUPER::get($remote, $local,
120 0 ▶ @{$DEFAULTS{get}},
Branch: 1 branch
BranchTrueFalseTotal
$sftp->SUPER::get($remote, $local, @{$Net::SFTP::Foreign::Compat::DEFAULTS{"get"};}, "dont_save", !defined($local), @cb) or return undef 0 0 0
121 dont_save => !defined($local),
122 @cb)
123 or return undef;
124  
125 0 ▶ if ($save) {
Branch: 1 branch
BranchTrueFalseTotal
if ($save) 0 0 0
126 0 return CORE::join('', @content);
127 }
128 }
129  
130 0 ▶sub put {
Subroutine put: not called CC=3 SCAR=24.8
Pod documented
131 0 ▶ croak '$Usage: $sftp->put($local, $remote, $cb)' if @_ < 3 or @_ > 4;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 3 or @_ > 4 0 0 0
Condition0%0/3
@_ < 3 or @_ > 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 3 or @_ > 4
@_ < 3 @_ > 4
Truth table0%0/3
A or B
A= @_ < 3B= @_ > 4
ABresult
1X1
011
000
132 0 my ($sftp, $local, $remote, $cb) = @_;
133  
134 $sftp->SUPER::put($local, $remote,
135 0 @{$DEFAULTS{put}},
136 callback => $cb);
137 0 $sftp->_warn_error;
138 0 !$sftp->SUPER::error;
139 }
140  
141 0 ▶sub ls {
Subroutine ls: not called CC=6 SCAR=37.4
Pod documented
142 0 ▶ croak '$Usage: $sftp->ls($path, $cb)' if @_ < 2 or @_ > 3;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 or @_ > 3 0 0 0
Condition0%0/3
@_ < 2 or @_ > 3
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ < 2 or @_ > 3
@_ < 2 @_ > 3
Truth table0%0/3
A or B
A= @_ < 2B= @_ > 3
ABresult
1X1
011
000
143 0 my ($sftp, $path, $cb) = @_;
144 0 ▶ if ($cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) { } 0 0 0
145 $sftp->SUPER::ls($path,
146 0 @{$DEFAULTS{ls}},
147 0 ▶ wanted => sub { _rebless_attrs($_[1]->{a});
Subroutine __ANON__: not called CC=1 SCAR=6.9
148 0 $cb->($_[1]);
149 0 0 } );
150 0 return ();
151 }
152 else {
153 0 ▶ if (my $ls = $sftp->SUPER::ls($path, @{$DEFAULTS{ls}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ls = $sftp->SUPER::ls($path, @{$Net::SFTP::Foreign::Compat::DEFAULTS{"ls"};})) 0 0 0
154 0 _rebless_attrs($_->{a}) for @$ls;
155 0 return @$ls;
156 }
157 return ()
158 0 }
159 }
160  
161 0 ▶sub do_open { shift->SUPER::open(@_) }
Subroutine do_open: not called CC=1 SCAR=6.9
Pod undocumented
162  
163 0 ▶sub do_opendir { shift->SUPER::opendir(@_) }
Subroutine do_opendir: not called CC=1 SCAR=6.9
Pod undocumented
164  
165 0 ▶sub do_realpath { shift->SUPER::realpath(@_) }
Subroutine do_realpath: not called CC=1 SCAR=6.9
Pod undocumented
166  
167 0 ▶sub do_read {
Subroutine do_read: not called CC=2 SCAR=17.9
Pod undocumented
168 0 my $sftp = shift;
169 0 my $read = $sftp->SUPER::sftpread(@_);
170 0 $sftp->_warn_error;
171 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
172 0 return ($read, $sftp->status);
173 }
174 else {
175 0 return $read
176 }
177 }
178  
179 8 ▶sub _gen_do_and_status {
Subroutine _gen_do_and_status: called CC=1 SCAR=2.6
180 8 my $method = "SUPER::" . shift;
181 0 ▶ return sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
182 0 my $sftp = shift;
183 0 $sftp->$method(@_);
184 0 $sftp->_warn_error;
185 0 $sftp->status;
186 }
187 8 }
188  
189 1 *do_write = _gen_do_and_status('sftpwrite');
190 1 *do_close = _gen_do_and_status('close');
191 1 *do_setstat = _gen_do_and_status('setstat');
192 1 *do_fsetstat = _gen_do_and_status('setstat');
193 1 *do_remove = _gen_do_and_status('remove');
194 1 *do_rename = _gen_do_and_status('rename');
195 1 *do_mkdir = _gen_do_and_status('mkdir');
196 1 *do_rmdir = _gen_do_and_status('rmdir');
197  
198 0 ▶sub _rebless_attrs {
Subroutine _rebless_attrs: not called CC=3 SCAR=24.8
199 0 my $a = shift;
200 0 ▶ if ($a) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a) 0 0 0
201 0 ▶ bless $a, ( $supplant
Branch: 1 branch
BranchTrueFalseTotal
$supplant ? : 0 0 0
202 ? "Net::SFTP::Attributes"
203 : "Net::SFTP::Foreign::Attributes::Compat" );
204 }
205 0 $a;
206 }
207  
208 3 ▶sub _gen_do_stat {
Subroutine _gen_do_stat: called CC=1 SCAR=3.8
209 3 my $name = shift;
210 3 my $method = "SUPER::$name";
211 0 ▶ return sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
212 0 ▶ croak '$Usage: $sftp->'.$name.'($local, $remote, $cb)' if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 0 0
213 0 my $sftp = shift;
214 0 ▶ if (my $a = $sftp->$method(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $a = $sftp->$method(@_)) { } 0 0 0
215 0 return _rebless_attrs($a);
216 }
217 else {
218 0 $sftp->_warn_error;
219 0 return undef;
220 }
221 }
222 3 }
223  
224 1 *do_lstat = _gen_do_stat('lstat');
225 1 *do_fstat = _gen_do_stat('fstat');
226 1 *do_stat = _gen_do_stat('stat');
227  
228  
229 1 1;
230  
231 __END__
« Foreign/Backend/Windows.pm ↑ Summary Foreign/Local.pm »