line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FTP::Path::Iter; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Iterative, recursive, FTP file finder |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
189670
|
use 5.010; |
|
1
|
|
|
|
|
5
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
27
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
9
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
59
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
475
|
use Net::FTP; |
|
1
|
|
|
|
|
78985
|
|
|
1
|
|
|
|
|
61
|
|
14
|
1
|
|
|
1
|
|
492
|
use File::Spec::Functions qw[ splitpath ]; |
|
1
|
|
|
|
|
659
|
|
|
1
|
|
|
|
|
59
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
338
|
use parent 'Path::Iterator::Rule'; |
|
1
|
|
|
|
|
204
|
|
|
1
|
|
|
|
|
5
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
11864
|
use Net::FTP::Path::Iter::Dir; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
32
|
|
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
7
|
use namespace::clean; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#pod =method new |
23
|
|
|
|
|
|
|
#pod |
24
|
|
|
|
|
|
|
#pod $ftp = Net::FTP::Path::Iter->new( [$host], %options ); |
25
|
|
|
|
|
|
|
#pod |
26
|
|
|
|
|
|
|
#pod Open up a connection to an FTP host and log in. The arguments |
27
|
|
|
|
|
|
|
#pod are the same as for L, with the addition of two |
28
|
|
|
|
|
|
|
#pod mandatory options, |
29
|
|
|
|
|
|
|
#pod |
30
|
|
|
|
|
|
|
#pod =over |
31
|
|
|
|
|
|
|
#pod |
32
|
|
|
|
|
|
|
#pod =item C |
33
|
|
|
|
|
|
|
#pod |
34
|
|
|
|
|
|
|
#pod The user name |
35
|
|
|
|
|
|
|
#pod |
36
|
|
|
|
|
|
|
#pod =item C |
37
|
|
|
|
|
|
|
#pod |
38
|
|
|
|
|
|
|
#pod The password |
39
|
|
|
|
|
|
|
#pod |
40
|
|
|
|
|
|
|
#pod =back |
41
|
|
|
|
|
|
|
#pod |
42
|
|
|
|
|
|
|
#pod =cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
1
|
1813
|
my $class = shift; |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
3
|
my %attr; |
50
|
1
|
50
|
|
|
|
4
|
if (@_ % 2) { |
51
|
1
|
|
|
|
|
3
|
my $host = shift; |
52
|
1
|
|
|
|
|
4
|
%attr = @_; |
53
|
1
|
|
|
|
|
4
|
$attr{Host} = $host; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
0
|
|
|
|
|
0
|
%attr = @_; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
12
|
my $self = $class->SUPER::new(); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
defined( my $host = delete $attr{Host} ) |
62
|
1
|
50
|
|
|
|
13
|
or croak( "missing Host attribute\n" ); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
defined( my $user = delete $attr{user} ) |
65
|
1
|
50
|
|
|
|
4
|
or croak( "missing user attribute\n" ); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
defined( my $password = delete $attr{password} ) |
68
|
1
|
50
|
|
|
|
6
|
or croak( "missing password attribute\n" ); |
69
|
|
|
|
|
|
|
|
70
|
1
|
50
|
|
|
|
7
|
$self->{server} = Net::FTP->new($host, %attr) |
71
|
|
|
|
|
|
|
or croak("unable to connect to server $host\n"); |
72
|
|
|
|
|
|
|
|
73
|
1
|
50
|
|
|
|
47
|
$self->{server}->login( $user, $password ) |
74
|
|
|
|
|
|
|
or croak("unable to log in to $host\n"); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
72
|
return $self; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _defaults { |
80
|
|
|
|
|
|
|
return ( |
81
|
|
|
|
|
|
|
_stringify => 0, |
82
|
|
|
|
|
|
|
follow_symlinks => 1, |
83
|
|
|
|
|
|
|
depthfirst => 0, |
84
|
|
|
|
|
|
|
sorted => 1, |
85
|
|
|
|
|
|
|
loop_safe => 1, |
86
|
0
|
|
|
0
|
|
0
|
error_handler => sub { die sprintf( "%s: %s", @_ ) }, |
87
|
1
|
|
|
1
|
|
758
|
visitor => undef, |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _fast_defaults { |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
return ( |
94
|
0
|
|
|
0
|
|
0
|
_stringify => 0, |
95
|
|
|
|
|
|
|
follow_symlinks => 1, |
96
|
|
|
|
|
|
|
depthfirst => -1, |
97
|
|
|
|
|
|
|
sorted => 0, |
98
|
|
|
|
|
|
|
loop_safe => 0, |
99
|
|
|
|
|
|
|
error_handler => undef, |
100
|
|
|
|
|
|
|
visitor => undef, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub _objectify { |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
1
|
|
53
|
my ( $self, $path ) = @_; |
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
5
|
my ( $volume, $directories, $name ) = splitpath($path); |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
16
|
$directories =~ s{(.+)/$}{$1}; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
5
|
my %attr = ( |
113
|
|
|
|
|
|
|
parent => $directories, |
114
|
|
|
|
|
|
|
name => $name, |
115
|
|
|
|
|
|
|
path => $path, |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
18
|
return Net::FTP::Path::Iter::Dir->new( server => $self->{server}, %attr ); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub _children { |
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
5
|
|
70
|
my ( $self, $path ) = @_; |
124
|
|
|
|
|
|
|
|
125
|
5
|
|
|
|
|
17
|
return map { [ $_->{name}, $_ ] } $path->_children; |
|
13
|
|
|
|
|
53
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _iter { |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
131
|
1
|
|
|
|
|
3
|
my $defaults = shift; |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
3
|
$defaults->{loop_safe} = 0; |
134
|
|
|
|
|
|
|
|
135
|
1
|
|
|
|
|
10
|
$self->SUPER::_iter( $defaults, @_ ); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# |
142
|
|
|
|
|
|
|
# This file is part of Net-FTP-Path-Iter |
143
|
|
|
|
|
|
|
# |
144
|
|
|
|
|
|
|
# This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. |
145
|
|
|
|
|
|
|
# |
146
|
|
|
|
|
|
|
# This is free software, licensed under: |
147
|
|
|
|
|
|
|
# |
148
|
|
|
|
|
|
|
# The GNU General Public License, Version 3, June 2007 |
149
|
|
|
|
|
|
|
# |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=pod |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 NAME |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Net::FTP::Path::Iter - Iterative, recursive, FTP file finder |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 VERSION |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
version 0.04 |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 SYNOPSIS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
use Net::FTP::Path::Iter; |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# connect to the FTP site |
166
|
|
|
|
|
|
|
my $ftp = Net::FTP::Path::Iter->new( $ftp_site, $user, $password ); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# define a visitor callback routine. It will recieve a |
169
|
|
|
|
|
|
|
# Net::FTP::Path::Iter::Entry object. |
170
|
|
|
|
|
|
|
sub visitor { my ($entry) = @_ } |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# use the Path::Iterator::Rule all() method to traverse the |
173
|
|
|
|
|
|
|
# site; |
174
|
|
|
|
|
|
|
$ftp->all( '/', \&visitor ); |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 DESCRIPTION |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
B is a subclass of L which |
179
|
|
|
|
|
|
|
iterates over an FTP site rather than a local filesystem. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
See the documentation L for how to filter and |
182
|
|
|
|
|
|
|
traverse paths. When B passes a path to a callback or |
183
|
|
|
|
|
|
|
returns one from an iterator, it will be in the form of a |
184
|
|
|
|
|
|
|
L object. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
B uses L to connect to the FTP site. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head2 Symbolic Links |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
At present, B does not handle symbolic links. It will |
191
|
|
|
|
|
|
|
output an error and skip them. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 METHODS |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head2 new |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
$ftp = Net::FTP::Path::Iter->new( [$host], %options ); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Open up a connection to an FTP host and log in. The arguments |
200
|
|
|
|
|
|
|
are the same as for L, with the addition of two |
201
|
|
|
|
|
|
|
mandatory options, |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=over |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item C |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
The user name |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item C |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
The password |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=back |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
B subclasses L. It is a hash based object |
218
|
|
|
|
|
|
|
and has the following additional attributes: |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=over |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=item C |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
The B object representing the connection to the FTP server. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=back |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through the |
231
|
|
|
|
|
|
|
web interface at L. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head1 AUTHOR |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Diab Jerius |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
This software is Copyright (c) 2017 by Smithsonian Astrophysical Observatory. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
This is free software, licensed under: |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
__END__ |