line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FTP::Path::Iter::Dir; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Class representing a Directory |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
24
|
use 5.010; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
365
|
use experimental 'switch'; |
|
1
|
|
|
|
|
2959
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
181
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
58
|
|
13
|
1
|
|
|
1
|
|
6
|
use Fcntl qw[ :mode ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
262
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use File::Spec::Functions qw[ catdir catfile ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
373
|
use namespace::clean; |
|
1
|
|
|
|
|
11087
|
|
|
1
|
|
|
|
|
6
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
716
|
use parent 'Net::FTP::Path::Iter::Entry'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
9
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
364
|
use Net::FTP::Path::Iter::File; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
27
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use constant is_file => 0; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
24
|
1
|
|
|
1
|
|
4
|
use constant is_dir => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
545
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _children { |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
5
|
|
8
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
78
|
my %attr = ( server => $self->server, ); |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
85
|
my $entries = $self->_get_entries( $self->path ); |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
16
|
my @children; |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
23
|
for my $entry ( @$entries ) { |
37
|
|
|
|
|
|
|
|
38
|
13
|
|
|
|
|
27
|
my $obj; |
39
|
|
|
|
|
|
|
|
40
|
13
|
|
|
|
|
34
|
for ( $entry->{type} ) { |
41
|
|
|
|
|
|
|
|
42
|
13
|
|
|
|
|
30
|
when ( 'd' ) { |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$obj = Net::FTP::Path::Iter::Dir->new( %$entry, %attr, |
45
|
4
|
|
|
|
|
169
|
path => catdir( $self->path, $entry->{name} ) ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
9
|
|
|
|
|
30
|
when ( 'f' ) { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$obj = Net::FTP::Path::Iter::File->new( %$entry, %attr, |
51
|
9
|
|
|
|
|
323
|
path => catfile( $self->path, $entry->{name} ) ); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
default { |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
0
|
warn( "ignoring $entry->{name}; unknown type $_\n" ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
13
|
|
|
|
|
215
|
push @children, $obj; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
44
|
return @children; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# if an entity doesn't have attributes, it didn't get loaded |
69
|
|
|
|
|
|
|
# from a directory listing. Try to get one. This should |
70
|
|
|
|
|
|
|
# happen rarely, so do this slowly but correctly. |
71
|
|
|
|
|
|
|
sub _retrieve_attrs { |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
1
|
|
47
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
1
|
50
|
|
|
|
15
|
return if $self->_has_attrs; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
23
|
my $server = $self->server; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
24
|
my $pwd = $server->pwd; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
104
|
my $entry = {}; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
21
|
$server->cwd( $self->path ) |
84
|
|
|
|
|
|
|
or croak( "unable to chdir to ", $self->path, "\n" ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# File::Listing doesn't return . or .. (and some FTP servers |
87
|
|
|
|
|
|
|
# don't return that info anyway), so try to go up a dir and |
88
|
|
|
|
|
|
|
# look for the name |
89
|
1
|
|
|
|
|
150
|
eval { |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# cdup sometimes returns ok even if it didn't work |
92
|
1
|
|
|
|
|
18
|
$server->cdup; |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
153
|
if ( $pwd ne $server->pwd ) { |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
my $entries = $self->_get_entries( '.' ); |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
0
|
( $entry ) = grep { $self->name eq $_->{name} } @$entries; |
|
0
|
|
|
|
|
0
|
|
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
croak( "unable to find attributes for ", $self->path, "\n" ) |
101
|
|
|
|
|
|
|
if !$entry; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
croak( $self->path, ": expected directory, got $entry->{type}\n" ) |
104
|
0
|
0
|
|
|
|
0
|
unless $entry->{type} eq 'd'; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# couldn't go up a directory; at the top? |
109
|
|
|
|
|
|
|
else { |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# fake it. |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
101
|
$entry = { |
114
|
|
|
|
|
|
|
size => 0, |
115
|
|
|
|
|
|
|
mtime => 0, |
116
|
|
|
|
|
|
|
mode => S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH |
117
|
|
|
|
|
|
|
| S_IXOTH, |
118
|
|
|
|
|
|
|
type => 'd', |
119
|
|
|
|
|
|
|
_has_attrs => 1, |
120
|
|
|
|
|
|
|
}; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
}; |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
6
|
my $err = $@; |
127
|
|
|
|
|
|
|
|
128
|
1
|
50
|
|
|
|
6
|
$server->cwd( $pwd ) |
129
|
|
|
|
|
|
|
or croak( "unable to return to directory: $pwd\n" ); |
130
|
|
|
|
|
|
|
|
131
|
1
|
50
|
|
|
|
129
|
croak( $err ) if $err; |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
25
|
$self->$_( $entry->{$_} ) for keys %$entry; |
134
|
1
|
|
|
|
|
86
|
return; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# |
138
|
|
|
|
|
|
|
# This file is part of Net-FTP-Path-Iter |
139
|
|
|
|
|
|
|
# |
140
|
|
|
|
|
|
|
# This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. |
141
|
|
|
|
|
|
|
# |
142
|
|
|
|
|
|
|
# This is free software, licensed under: |
143
|
|
|
|
|
|
|
# |
144
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
__END__ |