Find/Mixin.pm

filter: Statementstmt 15.7% 39 / 247 Branchbran 0.0% 0 / 176 Conditioncond 2.5% 1 / 39 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 52.3% 11 / 21 Podpod 0.0% 0 / 5 totaltotal 9.9% 51 / 513 CC 109 SCAR 69.6
CC
109
Cov
9%
recursive
2520.5
find
182.0
_data_command
156.0
CRAP 1058.0
↑ Summary Find.pm »
1 package Net::FTP::Find::Mixin;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.041';
7  
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Time::Local qw(timegm);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Net::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Listing;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 my @month_name_list = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
16  
17 1 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
18 1 my $class = shift;
19 1 ▶ my $pkg = shift || 'Net::FTP';
Condition50%1/2
shift() || 'Net::FTP'
l!l
10
MC/DC0%0/1
shift() || 'Net::FTP'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
20  
21 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 *{$pkg . '::find'} = \&find;
23 1 *{$pkg . '::finddepth'} = \&finddepth;
24 }
25  
26 0 ▶sub finddepth {
Subroutine finddepth: not called CC=4 SCAR=30.0
Pod undocumented
27 0 my $self = shift;
28 0 my ($opts, @directories) = @_;
29  
30 0 my %options = (
31 bydepth => 1,
32 );
33  
34 0 ▶ if (ref $opts eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $opts eq 'CODE') { } 0 0 0
elsif (ref $opts eq 'HASH') { } 0 0 0
35 0 $options{'wanted'} = $opts;
36 }
37 elsif (ref $opts eq 'HASH') {
38 0 ▶ while (my ($k, $v) = each(%$opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$opts) 0 0 0
39 0 $options{$k} = $v;
40 }
41 }
42  
43 0 &find($self, \%options, @directories);
44 }
45  
46 0 ▶sub find {
Subroutine find: not called CC=13 SCAR=52.0
Pod undocumented
47 0 my $self = shift;
48 0 my ($opts, @directories) = @_;
49  
50 0 my %options = (
51 use_mlsd => 1,
52 );
53  
54 0 ▶ if (ref $opts eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $opts eq 'CODE') { } 0 0 0
elsif (ref $opts eq 'HASH') { } 0 0 0
55 0 $options{'wanted'} = $opts;
56 }
57 elsif (ref $opts eq 'HASH') {
58 0 ▶ while (my ($k, $v) = each(%$opts)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$opts) 0 0 0
59 0 $options{$k} = $v;
60 }
61 }
62  
63 0 ▶ if (! $options{'wanted'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"wanted"}) 0 0 0
64 0 croak('no &wanted subroutine given');
65 }
66  
67 0 ▶ if ( !$options{'fstype'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($options{"fstype"}) 0 0 0
68 0 $options{'fstype'} = 'unix';
69 0 my $res = _command( $self, 'SYST' );
70 0 ▶ if ( $res->[0] == CMD_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[0] == 2) 0 0 0
71 0 ▶ if ( $res->[1] =~ m/windows/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->[1] =~ /windows/i) 0 0 0
72 0 $options{'fstype'} = 'dosftp';
73 }
74 }
75 }
76  
77 0 ▶ defined(my $cwd = $self->pwd)
Branch: 1 branch
BranchTrueFalseTotal
defined(my $cwd = $self->pwd) or return 0 0 0
78 or return;
79 0 ▶ $cwd =~ s{/*\z}{/} if $cwd;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd 0 0 0
80  
81 0 foreach my $d (@directories) {
82 0 ▶ &recursive( $self, $d =~ m!\A/! ? '' : $cwd, \%options, $d, 0 )
Branch: 2 branches
BranchTrueFalseTotal
&recursive($self, $d =~ m[\A/] ? "" : $cwd, \%options, $d, 0) or return 0 0 0
$d =~ m[\A/] ? : 0 0 0
83 or return;
84 }
85  
86 0 1;
87 }
88  
89 0 ▶sub recursive {
Subroutine recursive: not called CC=51 SCAR=78.3
Pod undocumented
90 0 my $self = shift;
91 0 my ($cwd, $opts, $directory, $depth) = @_;
92  
93 our (
94 0 $name, $dir,
95 $is_directory, $is_symlink, $mode,
96 $permissions, $link, $user, $group, $size, $month, $mday, $year_or_time,
97 $type, $ballpark_mtime,
98 $unix_like_system_size, $unix_like_system_name,
99 $mlsd_facts, $mtime,
100 );
101  
102 return 1
103 0 ▶ if (defined($opts->{'max_depth'}) && $depth > $opts->{'max_depth'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{"max_depth"} and $depth > $opts->{"max_depth"} 0 0 0
Condition0%0/3
defined $opts->{"max_depth"} and $depth > $opts->{"max_depth"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts->{"max_depth"} and $depth > $opts->{"max_depth"}
defined $opts->{"max_depth"} $depth > $opts->{"max_depth"}
Truth table0%0/3
A and B
A= defined $opts->{"max_depth"}B= $depth > $opts->{"max_depth"}
ABresult
0X0
100
111
104  
105 0 local $dir;
106 0 my $orig_cwd = undef;
107 0 my $entries;
108 0 ▶ if ($opts->{'no_chdir'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'no_chdir'}) { } 0 0 0
109 0 ▶ $entries
Branch: 1 branch
BranchTrueFalseTotal
$entries = _dir_entries($self, $opts, $directory, undef, undef, undef, $depth == 0) or return 0 0 0
110 = _dir_entries( $self, $opts, $directory, undef, undef, undef,
111 $depth == 0 )
112 or return;
113 0 ▶ return 1 unless @$entries;
Branch: 1 branch
BranchTrueFalseTotal
unless @$entries 0 0 0
114  
115 0 ▶ if ($depth == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0) 0 0 0
116 0 ▶ if (! grep {$_->{data}[0] eq '.'} @$entries) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"data"}[0] eq ".";} @$entries) 0 0 0
117 0 ▶ build_start_dir( $self, $opts, $entries, $directory,
Branch: 1 branch
BranchTrueFalseTotal
build_start_dir($self, $opts, $entries, $directory, dirname($directory)) or return 0 0 0
118 dirname($directory) )
119 or return;
120 }
121 }
122  
123 0 $dir = $directory;
124 }
125 else {
126 0 ▶ defined($orig_cwd = $self->pwd)
Branch: 1 branch
BranchTrueFalseTotal
defined($orig_cwd = $self->pwd) or return 0 0 0
127 or return;
128 0 ▶ if ($orig_cwd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($orig_cwd) 0 0 0
129 0 $orig_cwd =~ s{^/*}{/};
130 }
131  
132 0 ▶ $self->cwd($directory)
Branch: 1 branch
BranchTrueFalseTotal
$self->cwd($directory) or return 0 0 0
133 or return;
134 0 ▶ $entries
Branch: 1 branch
BranchTrueFalseTotal
$entries = _dir_entries($self, $opts, ".", undef, undef, undef, $depth == 0) or return 0 0 0
135 = _dir_entries( $self, $opts, '.', undef, undef, undef,
136 $depth == 0 )
137 or return;
138  
139 0 ▶ defined($dir = $self->pwd)
Branch: 1 branch
BranchTrueFalseTotal
defined($Net::FTP::Find::Mixin::dir = $self->pwd) or return 0 0 0
140 or return;
141 0 ▶ if ($dir) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::FTP::Find::Mixin::dir) { } 0 0 0
elsif (defined $Net::FTP::Find::Mixin::dir) { } 0 0 0
142 0 $dir =~ s{^/*}{/};
143 }
144 elsif (defined($dir)) {
145 0 $dir = $directory;
146 }
147  
148 0 ▶ if ($depth == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0) 0 0 0
149 0 ▶ if (! grep {$_->{data}[0] eq '.'} @$entries) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_->{"data"}[0] eq ".";} @$entries) 0 0 0
150 0 ▶ $self->cwd('..')
Branch: 1 branch
BranchTrueFalseTotal
$self->cwd("..") or return 0 0 0
151 or return;
152 0 ▶ build_start_dir($self, $opts, $entries, $directory, '.')
Branch: 1 branch
BranchTrueFalseTotal
build_start_dir($self, $opts, $entries, $directory, ".") or return 0 0 0
153 or return;
154 }
155  
156 0 ▶ $self->cwd($orig_cwd)
Branch: 1 branch
BranchTrueFalseTotal
$self->cwd($orig_cwd) or return 0 0 0
157 or return;
158 }
159  
160 0 ▶ if ( !@$entries ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@$entries) 0 0 0
161 0 ▶ $self->cwd($orig_cwd)
Branch: 1 branch
BranchTrueFalseTotal
$self->cwd($orig_cwd) or return 0 0 0
162 or return;
163 0 return 1;
164 }
165 }
166  
167 0 my @dirs = ();
168 0 foreach my $e (@$entries) {
169 local (
170 $permissions, $link, $user, $group, $unix_like_system_size, $month, $mday, $year_or_time, $unix_like_system_name
171 0 ) = split(/\s+/, $e->{line}, 9);
172 local (
173 $_, $type, $size, $ballpark_mtime, $mode
174 0 ) = @{ $e->{data} };
175 0 ▶ local $mlsd_facts = $e->{mlsd_facts} || undef;
Condition0%0/2
$e->{'mlsd_facts'} || undef
l!l
00
MC/DC0%0/1
$e->{'mlsd_facts'} || undef
$e->{'mlsd_facts'}
Truth table0%0/2
A
A= $e->{'mlsd_facts'}
Aresult
11
00
176  
177 0 ▶ next if $_ eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq ".." 0 0 0
178 0 ▶ next if $_ eq '.' && $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "." and $depth != 0 0 0 0
Condition0%0/3
$_ eq "." and $depth != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$_ eq "." and $depth != 0
$_ eq "." $depth != 0
Truth table0%0/3
A and B
A= $_ eq "."B= $depth != 0
ABresult
0X0
100
111
179  
180 0 ▶ if ($depth == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($depth == 0) 0 0 0
181 0 ▶ next if $_ ne '.';
Branch: 1 branch
BranchTrueFalseTotal
if $_ ne "." 0 0 0
182 0 $_ = $directory;
183 }
184  
185 0 ▶ local $name = $depth == 0 ? $_ : File::Spec->catfile($dir, $_);
Branch: 1 branch
BranchTrueFalseTotal
$depth == 0 ? : 0 0 0
186 0 ▶ $_ = $name if $opts->{'no_chdir'} && $depth != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_chdir"} and $depth != 0 0 0 0
Condition0%0/3
$opts->{"no_chdir"} and $depth != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"no_chdir"} and $depth != 0
$opts->{"no_chdir"} $depth != 0
Truth table0%0/3
A and B
A= $opts->{"no_chdir"}B= $depth != 0
ABresult
0X0
100
111
187 0 my $next = $_;
188  
189 0 ▶ $name =~ s/$cwd// if $cwd;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd 0 0 0
190 0 ▶ $dir =~ s/$cwd// if $cwd;
Branch: 1 branch
BranchTrueFalseTotal
if $cwd 0 0 0
191  
192 0 local $is_directory = $type eq 'd';
193 0 local $is_symlink = substr($type, 0, 1) eq 'l';
194  
195 0 local $mtime;
196 0 ▶ if ($mlsd_facts) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Net::FTP::Find::Mixin::mlsd_facts) { } 0 0 0
elsif ($Net::FTP::Find::Mixin::type eq 'f' and $opts->{'fetch_mtime'}) { } 0 0 0
197 0 $mtime = $ballpark_mtime;
198 }
199 ▶ elsif ($type eq 'f' && $opts->{fetch_mtime}) {
Condition0%0/3
$Net::FTP::Find::Mixin::type eq "f" and $opts->{"fetch_mtime"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Find::Mixin::type eq "f" and $opts->{"fetch_mtime"}
$Net::FTP::Find::Mixin::type eq "f" $opts->{"fetch_mtime"}
Truth table0%0/3
A and B
A= $Net::FTP::Find::Mixin::type eq "f"B= $opts->{"fetch_mtime"}
ABresult
0X0
100
111
200 0 $mtime = _mdtm_gmt($self, $_);
201 }
202  
203 0 ▶ if ($is_directory && $opts->{'bydepth'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Find::Mixin::is_directory and $opts->{"bydepth"}) 0 0 0
Condition0%0/3
$Net::FTP::Find::Mixin::is_directory and $opts->{"bydepth"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Find::Mixin::is_directory and $opts->{"bydepth"}
$Net::FTP::Find::Mixin::is_directory $opts->{"bydepth"}
Truth table0%0/3
A and B
A= $Net::FTP::Find::Mixin::is_directoryB= $opts->{"bydepth"}
ABresult
0X0
100
111
204 0 ▶ &recursive($self, $cwd, $opts, $next, $depth+1)
Branch: 1 branch
BranchTrueFalseTotal
&recursive($self, $cwd, $opts, $next, $depth + 1) or return 0 0 0
205 or return;
206 }
207  
208 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts->{"min_depth"} or $depth > $opts->{"min_depth"}) 0 0 0
Condition0%0/3
not defined $opts->{"min_depth"} or $depth > $opts->{"min_depth"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $opts->{"min_depth"} or $depth > $opts->{"min_depth"}
not defined $opts->{"min_depth"} $depth > $opts->{"min_depth"}
Truth table0%0/3
not(A) or B
A= not defined $opts->{"min_depth"}B= $depth > $opts->{"min_depth"}
ABresult
1X1
011
000
209 (! defined($opts->{'min_depth'}))
210 || ($depth > $opts->{'min_depth'})
211 ) {
212 0 ▶ local $_ = '.' if (! $opts->{'no_chdir'}) && $depth == 0;
Branch: 1 branch
BranchTrueFalseTotal
if not $opts->{"no_chdir"} and $depth == 0 0 0 0
Condition0%0/3
not $opts->{"no_chdir"} and $depth == 0
!ll&&!rl&&r
000
MC/DC0%0/2
not $opts->{"no_chdir"} and $depth == 0
not $opts->{"no_chdir"} $depth == 0
Truth table0%0/3
not(A) and B
A= not $opts->{"no_chdir"}B= $depth == 0
ABresult
0X0
100
111
213  
214 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
215 0 foreach my $k (qw(
216 name dir is_directory is_symlink mode
217 permissions link user group size month mday year_or_time
218 type ballpark_mtime mtime mlsd_facts
219 )) {
220 0 ${'Net::FTP::Find::'.$k} = $$k;
221 }
222  
223 0 $opts->{'wanted'}($self);
224 }
225  
226 0 ▶ if ($is_directory && ! $opts->{'bydepth'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::FTP::Find::Mixin::is_directory and not $opts->{"bydepth"}) 0 0 0
Condition0%0/3
$Net::FTP::Find::Mixin::is_directory and not $opts->{"bydepth"}
!ll&&!rl&&r
000
MC/DC0%0/2
$Net::FTP::Find::Mixin::is_directory and not $opts->{"bydepth"}
$Net::FTP::Find::Mixin::is_directory not $opts->{"bydepth"}
Truth table0%0/3
A and not(B)
A= $Net::FTP::Find::Mixin::is_directoryB= not $opts->{"bydepth"}
ABresult
0X0
100
111
227 0 ▶ &recursive($self, $cwd, $opts, $next, $depth+1)
Branch: 1 branch
BranchTrueFalseTotal
&recursive($self, $cwd, $opts, $next, $depth + 1) or return 0 0 0
228 or return;
229 }
230 }
231  
232 0 ▶ if ($orig_cwd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($orig_cwd) 0 0 0
233 0 ▶ $self->cwd($orig_cwd)
Branch: 1 branch
BranchTrueFalseTotal
$self->cwd($orig_cwd) or return 0 0 0
234 or return;
235 }
236  
237 0 1;
238 }
239  
240 0 ▶sub build_start_dir {
Subroutine build_start_dir: not called CC=8 SCAR=42.8
Pod undocumented
241 0 my ($self, $opts, $entries, $current, $parent) = @_;
242  
243 0 my $detected = 0;
244 0 ▶ if ($current ne '/') {
Branch: 1 branch
BranchTrueFalseTotal
if ($current ne "/") 0 0 0
245 0 ▶ my $parent_entries = _dir_entries( $self, $opts, $parent )
Branch: 1 branch
BranchTrueFalseTotal
my $parent_entries = _dir_entries($self, $opts, $parent) or return 0 0 0
246 or return;
247 0 my $basename = basename($current);
248  
249 0 for my $e (@$parent_entries) {
250 0 ▶ next if $e->{data}[0] ne $basename;
Branch: 1 branch
BranchTrueFalseTotal
if $e->{"data"}[0] ne $basename 0 0 0
251  
252 0 $detected = 1;
253 0 $e->{line} =~ s/$basename$/./g;
254 0 $e->{data}[0] = '.';
255 0 splice @$entries, 0, scalar(@$entries), $e;
256 }
257 }
258  
259 0 ▶ if (! $detected) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($detected) 0 0 0
260 0 my ($year, $month, $mday, $hour, $min) = (localtime)[5,4,3,2,1];
261 0 my $line;
262 0 ▶ if ($opts->{'fstype'} eq 'dosftp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'fstype'} eq 'dosftp') { } 0 0 0
263 0 ▶ $line = join(
Branch: 1 branch
BranchTrueFalseTotal
$hour < 12 ? : 0 0 0
264 ' ',
265 sprintf( '%02d-%02d-%d',
266 $month + 1, $mday, substr( $year + 1900, 2 ) ),
267 ( $hour < 12
268 ? sprintf( '%02d:%02dAM', $hour, $min )
269 : sprintf( '%02d:%02dPM', $hour - 12, $min )
270 ),
271 '<DIR>', '.'
272 );
273 }
274 else {
275 0 $line = join(' ',
276 'drwxr-xr-x',
277 scalar(@$entries)+2,
278 '-',
279 '-',
280 0,
281 $month_name_list[$month],
282 sprintf('%02d', $mday),
283 sprintf('%02d:%02d', $hour, $min),
284 '.'
285 );
286 }
287 0 my ($e) = parse_entries([$line], undef, undef, undef, 1);
288 0 splice @$entries, 0, scalar(@$entries), $e;
289 }
290  
291 0 1;
292 }
293  
294 0 ▶sub _list {
Subroutine _list: not called CC=3 SCAR=24.8
295 0 my $self = shift;
296  
297 0 ▶ if ( $self->isa('Net::FTPSSL') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('Net::FTPSSL')) { } 0 0 0
298 0 my @entries = $self->list(@_);
299 0 ▶ if ( $self->last_status_code != CMD_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->last_status_code != 2) { } 0 0 0
300 0 return;
301 }
302 else {
303 0 [@entries];
304 }
305 }
306 else {
307 0 $self->dir(@_);
308 }
309 }
310  
311 0 ▶sub _command {
Subroutine _command: not called CC=2 SCAR=17.9
312 0 my $self = shift;
313  
314 0 ▶ if ( $self->isa('Net::FTPSSL') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('Net::FTPSSL')) { } 0 0 0
315 0 my $status = $self->command(@_)->response;
316 0 return [$status, $self->last_message];
317 }
318 else {
319 0 my $status = $self->cmd(@_);
320 0 return [$status, $self->message];
321 }
322 }
323  
324 0 ▶sub _data_command {
Subroutine _data_command: not called CC=12 SCAR=50.5
325 0 my $self = shift;
326  
327 0 my $res = '';
328 0 ▶ if ( $self->isa('Net::FTPSSL') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('Net::FTPSSL')) { } 0 0 0
329 0 ▶ unless ( $self->prep_data_channel ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->prep_data_channel) 0 0 0
330 0 return;
331 }
332  
333 0 ▶ if ( $self->command(@_)->response != CMD_INFO ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->command(@_)->response != 1) 0 0 0
334 0 $self->_croak_or_return;
335 0 return;
336 }
337  
338 0 my ( $tmp, $io, $size );
339  
340 0 $size = ${*$self}{buf_size};
341  
342 0 $io = $self->_get_data_channel;
343 0 ▶ unless ( defined $io ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $io) 0 0 0
344 0 return;
345 }
346  
347 0 ▶ while ( my $len = sysread $io, $tmp, $size ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = sysread($io, $tmp, $size)) 0 0 0
348 0 ▶ unless ( defined $len ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $len) 0 0 0
349 0 ▶ next if $! == Net::FTPSSL::EINTR();
Branch: 1 branch
BranchTrueFalseTotal
if $! == Net::FTPSSL::EINTR() 0 0 0
350 0 $self->_croak_or_return;
351 0 $io->close;
352 0 return;
353 }
354 0 $res .= $tmp;
355 }
356  
357 0 $io->close;
358  
359 0 ▶ if ( $self->response() != CMD_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->response != 2) 0 0 0
360 0 $self->_croak_or_return;
361 0 return;
362 }
363 }
364 else {
365 0 ▶ my $data = $self->_data_cmd(@_)
Branch: 1 branch
BranchTrueFalseTotal
my $data = $self->_data_cmd(@_) or return 0 0 0
366 or return;
367 0 my $buf;
368 0 my $size = ${*$self}{'net_ftp_blksize'};
369 0 ▶ while ( $data->read( $buf, $size ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->read($buf, $size)) 0 0 0
370 0 $res .= $buf;
371 }
372 $data->close
373 0 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
$data->close or return 0 0 0
374 }
375  
376 0 $res;
377 }
378  
379 0 ▶sub _mdtm_gmt {
Subroutine _mdtm_gmt: not called CC=2 SCAR=17.9
380 0 my $self = shift;
381  
382 0 ▶ if ( $self->isa('Net::FTPSSL') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('Net::FTPSSL')) { } 0 0 0
383 0 $self->_mdtm(@_);
384 }
385 else {
386 0 $self->mdtm(@_);
387 }
388 }
389  
390 0 ▶sub _dir_entries {
Subroutine _dir_entries: not called CC=12 SCAR=50.5
391 0 my $self = shift;
392 0 my ($opts, $directory, $tz, $fstype, $error, $preserve_current) = @_;
393  
394 0 ▶ if ($directory ne '.' && $directory ne '..') {
Branch: 1 branch
BranchTrueFalseTotal
if ($directory ne "." and $directory ne "..") 0 0 0
Condition0%0/3
$directory ne "." and $directory ne ".."
!ll&&!rl&&r
000
MC/DC0%0/2
$directory ne "." and $directory ne ".."
$directory ne "." $directory ne ".."
Truth table0%0/3
A and B
A= $directory ne "."B= $directory ne ".."
ABresult
0X0
100
111
395 0 $directory =~ s{/*\z}{/};
396 }
397  
398 0 ▶ if ( $opts->{use_mlsd}
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'use_mlsd'} and defined(my $res = _data_command($self, 'MLSD', $directory))) { } 0 0 0
Condition0%0/3
$opts->{"use_mlsd"} and defined(my $res = _data_command($self, "MLSD", $directory))
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->{"use_mlsd"} and defined(my $res = _data_command($self, "MLSD", $directory))
$opts->{"use_mlsd"} defined(my $res = _data_command($self, "MLSD", $directory))
Truth table0%0/3
A and B
A= $opts->{"use_mlsd"}B= defined(my $res = _data_command($self, "MLSD", $directory))
ABresult
0X0
100
111
399 && defined( my $res = _data_command( $self, 'MLSD', $directory ) ) )
400 {
401 my @entries = map {
402 0 (my $line = $_) =~ s/(\r\n|\r|\n)\z//;
403  
404 0 my %data;
405 0 my ( $facts, $name ) = split ' ', $line, 2;
406 0 for my $i ( split ';', $facts ) {
407 0 my ( $k, $v ) = split '=', $i, 2;
408 0 $data{lc $k} = $v;
409 }
410  
411 $data{modify}
412 0 =~ /((\d\d)(\d\d\d?))(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/;
413 0 ▶ my $modify = timegm( $8, $7, $6, $5, $4 - 1,
Branch: 1 branch
BranchTrueFalseTotal
$2 eq '19' ? : 0 0 0
414 $2 eq '19' ? $3 : ( $1 - 1900 ) );
415  
416 +{ line => '',
417 data => [
418 $name,
419 ( $data{type} =~ m/dir\z/ ? 'd'
420 : $data{type} =~ m/link/ ? 'l'
421 : 'f'
422 ),
423 $data{size} || 0,
424 $modify,
425 0 ▶ $data{'UNIX.mode'}
Branch: 2 branches
BranchTrueFalseTotal
$data{'type'} =~ /dir\z/ ? : 0 0 0
$data{'type'} =~ /link/ ? : 0 0 0
Condition0%0/2
$data{'size'} || 0
l!l
00
MC/DC0%0/1
$data{'size'} || 0
$data{'size'}
Truth table0%0/2
A
A= $data{'size'}
Aresult
11
00
426 ],
427 mlsd_facts => \%data,
428 };
429 } split( /\n/, $res );
430  
431 0 ▶ return wantarray ? @entries : \@entries;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
432 }
433 else {
434 0 $opts->{use_mlsd} = 0;
435 }
436  
437 0 ▶ my $list = _list($self, $directory)
Branch: 1 branch
BranchTrueFalseTotal
my $list = _list($self, $directory) or return 0 0 0
438 or return;
439 0 parse_entries( $list, $tz, $fstype, $error, $preserve_current );
440 }
441  
442 0 ▶sub parse_entries {
Subroutine parse_entries: not called CC=10 SCAR=47.0
Pod undocumented
443 0 my($dir, $tz, $fstype, $error, $preserve_current) = @_;
444  
445 0 ▶ return unless $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 0 0 0
446  
447 0 ▶ if ($preserve_current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preserve_current) 0 0 0
448 $dir = [ map {
449 0 my $e = $_;
450 0 $e =~ s/(\s\S*)d(?=\S*\z)/$1dd/g;
451 0 $e =~ s/(?<=\s)\.\z/d./g;
452 0 $e;
453 } @$dir ];
454 }
455  
456 my @parsed = map {
457 0 my ($data) = File::Listing::parse_dir($_, $tz, $fstype, $error);
458 0 ▶ $data ? +{ line => $_, data => $data } : ()
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
459 } @$dir;
460  
461 0 ▶ if (@$dir && ! @parsed) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$dir and not @parsed) 0 0 0
Condition0%0/3
@$dir and not @parsed
!ll&&!rl&&r
000
MC/DC0%0/2
@$dir and not @parsed
@$dir not @parsed
Truth table0%0/3
A and not(B)
A= @$dirB= not @parsed
ABresult
0X0
100
111
462 # Fallback
463 @parsed = map {
464 0 my $l = $_;
465 0 $l =~ s/
466 (\s\d+\s+)
467 (\d+)\S*
468 (?=\s+\d+\s+(\d{2}:\d{2}|\d{4}))
469 0 /$1 . $month_name_list[$2-1]/ex;
470 0 my ($data) = File::Listing::parse_dir($l, $tz, $fstype, $error);
471 0 ▶ $data ? +{ line => $_, data => $data } : ()
Branch: 1 branch
BranchTrueFalseTotal
$data ? : 0 0 0
472 } @$dir;
473 }
474  
475 0 ▶ if ($preserve_current) {
Branch: 1 branch
BranchTrueFalseTotal
if ($preserve_current) 0 0 0
476 0 for (@parsed) {
477 0 $_->{data}[0] =~ s/dd/d/;
478 0 $_->{data}[0] =~ s/d\././g;
479 }
480 }
481  
482 0 ▶ wantarray ? @parsed : \@parsed;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
483 }
484  
485 1 1;
486 __END__
↑ Summary Find.pm »