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
|
|
|
|
|
5
|
|
6
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
8
|
1
|
|
|
1
|
|
385
|
use experimental 'switch'; |
|
1
|
|
|
|
|
2693
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
151
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
13
|
1
|
|
|
1
|
|
6
|
use Fcntl qw[ :mode ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
227
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use File::Spec::Functions qw[ catdir catfile ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
380
|
use namespace::clean; |
|
1
|
|
|
|
|
10416
|
|
|
1
|
|
|
|
|
7
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
690
|
use parent 'Net::FTP::Path::Iter::Entry'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
7
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
388
|
use Net::FTP::Path::Iter::File; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
1
|
|
5
|
use constant is_file => 0; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
41
|
|
24
|
1
|
|
|
1
|
|
5
|
use constant is_dir => 1; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
466
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _children { |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
5
|
|
9
|
my $self = shift; |
29
|
|
|
|
|
|
|
|
30
|
5
|
|
|
|
|
73
|
my %attr = ( server => $self->server, ); |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
88
|
my $entries = $self->_get_entries( $self->path ); |
33
|
|
|
|
|
|
|
|
34
|
5
|
|
|
|
|
11
|
my @children; |
35
|
|
|
|
|
|
|
|
36
|
5
|
|
|
|
|
17
|
for my $entry ( @$entries ) { |
37
|
|
|
|
|
|
|
|
38
|
13
|
|
|
|
|
23
|
my $obj; |
39
|
|
|
|
|
|
|
|
40
|
13
|
|
|
|
|
28
|
for ( $entry->{type} ) { |
41
|
|
|
|
|
|
|
|
42
|
13
|
|
|
|
|
33
|
when ( 'd' ) { |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$obj = Net::FTP::Path::Iter::Dir->new( %$entry, %attr, |
45
|
4
|
|
|
|
|
125
|
path => catdir( $self->path, $entry->{name} ) ); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
9
|
|
|
|
|
22
|
when ( 'f' ) { |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$obj = Net::FTP::Path::Iter::File->new( %$entry, %attr, |
51
|
9
|
|
|
|
|
239
|
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
|
|
|
|
|
212
|
push @children, $obj; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
5
|
|
|
|
|
39
|
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
|
|
|
|
16
|
return if $self->_has_attrs; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
21
|
my $server = $self->server; |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
12
|
my $pwd = $server->pwd; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
113
|
my $entry = {}; |
82
|
|
|
|
|
|
|
|
83
|
1
|
50
|
|
|
|
30
|
$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
|
|
|
|
|
247
|
eval { |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# cdup sometimes returns ok even if it didn't work |
92
|
1
|
|
|
|
|
17
|
$server->cdup; |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
178
|
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
|
|
|
|
|
154
|
$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
|
|
|
|
|
3
|
my $err = $@; |
127
|
|
|
|
|
|
|
|
128
|
1
|
50
|
|
|
|
5
|
$server->cwd( $pwd ) |
129
|
|
|
|
|
|
|
or croak( "unable to return to directory: $pwd\n" ); |
130
|
|
|
|
|
|
|
|
131
|
1
|
50
|
|
|
|
141
|
croak( $err ) if $err; |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
30
|
$self->$_( $entry->{$_} ) for keys %$entry; |
134
|
1
|
|
|
|
|
80
|
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__ |