line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Listing::Ftpcopy; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
1842328
|
use strict; |
|
11
|
|
|
|
|
34
|
|
|
11
|
|
|
|
|
337
|
|
4
|
11
|
|
|
11
|
|
81
|
use warnings; |
|
11
|
|
|
|
|
30
|
|
|
11
|
|
|
|
|
293
|
|
5
|
11
|
|
|
11
|
|
273
|
use 5.008001; |
|
11
|
|
|
|
|
47
|
|
6
|
11
|
|
|
11
|
|
62
|
use Exporter; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
496
|
|
7
|
11
|
|
|
11
|
|
79
|
use Carp qw( croak ); |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
537
|
|
8
|
11
|
|
|
11
|
|
3439
|
use Time::Local qw( timelocal ); |
|
11
|
|
|
|
|
20955
|
|
|
11
|
|
|
|
|
7965
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: parse directory listing using ftpparse from ftpcopy |
11
|
|
|
|
|
|
|
our $VERSION = '0.08'; # VERSION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub parse_dir ($;$$$) |
15
|
|
|
|
|
|
|
{ |
16
|
7
|
|
|
7
|
1
|
6213
|
my($listing, $time_zone, $type, $error) = @_; |
17
|
|
|
|
|
|
|
|
18
|
7
|
100
|
|
0
|
|
38
|
$error = sub { warn shift } if (defined $error ? $error : '') eq 'warn'; |
|
0
|
50
|
|
|
|
0
|
|
19
|
|
|
|
|
|
|
|
20
|
7
|
|
|
|
|
17
|
my $next; |
21
|
7
|
100
|
|
|
|
55
|
if(ref($listing) eq 'ARRAY') |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
22
|
|
|
|
|
|
|
{ |
23
|
2
|
|
|
|
|
8
|
my @lines = @$listing; |
24
|
2
|
|
|
5
|
|
14
|
$next = sub { shift @lines }; |
|
5
|
|
|
|
|
18
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
elsif(ref($listing) eq 'GLOB') |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
$next = sub { |
29
|
3
|
|
|
3
|
|
15
|
my $line = <$listing>; |
30
|
3
|
|
|
|
|
13
|
$line; |
31
|
1
|
|
|
|
|
7
|
}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif(ref $listing) |
34
|
|
|
|
|
|
|
{ |
35
|
0
|
|
|
|
|
0
|
croak "Illegal argument to parse_dir()"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
elsif($listing =~ /^\*\w+(::\w+)+$/) |
38
|
|
|
|
|
|
|
{ |
39
|
|
|
|
|
|
|
$next = sub { |
40
|
3
|
|
|
3
|
|
11
|
my $line = <$listing>; |
41
|
3
|
|
|
|
|
10
|
$line; |
42
|
1
|
|
|
|
|
5
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else |
45
|
|
|
|
|
|
|
{ |
46
|
3
|
|
|
|
|
58
|
my @lines = split /\015?\012/, $listing; |
47
|
3
|
|
|
49
|
|
19
|
$next = sub { shift @lines }; |
|
49
|
|
|
|
|
99
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
17
|
my @answer; |
51
|
|
|
|
|
|
|
|
52
|
7
|
|
|
|
|
20
|
my $line = $next->(); |
53
|
7
|
|
|
|
|
28
|
while(defined $line) |
54
|
|
|
|
|
|
|
{ |
55
|
53
|
|
|
|
|
88
|
chomp $line; |
56
|
53
|
|
|
|
|
228
|
my $h = _parse_dir($line); |
57
|
53
|
100
|
|
|
|
111
|
if(defined $h) |
|
|
100
|
|
|
|
|
|
58
|
|
|
|
|
|
|
{ |
59
|
34
|
|
|
|
|
85
|
my $mtimetype = pop @$h; |
60
|
34
|
50
|
66
|
|
|
83
|
if($mtimetype == MTIME_LOCAL()) |
|
|
50
|
33
|
|
|
|
|
61
|
|
|
|
|
|
|
{ |
62
|
0
|
0
|
|
|
|
0
|
if(defined $time_zone) |
63
|
|
|
|
|
|
|
{ |
64
|
0
|
|
|
|
|
0
|
my $secs = localtime($h->[3]); |
65
|
0
|
|
|
|
|
0
|
local $ENV{TZ} = $time_zone; |
66
|
0
|
|
|
|
|
0
|
$h->[3] = timelocal($secs); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
elsif($mtimetype == MTIME_REMOTEMINUTE() |
70
|
|
|
|
|
|
|
|| $mtimetype == MTIME_REMOTEDAY() |
71
|
|
|
|
|
|
|
|| $mtimetype == MTIME_REMOTESECOND()) |
72
|
|
|
|
|
|
|
{ |
73
|
34
|
50
|
|
|
|
67
|
if(defined $time_zone) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
0
|
local $ENV{TZ} = $time_zone; |
76
|
0
|
|
|
|
|
0
|
$h->[3] = timelocal(gmtime($h->[3])); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else |
79
|
|
|
|
|
|
|
{ |
80
|
34
|
|
|
|
|
150
|
$h->[3] = timelocal(gmtime($h->[3])); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
34
|
|
|
|
|
1669
|
push @answer, $h; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif(defined $error) |
86
|
|
|
|
|
|
|
{ |
87
|
1
|
|
|
|
|
2
|
$error->($line) |
88
|
|
|
|
|
|
|
} |
89
|
53
|
|
|
|
|
95
|
$line = $next->(); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
7
|
100
|
|
|
|
115
|
return wantarray ? @answer : \@answer; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
97
|
|
|
|
|
|
|
our @EXPORT = qw( parse_dir ); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [qw( |
100
|
|
|
|
|
|
|
parse_dir |
101
|
|
|
|
|
|
|
ftpparse |
102
|
|
|
|
|
|
|
FORMAT_EPLF |
103
|
|
|
|
|
|
|
FORMAT_LS |
104
|
|
|
|
|
|
|
FORMAT_MLSX |
105
|
|
|
|
|
|
|
FORMAT_UNKNOWN |
106
|
|
|
|
|
|
|
ID_FULL |
107
|
|
|
|
|
|
|
ID_UNKNOWN |
108
|
|
|
|
|
|
|
MTIME_LOCAL |
109
|
|
|
|
|
|
|
MTIME_REMOTEDAY |
110
|
|
|
|
|
|
|
MTIME_REMOTEMINUTE |
111
|
|
|
|
|
|
|
MTIME_REMOTESECOND |
112
|
|
|
|
|
|
|
MTIME_UNKNOWN |
113
|
|
|
|
|
|
|
SIZE_ASCII |
114
|
|
|
|
|
|
|
SIZE_BINARY |
115
|
|
|
|
|
|
|
SIZE_UNKNOWN |
116
|
|
|
|
|
|
|
) ] ); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{all} } ); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
require XSLoader; |
121
|
|
|
|
|
|
|
XSLoader::load('File::Listing::Ftpcopy', $VERSION); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub AUTOLOAD |
124
|
|
|
|
|
|
|
{ |
125
|
27
|
|
|
27
|
|
7120
|
my $name; |
126
|
27
|
|
|
|
|
41
|
our $AUTOLOAD; |
127
|
27
|
|
|
|
|
158
|
($name = $AUTOLOAD) =~ s/.*:://; |
128
|
27
|
50
|
|
|
|
83
|
croak "$AUTOLOAD not defined" if $name eq '_constant'; |
129
|
27
|
|
|
|
|
89
|
my $val = _constant($name); |
130
|
27
|
50
|
|
|
|
64
|
croak "$AUTOLOAD not defined" if $val == -1; |
131
|
27
|
|
|
|
|
43
|
do { |
132
|
11
|
|
|
11
|
|
121
|
no strict 'refs'; |
|
11
|
|
|
|
|
29
|
|
|
11
|
|
|
|
|
951
|
|
133
|
27
|
|
|
85
|
|
189
|
*$AUTOLOAD = sub { $val }; |
|
85
|
|
|
|
|
271
|
|
134
|
|
|
|
|
|
|
}; |
135
|
27
|
|
|
|
|
97
|
goto &$AUTOLOAD; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# http://perldoc.perl.org/perlxstut.html |
142
|
|
|
|
|
|
|
# http://perldoc.perl.org/perlguts.html |
143
|
|
|
|
|
|
|
# http://old.nabble.com/*URGENT*-ftpparse-licensing-issue-to61623.html |
144
|
|
|
|
|
|
|
# http://fossies.org/dox/ftpcopy-0.6.7/index.html |
145
|
|
|
|
|
|
|
# http://woodsheep.jp/wget-ftpparse/wget-1.5.3-ftpparse-19970712-0.52.patch |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |