blib/lib/Net/FTP/Simple.pm

filter: Statementstmt 78.2% 140 / 179 Branchbran 47.2% 51 / 108 Conditioncond 54.5% 6 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 91.6% 22 / 24 Podpod 100% 4 / 4 totaltotal 67.5% 225 / 333 CC 64 SCAR 31.8
CC
64
Cov
66%
retrieve_files
132.0
_create_and_cwd_remote_dir
30.0
send_files
15.2
CRAP 24.0
↑ Summary
1 #
2 # Net::FTP::Simple - Simplified Net::FTP interface encapsulating a few simple
3 # operations.
4 #
5 # Written by Wil Cooley <wcooley@nakedape.cc>
6 #
7 # $Id: Simple.pm 758 2008-10-11 04:29:18Z wcooley $
8 #
9 package Net::FTP::Simple;
10 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use File::Basename qw( basename dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Net::FTP;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # FIXME MakeMaker handles it okay if it's all on one line, but Perl::Critic
19 # pukes :(
20 #eval q{ use version; our $VERSION = qv(0.0.5) }; our $VERSION = '0.0005' if ($EVAL_ERROR);
21 3 our $VERSION = '0.0007';
22  
23  
24 5 ▶sub send_files {
Subroutine send_files: called CC=11 SCAR=27.2
Pod documented
25 # Allow calls either as Net::FTP::Simple->send_files or
26 # Net::FTP::Simple::send_files
27 5 my ($opt_ref) = $_[-1];
28  
29 5 my @successful_transfers;
30 5 my $ftp = Net::FTP::Simple->_new($opt_ref);
31  
32 $ftp->_create_and_cwd_remote_dir()
33 5 ▶ if ($ftp->{'remote_dir'});
Branch: 1 branch
BranchTrueFalseTotal
if $ftp->{"remote_dir"} 0 5 5
34  
35 FILE_TO_TRANSFER:
36 5 for my $file (@{ $ftp->{'files'} }){
37 13 my $try_count;
38 13 my $basename = basename($file);
39 13 my $tmpname = $basename . '.tmp';
40  
41 13 ▶ unless ( -r $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file) 0 13 13
42 carp $ftp->_error("Local file '$file' unreadable; unable to transfer")
43 0 ▶ unless ($ftp->{'quiet_mode'});
Branch: 1 branch
BranchTrueFalseTotal
unless $ftp->{"quiet_mode"} 0 0 0
44 0 next FILE_TO_TRANSFER;
45 }
46  
47 13 ▶ unless ( $ftp->_conn()->put($file, $tmpname) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->_conn->put($file, $tmpname)) 0 13 13
48 carp $ftp->_error("Error transferring file '$file' to '$tmpname'")
49 0 ▶ unless ($ftp->{'quiet_mode'});
Branch: 1 branch
BranchTrueFalseTotal
unless $ftp->{"quiet_mode"} 0 0 0
50 0 next FILE_TO_TRANSFER;
51 }
52  
53 13 eval {
54 13 $try_count = $ftp->_op_retry('rename', $tmpname, $basename);
55 };
56  
57 13 ▶ if ($EVAL_ERROR =~ m/'rename' failed after \d+ attempts/ms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::FTP::Simple::EVAL_ERROR =~ /'rename' failed after \d+ attempts/ms) { } 2 11 13
elsif ($Net::FTP::Simple::EVAL_ERROR) { } 0 11 11
58 2 carp "Error renaming '$tmpname' to '$basename'";
59 2 next FILE_TO_TRANSFER;
60 }
61 elsif($EVAL_ERROR) {
62 # Rethrow unexpected exceptions
63 0 croak $EVAL_ERROR;
64 }
65  
66 11 ▶ if ($try_count > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try_count > 1) 4 7 11
67 4 carp "Transfer of file '$file' succeeded after $try_count tries";
68 }
69  
70 11 push @successful_transfers, $file;
71 }
72  
73 wantarray ? return @successful_transfers
74 5 ▶ : return \@successful_transfers
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 5 0 5
75 ;
76  
77 }
78  
79 4 ▶sub rename_files {
Subroutine rename_files: called CC=8 SCAR=21.6
Pod documented
80 # Allow calls either as Net::FTP::Simple->rename_files or
81 # Net::FTP::Simple::rename_files
82 4 my ($opt_ref) = $_[-1];
83  
84 4 my @successful_renames;
85  
86 4 my $ftp = Net::FTP::Simple->_new($opt_ref);
87  
88 4 ▶ if (exists $ftp->{'remote_dir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ftp->{"remote_dir"}) 0 4 4
89 0 ▶ $ftp->_conn()->cwd($ftp->{'remote_dir'})
Branch: 1 branch
BranchTrueFalseTotal
$ftp->_conn->cwd($ftp->{"remote_dir"}) or croak($ftp->_error("Error changing to remote directory", qq['$ftp->{"remote_dir"}'])) 0 0 0
90 or croak $ftp->_error("Error changing to remote directory",
91 "'$ftp->{'remote_dir'}'");
92 }
93  
94 FILE_TO_RENAME:
95 4 for my $src (sort keys %{ $ftp->{'rename_files'} }) {
96 12 my $dst = $ftp->{'rename_files'}{ $src };
97 12 my $try_count;
98  
99 12 eval {
100 12 $try_count = $ftp->_op_retry('rename', $src, $dst);
101 };
102  
103 12 ▶ if ($EVAL_ERROR =~ m/'rename' failed after \d+ attempts/ms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::FTP::Simple::EVAL_ERROR =~ /'rename' failed after \d+ attempts/ms) { } 4 8 12
elsif ($Net::FTP::Simple::EVAL_ERROR) { } 0 8 8
104 4 carp "Error renaming '$src' to '$dst'";
105 4 next FILE_TO_RENAME;
106 }
107 elsif ($EVAL_ERROR) {
108 # Rethrow the exception if it's not recognized
109 0 croak $EVAL_ERROR;
110 }
111  
112 8 ▶ if ($try_count > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($try_count > 1) 4 4 8
113 4 carp "Rename of file from '$src' to '$dst' succeeded after"
114 . " $try_count tries";
115 }
116  
117 8 push @successful_renames, $src;
118  
119 }
120  
121 4 @successful_renames = sort @successful_renames;
122  
123 wantarray ? return @successful_renames
124 4 ▶ : return \@successful_renames
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
125 ;
126  
127 }
128  
129 0 ▶sub retrieve_files {
Subroutine retrieve_files: not called CC=11 SCAR=48.8
Pod documented
130 # Allow calls either as Net::FTP::Simple->retrieve_files or
131 # Net::FTP::Simple::retrieve_files
132 0 my ($opt_ref) = $_[-1];
133  
134 0 my @successful_transfers;
135  
136 0 my $ftp = Net::FTP::Simple->_new($opt_ref);
137  
138 0 ▶ if ($ftp->{'remote_dir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->{"remote_dir"}) 0 0 0
139  
140 0 ▶ $ftp->_conn()->cwd($ftp->{'remote_dir'})
Branch: 1 branch
BranchTrueFalseTotal
$ftp->_conn->cwd($ftp->{"remote_dir"}) or croak($ftp->_error("Error changing to remote directory", qq['$ftp->{"remote_dir"}'])) 0 0 0
141 or croak $ftp->_error("Error changing to remote directory",
142 "'$ftp->{'remote_dir'}'");
143 }
144  
145 0 ▶ if (not exists $ftp->{'files'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $ftp->{"files"}) 0 0 0
146 0 ▶ if (exists $ftp->{'file_filter'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ftp->{'file_filter'}) { } 0 0 0
147 0 $ftp->_list_and_filter(); # Populate $ftp->{'files'}
148 }
149 else {
150 # Punt if we have neither files nor a file filter
151 0 return;
152 }
153 }
154  
155 FILES_TO_TRANSFER:
156 0 for my $file (@{ $ftp->{'files'} }) {
157 0 my $basename = basename($file);
158  
159 0 ▶ unless ( $ftp->_conn()->get($file, $basename) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ftp->_conn->get($file, $basename)) 0 0 0
160 carp $ftp->_error("Error getting file '$file'")
161 0 ▶ unless ($ftp->{'quiet_mode'});
Branch: 1 branch
BranchTrueFalseTotal
unless $ftp->{"quiet_mode"} 0 0 0
162 0 next FILES_TO_TRANSFER;
163 }
164  
165 0 push @successful_transfers, $basename;
166  
167 0 ▶ if ($ftp->{'delete_after'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->{"delete_after"}) 0 0 0
168 0 ▶ $ftp->_conn()->delete($file)
Branch: 1 branch
BranchTrueFalseTotal
$ftp->_conn->delete($file) or carp($ftp->_error("Error deleting remote file '${file}'")) 0 0 0
169 or carp $ftp->_error("Error deleting remote file '$file'");
170 }
171 }
172  
173 wantarray ? return @successful_transfers
174 0 ▶ : return \@successful_transfers
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
175 ;
176  
177 }
178  
179 4 ▶sub list_files {
Subroutine list_files: called CC=4 SCAR=15.9
Pod documented
180 # Allow calls either as Net::FTP::Simple->list_files or
181 # Net::FTP::Simple::list_files
182 4 my ($opt_ref) = $_[-1];
183  
184 4 my @remote_files;
185  
186 4 my $ftp = Net::FTP::Simple->_new($opt_ref);
187  
188 4 ▶ if ($ftp->{'remote_dir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ftp->{"remote_dir"}) 0 4 4
189  
190 0 ▶ $ftp->_conn()->cwd($ftp->{'remote_dir'})
Branch: 1 branch
BranchTrueFalseTotal
$ftp->_conn->cwd($ftp->{"remote_dir"}) or croak($ftp->_error("Error changing to remote directory", qq['$ftp->{"remote_dir"}'])) 0 0 0
191 or croak $ftp->_error("Error changing to remote directory",
192 "'$ftp->{'remote_dir'}'");
193 }
194  
195 4 @remote_files = $ftp->_list_and_filter();
196  
197 wantarray ? return @remote_files
198 4 ▶ : return \@remote_files
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
199 ;
200  
201 }
202  
203 #######################################################################
204 # Private data
205 #######################################################################
206  
207 # Error messages which indicate a possibly temporary error condition
208 3 our %retryable_errors = (
209 rename => [
210 qq/The process cannot access the file because /
211 . qq/it is being used by another process/,
212 ],
213 );
214  
215 # Maximum number of times to retry an operation.
216 3 our %retry_max = (
217 default => 0,
218 rename => 3,
219 );
220  
221 # Time to wait on retry in seconds
222 3 our %retry_wait = (
223 default => 10,
224 rename => 10,
225 );
226  
227  
228 #######################################################################
229 # Private class below here
230 #######################################################################
231 #
232 # Private constructor!
233 #
234 22 ▶sub _new {
Subroutine _new: called CC=5 SCAR=16.3
235 22 my ($class, $opt_ref) = @_;
236 22 my $obj = bless $opt_ref, $class;
237  
238 # Capture which of the wrapper subs called us so we can be identified as
239 # that instead of the actual object.
240 22 $obj->_set_caller( (caller(1))[3] );
241  
242 # mmm required options
243 croak $obj->_caller(), " requires at least 'server' parameter"
244 22 ▶ unless($obj->{'server'});
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"server"} 1 21 22
245  
246 #
247 # Allow the user to pass in an object instead of creating a new instance.
248 # This allows test scripts to use a mock Net::FTP object and simulate a
249 # number of different cases.
250 #
251 21 ▶ unless ($obj->{'conn'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->{'conn'}) { } 20 1 21
252 my $ftpconn = Net::FTP->new($obj->{'server'},
253 1 ▶ Debug => $obj->{'debug_ftp'})
Branch: 1 branch
BranchTrueFalseTotal
my $ftpconn = "Net::FTP"->new($obj->{"server"}, "Debug", $obj->{"debug_ftp"}) or croak($obj->_error("Error creating Net::FTP object:", "'$Net::FTP::Simple::EVAL_ERROR'")) 0 1 1
254 or croak $obj->_error("Error creating Net::FTP object:",
255 "'$EVAL_ERROR'");
256  
257 0 $obj->_set_conn($ftpconn);
258 }
259 else {
260 20 $obj->_set_conn($obj->{'conn'});
261 }
262  
263 20 ▶ $obj->_conn()->login( @{ $obj }{ qw( username password ) } )
Branch: 1 branch
BranchTrueFalseTotal
$obj->_conn->login(@{$obj;}{"username", "password"}) or croak($obj->_error(qq[Error logging in to '$obj->{"server"}'])) 20 0 20
264 or croak $obj->_error("Error logging in to '$obj->{'server'}'");
265  
266 20 $obj->_setup_mode();
267  
268 20 return $obj;
269 }
270  
271 22 ▶sub DESTROY {
Subroutine DESTROY: called CC=3 SCAR=11.0
272 22 my ($self) = shift;
273  
274 22 ▶ if($self->_conn()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_conn) 19 3 22
275 19 ▶ $self->_conn()->quit()
Branch: 1 branch
BranchTrueFalseTotal
$self->_conn->quit or croak($self->_error("Error closing FTP connection:", "'$Net::FTP::Simple::EVAL_ERROR'")) 19 0 19
276 or croak $self->_error("Error closing FTP connection:",
277 "'$EVAL_ERROR'");
278 }
279  
280 22 $self->_set_conn(undef);
281 }
282  
283 20 ▶sub _setup_mode {
Subroutine _setup_mode: called CC=5 SCAR=21.9
284 20 my ($self) = shift;
285  
286 20 ▶ if (exists $self->{'mode'} and $self->{'mode'} eq 'ascii') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'mode'} and $self->{'mode'} eq 'ascii') { } 0 20 20
Condition33%1/3
exists $self->{"mode"} and $self->{"mode"} eq "ascii"
!ll&&!rl&&r
2000
MC/DC0%0/2
exists $self->{"mode"} and $self->{"mode"} eq "ascii"
exists $self->{"mode"} $self->{"mode"} eq "ascii"
Truth table33%1/3
A and B
A= exists $self->{"mode"}B= $self->{"mode"} eq "ascii"
ABresult
0X0
100
111
287 0 ▶ $self->_conn()->ascii()
Branch: 1 branch
BranchTrueFalseTotal
$self->_conn->ascii or croak($self->_error("Error setting transfer mode to ascii")) 0 0 0
288 or croak $self->_error('Error setting transfer mode to ascii');
289 }
290 else {
291 20 ▶ $self->_conn()->binary()
Branch: 1 branch
BranchTrueFalseTotal
$self->_conn->binary or croak($self->_error("Error setting transfer mode to binary")) 20 0 20
292 or croak $self->_error('Error setting transfer mode to binary');
293 }
294 }
295  
296 #sub _setup_connection {
297 #my ($self) = shift;
298 #
299 #}
300  
301 #######################################################################
302 # Accessors
303 #######################################################################
304 177 ▶sub _conn {
Subroutine _conn: called CC=1 SCAR=0.0
305 177 my ($self) = shift;
306 177 return $self->{'connection'};
307 }
308  
309 43 ▶sub _set_conn {
Subroutine _set_conn: called CC=1 SCAR=0.0
310 43 my ($self) = shift;
311 43 my ($conn) = @_;
312  
313 43 return $self->{'connection'} = $conn;
314 }
315  
316 5 ▶sub _caller {
Subroutine _caller: called CC=1 SCAR=0.0
317 5 my ($self) = shift;
318 5 return $self->{'caller'};
319 }
320  
321 22 ▶sub _set_caller {
Subroutine _set_caller: called CC=2 SCAR=6.9
322 22 my ($self) = shift;
323 22 my ($caller) = @_;
324  
325 # It should always be something; if _new is called directly (as it usually
326 # shouldn't be, but may be in test scripts)
327 22 ▶ $caller = 'main' unless ($caller);
Branch: 1 branch
BranchTrueFalseTotal
unless $caller 7 15 22
328  
329 22 return $self->{'caller'} = $caller;
330 }
331  
332 #
333 # _error - Format the FTP error string to include the error code.
334 #
335 2 ▶sub _error {
Subroutine _error: called CC=3 SCAR=13.6
336 2 my ($self) = shift;
337 2 my ($msg) = join(" ", @_);
338 2 my $ftp_err = q{};
339  
340 # This may be called for errors other than those from Net::FTP
341 # and there may not be a connection object
342 2 ▶ if ($self->_conn() and not $self->_conn()->ok()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_conn and not $self->_conn->ok) 0 2 2
Condition33%1/3
$self->_conn and not $self->_conn->ok
!ll&&!rl&&r
200
MC/DC0%0/2
$self->_conn and not $self->_conn->ok
$self->_conn not $self->_conn->ok
Truth table33%1/3
A and not(B)
A= $self->_connB= not $self->_conn->ok
ABresult
0X0
100
111
343 0 my $msg = $self->_conn()->message();
344 0 chomp $msg;
345  
346 0 $ftp_err = sprintf(q(: '%d %s'), $self->_conn()->code(), $msg);
347 }
348  
349 2 return sprintf(q(%s: %s%s),
350 $self->_caller(),
351 $msg,
352 $ftp_err,
353 );
354 }
355  
356  
357 0 ▶sub _create_and_cwd_remote_dir {
Subroutine _create_and_cwd_remote_dir: not called CC=5 SCAR=34.0
358 0 my ($self) = shift;
359  
360 # Try first change to the directory
361 0 ▶ unless ($self->_conn()->cwd($self->{'remote_dir'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_conn->cwd($self->{"remote_dir"})) 0 0 0
362  
363 # Give up now if user requested _not_ creating the remote
364 # directory
365 0 ▶ if ($self->{'disable_create_remote_dir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"disable_create_remote_dir"}) 0 0 0
366 0 croak $self->_error("Error changing to remote directory",
367 "'$self->{'remote_dir'}'");
368 }
369  
370 # Try to create the output path if it doesn't exist
371 0 ▶ $self->_conn()->mkdir($self->{'remote_dir'}, 1)
Branch: 1 branch
BranchTrueFalseTotal
$self->_conn->mkdir($self->{"remote_dir"}, 1) or croak($self->_error("Error making remote directory", qq['$self->{"remote_dir"}'])) 0 0 0
372 or croak $self->_error("Error making remote directory",
373 "'$self->{'remote_dir'}'");
374  
375 0 ▶ $self->_conn()->cwd($self->{'remote_dir'})
Branch: 1 branch
BranchTrueFalseTotal
$self->_conn->cwd($self->{"remote_dir"}) or croak($self->_error("Error changing to remote directory after", qq[creating '$self->{"remote_dir"}'])) 0 0 0
376 or croak $self->_error("Error changing to remote directory after",
377 "creating '$self->{'remote_dir'}'");
378 }
379  
380 }
381  
382  
383 31 ▶sub _op_retry {
Subroutine _op_retry: called CC=4 SCAR=13.9
384 31 my ($self, $op, @op_args) = @_;
385 31 my $conn = $self->_conn();
386 31 my $try_count = 1;
387  
388 31 ▶ croak ref $conn, " cannot do '$op'"
Branch: 1 branch
BranchTrueFalseTotal
unless $conn->can($op) 0 31 31
389 unless ($conn->can($op));
390  
391 OP_TRY:
392 31 ▶ while(not $conn->$op(@op_args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($conn->$op(@op_args)) 35 23 58
393 35 $try_count += 1;
394  
395 35 ▶ croak "'$op' failed after $try_count attempts"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_retryable_op($op, $try_count) 8 27 35
396 unless ( $self->_is_retryable_op($op, $try_count) );
397  
398 27 $self->_sleep_for_op($op);
399 }
400  
401 23 return $try_count;
402 }
403  
404 #
405 # Sleep for operation; returns nothing useful.
406 #
407 27 ▶sub _sleep_for_op {
Subroutine _sleep_for_op: called CC=2 SCAR=7.0
408 27 my $self = shift;
409 27 my ($op) = @_;
410  
411 my $retry_wait = exists $retry_wait{ $op } ? $retry_wait{ $op }
412 27 ▶ : $retry_wait{ 'default' }
Branch: 1 branch
BranchTrueFalseTotal
exists $Net::FTP::Simple::retry_wait{$op} ? : 27 0 27
413 ;
414  
415 27 sleep $retry_wait;
416  
417 }
418  
419 #
420 # _is_retryable_op - Tests if a failing operation is retryable,
421 # comparing both the error message and the retry count.
422 #
423 35 ▶sub _is_retryable_op {
Subroutine _is_retryable_op: called CC=6 SCAR=18.5
424 35 my $self = shift;
425 35 my ($op, $count) = @_;
426  
427 35 my $caller_error_message = $self->_conn()->message();
428  
429 my $retry_max = exists $retry_max{ $op } ? $retry_max{ $op }
430 35 ▶ : $retry_max{ 'default' }
Branch: 1 branch
BranchTrueFalseTotal
exists $Net::FTP::Simple::retry_max{$op} ? : 35 0 35
431 ;
432  
433 35 ▶ return unless (exists $retryable_errors{ $op });
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Net::FTP::Simple::retryable_errors{$op} 0 35 35
434 35 ▶ return if ($count > $retry_max);
Branch: 1 branch
BranchTrueFalseTotal
if $count > $retry_max 8 27 35
435  
436 27 for my $msg (@{ $retryable_errors{ $op } }) {
437 27 ▶ if ($caller_error_message =~ m/$msg/ms) { # No 'x'!
Branch: 1 branch
BranchTrueFalseTotal
if ($caller_error_message =~ /$msg/ms) 27 0 27
438 27 return 1;
439 }
440 }
441  
442 # False if we fall through the loop
443 0 return;
444 }
445  
446 # Assume everything else is set up
447 14 ▶sub _list_and_filter {
Subroutine _list_and_filter: called CC=8 SCAR=20.8
448 14 my ($self) = shift;
449  
450 14 ▶ my $filter = $self->{'file_filter'} || qr/./xms;
Condition100%2/2
$self->{'file_filter'} || qr/./msx
l!l
59
MC/DC100%1/1
$self->{'file_filter'} || qr/./msx
$self->{'file_filter'}
Truth table100%2/2
A
A= $self->{'file_filter'}
Aresult
11
00
451 14 my @remote_list;
452 my @remote_files;
453  
454 # FIXME I need to figure out how to distinguish between an empty list (no
455 # files in the directory) and an error. Hopefully, if the directory
456 # permissions are such that the directory cannot be listed, the cwd will
457 # also fail (assuming one is done prior to this :\). Of course, it's
458 # possible to have +x-r, but for now, just hope for the best :)
459 14 ▶ return unless (@remote_list = $self->_conn()->dir());
Branch: 1 branch
BranchTrueFalseTotal
unless @remote_list = $self->_conn->dir 4 10 14
460  
461 REMOTE_LIST:
462 10 for my $entry (@remote_list) {
463 52 chomp $entry;
464  
465 # This correctly splits a line where the filename has spaces; the '9'
466 # collects the 9th field and everything after into one item
467 52 my ($mode, $filename) = (split /\s+/, $entry, 9)[0,-1];
468  
469 # Skip non-file things
470 52 ▶ next REMOTE_LIST unless ($mode && $mode =~ /\A-/xms);
Branch: 1 branch
BranchTrueFalseTotal
unless $mode and $mode =~ /\A-/msx 30 22 52
Condition66%2/3
$mode and $mode =~ /\A-/msx
!ll&&!rl&&r
03022
MC/DC50%1/2
$mode and $mode =~ /\A-/msx
$mode $mode =~ /\A-/msx
Truth table66%2/3
A and B
A= $modeB= $mode =~ /\A-/msx
ABresult
0X0
100
111
471  
472 # Skip files not matching the filter
473 22 ▶ next REMOTE_LIST unless ($filename =~ m/$filter/xms);
Branch: 1 branch
BranchTrueFalseTotal
unless $filename =~ /$filter/msx 3 19 22
474  
475 19 push @remote_files, $filename;
476 }
477  
478 10 push @{ $self->{'files'} }, @remote_files;
479  
480 wantarray ? return @remote_files
481 10 ▶ : return \@remote_files
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 4 10
482 ;
483 }
484  
485  
486  
487 3 1;
488  
489 __END__
↑ Summary