xFTP.pm

filter: Statementstmt 22.5% 45 / 200 Branchbran 1.1% 1 / 86 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 73.6% 14 / 19 Podpod 100% 5 / 5 totaltotal 18.1% 65 / 358 CC 70 SCAR 81.5
CC
70
Cov
15%
new
4556.0
haveModule
20.0
haveFTP
2.0
CRAP 3469.9
↑ Summary xFTP_LOCAL.pm »
1 package Net::xFTP;
2
3 2 require 5.001;
4
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use vars qw(@ISA $VERSION %CONSTANTS);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Cwd 'cwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 #x use Fcntl ':mode';
12 #x use File::Copy;
13
14 2 my @supported_mods = (qw(ftp sftp ssh2 local foreign openssh fsp ftpssl));
15 2 my %haveit;
16 2 my $haveSFTPConstants = 0;
17
18 2 foreach my $imod (@supported_mods)
19 {
20 16 $haveit{$imod} = 0;
21 }
22 2 $haveit{'local'} = 1; #JWT:ADDED 20150123 - WE *ALWAYS* HAVE "local", SINCE NO EXTERNAL MODULE REQUIRED!
23
24 2 ▶my $bummer = ($^O =~ /Win/o) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /Win/o ? : 0 2 2
25
26 0 ▶eval 'use Net::LOCAL; $haveit{"local"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
27 2 ▶eval 'use Net::FTP; $haveit{"ftp"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 0 ▶eval 'use Net::SFTP; $haveit{"sftp"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
29 0 ▶eval 'use Net::SFTP::Constants qw(SSH2_FXF_WRITE SSH2_FXF_CREAT SSH2_FXF_TRUNC); $haveSFTPConstants = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
30 0 ▶eval 'use Net::SSH2; use Net::SSH2::SFTP; $haveit{"ssh2"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
31 0 ▶eval 'use Net::SFTP::Foreign; $haveit{"foreign"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
32 0 ▶eval 'use Net::OpenSSH; use IO::Pty; $haveit{"openssh"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
33 0 ▶eval 'use Net::FSP; $haveit{"fsp"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
34 0 ▶eval 'use Net::FTPSSL; $haveit{"ftpssl"} = 1; 1';
Subroutine BEGIN: called CC=1 SCAR=1.2
35
36 2 our $VERSION = '1.02';
37
38 sub new
39 0 ▶{
Subroutine new: not called CC=67 SCAR=84.2
Pod documented
40 0 my $class = shift;
41 0 $@ = '';
42 0 ▶ my $pkg = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
43 0 $pkg =~ s/\s+//go;
44 0 ▶ $pkg = 'Net::' . $pkg unless (!$pkg || $pkg =~ /^Net/o);
Branch: 1 branch
BranchTrueFalseTotal
unless not $pkg or $pkg =~ /^Net/o 0 0 0
Condition0%0/3
not $pkg or $pkg =~ /^Net/o
l!l&&r!l&&!r
000
MC/DC0%0/2
not $pkg or $pkg =~ /^Net/o
not $pkg $pkg =~ /^Net/o
Truth table0%0/3
not(A) or B
A= not $pkgB= $pkg =~ /^Net/o
ABresult
1X1
011
000
45 0 ▶ $pkg = 'Net::SFTP::Foreign' if ($pkg eq 'Net::Foreign'); #FIXUP.
Branch: 1 branch
BranchTrueFalseTotal
if $pkg eq "Net::Foreign" 0 0 0
46 0 my $host = shift;
47 0 my %args = @_;
48 0 my $xftp;
49 my %xftp_args;
50 0 my ($i, $j, $t);
51
52 0 foreach $i (keys %args)
53 {
54 0 ▶ if ($i =~ s/^xftp_//o) #EXTRACT OUT OUR SPECIAL ARGS ("xftp_*")
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ s/^xftp_//o) 0 0 0
55 {
56 0 $xftp_args{$i} = $args{"xftp_$i"};
57
58 0 delete $args{"xftp_$i"};
59 }
60 }
61 0 ▶ if ($pkg =~ /Net::FTPSSL/)
Branch: 8 branches
BranchTrueFalseTotal
if ($pkg =~ /Net::FTPSSL/) { } 0 0 0
elsif ($pkg =~ /Net::FTP/) { } 0 0 0
elsif ($pkg =~ /Net::SFTP::Foreign/) { } 0 0 0
elsif ($pkg =~ /Net::SSH2/) { } 0 0 0
elsif ($pkg =~ /Net::SFTP/) { } 0 0 0
elsif ($pkg =~ /Net::FSP/) { } 0 0 0
elsif ($pkg =~ /Net::OpenSSH/) { } 0 0 0
elsif (not $pkg or $pkg =~ /local/i) { } 0 0 0
62 {
63 0 eval { require "Net/xFTP_FTPSSL.pm" };
64 0 ▶ if ($@ || !$haveit{'ftpssl'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"ftpssl"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"ftpssl"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"ftpssl"}
$@ not $haveit{"ftpssl"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"ftpssl"}
ABresult
1X1
011
000
65 {
66 0 warn "xFTP:Could not require Net::xFTP_FTPSSL.pm module($@)!";
67 0 return undef;
68 }
69 0 foreach $i (keys %args)
70 {
71 0 foreach $j (@supported_mods)
72 {
73 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
74 {
75 0 ▶ if ($j eq 'ftpssl')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "ftpssl") 0 0 0
76 {
77 0 ($t = $i) =~ s/^${j}_//;
78 0 $args{$t} = $args{$i};
79 }
80 0 delete $args{$i};
81 }
82 }
83 }
84 0 $xftp = Net::xFTP::FTPSSL::new_ftpssl("${class}::FTPSSL", $pkg, $host, %args);
85 }
86 elsif ($pkg =~ /Net::FTP/)
87 {
88 0 eval { require "Net/xFTP_FTP.pm" };
89 0 ▶ if ($@ || !$haveit{'ftp'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"ftp"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"ftp"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"ftp"}
$@ not $haveit{"ftp"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"ftp"}
ABresult
1X1
011
000
90 {
91 0 warn "xFTP:Could not require Net::xFTP_FTP.pm module($@)!";
92 0 return undef;
93 }
94 0 foreach $i (keys %args)
95 {
96 0 foreach $j (@supported_mods)
97 {
98 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
99 {
100 0 ▶ if ($j eq 'ftp')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "ftp") 0 0 0
101 {
102 0 ($t = $i) =~ s/^${j}_//;
103 0 $args{$t} = $args{$i};
104 }
105 0 delete $args{$i};
106 }
107 }
108 }
109 0 $xftp = Net::xFTP::FTP::new_ftp("${class}::FTP", $pkg, $host, %args);
110 }
111 elsif ($pkg =~ /Net::SFTP::Foreign/)
112 {
113 0 eval { require "Net/xFTP_Foreign.pm" };
114 0 ▶ if ($@ || !$haveit{'foreign'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"foreign"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"foreign"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"foreign"}
$@ not $haveit{"foreign"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"foreign"}
ABresult
1X1
011
000
115 {
116 0 warn "xFTP:Could not require Net::xFTP_Foreign.pm module($@)!";
117 0 return undef;
118 }
119 0 foreach $i (keys %args)
120 {
121 0 foreach $j (@supported_mods)
122 {
123 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
124 {
125 0 ▶ if ($j eq 'foreign')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "foreign") 0 0 0
126 {
127 0 ($t = $i) =~ s/^${j}_//;
128 0 $args{$t} = $args{$i};
129 }
130 0 delete $args{$i};
131 }
132 }
133 }
134 0 $xftp = Net::xFTP::Foreign::new_foreign("${class}::Foreign", $pkg, $host, %args);
135 }
136 elsif ($pkg =~ /Net::SSH2/)
137 {
138 0 eval { require "Net/xFTP_SSH2.pm" };
139 0 ▶ if ($@ || !$haveit{'ssh2'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"ssh2"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"ssh2"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"ssh2"}
$@ not $haveit{"ssh2"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"ssh2"}
ABresult
1X1
011
000
140 {
141 0 warn "xFTP:Could not require Net::xFTP_SSH2.pm module($@)!";
142 0 return undef;
143 }
144 0 foreach $i (keys %args)
145 {
146 0 foreach $j (@supported_mods)
147 {
148 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
149 {
150 0 ▶ if ($j eq 'ssh2')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "ssh2") 0 0 0
151 {
152 0 ($t = $i) =~ s/^${j}_//;
153 0 $args{$t} = $args{$i};
154 }
155 0 delete $args{$i};
156 }
157 }
158 }
159 0 $xftp = Net::xFTP::SSH2::new_ssh2("${class}::SSH2", $pkg, $host, %args);
160 }
161 elsif ($pkg =~ /Net::SFTP/)
162 {
163 0 eval { require "Net/xFTP_SFTP.pm" };
164 0 ▶ if ($@ || !$haveit{'sftp'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"sftp"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"sftp"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"sftp"}
$@ not $haveit{"sftp"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"sftp"}
ABresult
1X1
011
000
165 {
166 0 warn "xFTP:Could not require Net::xFTP_SFTP.pm module($@)!";
167 0 return undef;
168 }
169 0 foreach $i (keys %args)
170 {
171 0 foreach $j (@supported_mods)
172 {
173 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
174 {
175 0 ▶ if ($j eq 'sftp')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "sftp") 0 0 0
176 {
177 0 ($t = $i) =~ s/^${j}_//;
178 0 $args{$t} = $args{$i};
179 }
180 0 delete $args{$i};
181 }
182 }
183 }
184 0 $xftp = Net::xFTP::SFTP::new_sftp("${class}::SFTP", $pkg, $host, %args);
185 0 ▶ $xftp->{haveSFTPConstants} = $haveSFTPConstants if ($xftp);
Branch: 1 branch
BranchTrueFalseTotal
if $xftp 0 0 0
186 }
187 elsif ($pkg =~ /Net::FSP/)
188 {
189 0 eval { require "Net/xFTP_FSP.pm" };
190 0 ▶ if ($@ || !$haveit{'fsp'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"fsp"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"fsp"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"fsp"}
$@ not $haveit{"fsp"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"fsp"}
ABresult
1X1
011
000
191 {
192 0 warn "xFTP:Could not require Net::xFTP_FSP.pm module($@)!";
193 0 return undef;
194 }
195 0 foreach $i (keys %args)
196 {
197 0 foreach $j (@supported_mods)
198 {
199 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
200 {
201 0 ▶ if ($j eq 'fsp')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "fsp") 0 0 0
202 {
203 0 ($t = $i) =~ s/^${j}_//;
204 0 $args{$t} = $args{$i};
205 }
206 0 delete $args{$i};
207 }
208 }
209 }
210 0 $xftp = Net::xFTP::FSP::new_fsp("${class}::FSP", $pkg, $host, %args);
211 }
212 elsif ($pkg =~ /Net::OpenSSH/)
213 {
214 0 eval { require "Net/xFTP_OpenSSH.pm" };
215 0 ▶ if ($@ || !$haveit{'openssh'})
Branch: 1 branch
BranchTrueFalseTotal
if ($@ or not $haveit{"openssh"}) 0 0 0
Condition0%0/3
$@ or not $haveit{"openssh"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$@ or not $haveit{"openssh"}
$@ not $haveit{"openssh"}
Truth table0%0/3
A or not(B)
A= $@B= not $haveit{"openssh"}
ABresult
1X1
011
000
216 {
217 0 warn "xFTP:Could not require Net::xFTP_OpenSSH.pm module($@)!";
218 0 return undef;
219 }
220 0 foreach $i (keys %args)
221 {
222 0 foreach $j (@supported_mods)
223 {
224 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
225 {
226 0 ▶ if ($j eq 'openssh')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "openssh") 0 0 0
227 {
228 0 ($t = $i) =~ s/^${j}_//;
229 0 $args{$t} = $args{$i};
230 }
231 0 delete $args{$i};
232 }
233 }
234 }
235 0 $xftp = Net::xFTP::OpenSSH::new_openssh("${class}::OpenSSH", $pkg, $host, %args);
236 }
237 ▶ elsif (!$pkg || $pkg =~ /local/i)
Condition0%0/3
not $pkg or $pkg =~ /local/i
l!l&&r!l&&!r
000
MC/DC0%0/2
not $pkg or $pkg =~ /local/i
not $pkg $pkg =~ /local/i
Truth table0%0/3
not(A) or B
A= not $pkgB= $pkg =~ /local/i
ABresult
1X1
011
000
238 {
239 0 eval { require "Net/xFTP_LOCAL.pm" };
240 0 ▶ if ($@)
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
241 {
242 0 warn "xFTP:Could not require Net::xFTP_LOCAL.pm module($@)!";
243 0 return undef;
244 }
245 0 foreach $i (keys %args)
246 {
247 0 foreach $j (@supported_mods)
248 {
249 0 ▶ if ($i =~ /^${j}\_/)
Branch: 1 branch
BranchTrueFalseTotal
if ($i =~ /^$j\_/) 0 0 0
250 {
251 0 ▶ if ($j eq 'local')
Branch: 1 branch
BranchTrueFalseTotal
if ($j eq "local") 0 0 0
252 {
253 0 ($t = $i) =~ s/^${j}_//;
254 0 $args{$t} = $args{$i};
255 }
256 0 delete $args{$i};
257 }
258 }
259 }
260 0 $xftp = Net::xFTP::LOCAL::new_local("${class}::LOCAL", $pkg, $host, %args);
261 }
262 else
263 {
264 0 $@ = "No such package \"$pkg\"!";
265 0 warn "xFTP:$@!";
266 0 return undef;
267 }
268
269 0 ▶ if ($xftp)
Branch: 1 branch
BranchTrueFalseTotal
if ($xftp) { } 0 0 0
270 {
271 0 ▶ $xftp->{pkg} = ($pkg =~ /local/io) ? $pkg : '';
Branch: 1 branch
BranchTrueFalseTotal
$pkg =~ /local/io ? : 0 0 0
272 0 ▶ $xftp->{bummer} = ($^O =~ /Win/o) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$^O =~ /Win/o ? : 0 0 0
273 0 return $xftp;
274 }
275 else
276 {
277 0 @_ = @_ . " Could not get new $pkg object (undef)!";
278 }
279 0 return undef;
280 }
281
282 sub haveFTP #DEPRECIATED, USE haveModule($module) INSTEAD!
283 0 ▶{
Subroutine haveFTP: not called CC=1 SCAR=6.9
Pod documented
284 0 return $haveit{'ftp'};
285 }
286
287 sub haveSFTP
288 0 ▶{
Subroutine haveSFTP: not called CC=1 SCAR=6.9
Pod documented
289 0 return $haveit{'sftp'};
290 }
291
292 sub haveModule
293 0 ▶{
Subroutine haveModule: not called CC=4 SCAR=30.0
Pod documented
294 0 my $self = shift;
295 0 my $modul = shift;
296
297 0 my $modHash = &haveModules();
298 0 ▶ if ($modul =~ /^Net\:\:/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modul =~ /^Net\:\:/) 0 0 0
299 0 ▶ return (defined $modHash->{$modul}) ? $modHash->{$modul} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $modHash->{$modul} ? : 0 0 0
300 }
301 0 $modul =~ tr/A-Z/a-z/;
302 0 ▶ return (defined $haveit{$modul}) ? $haveit{$modul} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $haveit{$modul} ? : 0 0 0
303 }
304
305 sub haveModules
306 0 ▶{
Subroutine haveModules: not called CC=1 SCAR=6.9
Pod documented
307 return { 'Net::FTP' => $haveit{'ftp'}, 'Net::SFTP' => $haveit{'sftp'},
308 'Net::SSH2' => $haveit{'ssh2'}, 'Net::SFTP::Foreign' => $haveit{'foreign'},
309 'Net::OpenSSH' => $haveit{'openssh'}, 'Net::FSP' => $haveit{'fsp'},
310 0 'Net::FTPSSL' => $haveit{'ftpssl'}, 'Net::LOCAL' => $haveit{'local'}};
311 }
312
313 2 1
314
315 __END__
↑ Summary xFTP_LOCAL.pm »