| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
17
|
|
|
17
|
|
2136
|
use strict; use warnings; |
|
|
17
|
|
|
17
|
|
46
|
|
|
|
17
|
|
|
|
|
635
|
|
|
|
17
|
|
|
|
|
110
|
|
|
|
17
|
|
|
|
|
41
|
|
|
|
17
|
|
|
|
|
720
|
|
|
2
|
|
|
|
|
|
|
package IO::All::Dir; |
|
3
|
|
|
|
|
|
|
|
|
4
|
17
|
|
|
17
|
|
115
|
use Scalar::Util 'blessed'; |
|
|
17
|
|
|
|
|
43
|
|
|
|
17
|
|
|
|
|
1232
|
|
|
5
|
17
|
|
|
17
|
|
127
|
use File::Glob 'bsd_glob'; |
|
|
17
|
|
|
|
|
42
|
|
|
|
17
|
|
|
|
|
4408
|
|
|
6
|
17
|
|
|
17
|
|
623
|
use IO::All::Filesys -base; |
|
|
17
|
|
|
|
|
45
|
|
|
|
17
|
|
|
|
|
156
|
|
|
7
|
17
|
|
|
17
|
|
185
|
use IO::All -base; |
|
|
17
|
|
|
|
|
85
|
|
|
|
17
|
|
|
|
|
136
|
|
|
8
|
17
|
|
|
17
|
|
8400
|
use IO::Dir; |
|
|
17
|
|
|
|
|
168074
|
|
|
|
17
|
|
|
|
|
27015
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#=============================================================================== |
|
11
|
|
|
|
|
|
|
const type => 'dir'; |
|
12
|
|
|
|
|
|
|
option 'sort' => 1; |
|
13
|
|
|
|
|
|
|
chain filter => undef; |
|
14
|
|
|
|
|
|
|
option 'deep'; |
|
15
|
|
|
|
|
|
|
field 'chdir_from'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#=============================================================================== |
|
18
|
|
|
|
|
|
|
sub dir { |
|
19
|
234
|
|
|
234
|
1
|
454
|
my $self = shift; |
|
20
|
234
|
|
66
|
|
|
1582
|
my $had_prev = blessed($self) && $self->pathname; |
|
21
|
|
|
|
|
|
|
|
|
22
|
234
|
100
|
|
|
|
748
|
bless $self, __PACKAGE__ unless $had_prev; |
|
23
|
234
|
100
|
100
|
|
|
1974
|
if (@_ && @_ > 1 || @_ && $had_prev) { |
|
|
|
100
|
100
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
24
|
12
|
100
|
|
|
|
45
|
$self->name( |
|
25
|
|
|
|
|
|
|
$self->_spec_class->catdir( |
|
26
|
|
|
|
|
|
|
($self->pathname ? ($self->pathname) : () ), |
|
27
|
|
|
|
|
|
|
@_, |
|
28
|
|
|
|
|
|
|
) |
|
29
|
|
|
|
|
|
|
) |
|
30
|
|
|
|
|
|
|
} elsif (@_) { |
|
31
|
221
|
|
|
|
|
622
|
$self->name($_[0]) |
|
32
|
|
|
|
|
|
|
} |
|
33
|
234
|
|
|
|
|
749
|
return $self->_init; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub dir_handle { |
|
37
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
38
|
0
|
|
|
|
|
0
|
bless $self, __PACKAGE__; |
|
39
|
0
|
0
|
|
|
|
0
|
$self->_handle(shift) if @_; |
|
40
|
0
|
|
|
|
|
0
|
return $self->_init; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#=============================================================================== |
|
44
|
|
|
|
|
|
|
sub _assert_open { |
|
45
|
943
|
|
|
943
|
|
1522
|
my $self = shift; |
|
46
|
943
|
100
|
|
|
|
2427
|
return if $self->is_open; |
|
47
|
138
|
|
|
|
|
418
|
$self->open; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub open { |
|
51
|
138
|
|
|
138
|
1
|
246
|
my $self = shift; |
|
52
|
138
|
|
|
|
|
445
|
$self->is_open(1); |
|
53
|
138
|
50
|
33
|
|
|
456
|
$self->_assert_dirpath($self->pathname) |
|
54
|
|
|
|
|
|
|
if $self->pathname and $self->_assert; |
|
55
|
138
|
|
|
|
|
706
|
my $handle = IO::Dir->new; |
|
56
|
138
|
|
|
|
|
3468
|
$self->io_handle($handle); |
|
57
|
138
|
100
|
|
|
|
388
|
$handle->open($self->pathname) |
|
58
|
|
|
|
|
|
|
or $self->throw($self->open_msg); |
|
59
|
137
|
|
|
|
|
5999
|
return $self; |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub open_msg { |
|
63
|
1
|
|
|
1
|
0
|
65
|
my $self = shift; |
|
64
|
1
|
50
|
|
|
|
5
|
my $name = defined $self->pathname |
|
65
|
|
|
|
|
|
|
? " '" . $self->pathname . "'" |
|
66
|
|
|
|
|
|
|
: ''; |
|
67
|
1
|
|
|
|
|
24
|
return qq{Can't open directory$name:\n$!}; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
1
|
0
|
sub exists { -d shift->pathname } |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#=============================================================================== |
|
73
|
|
|
|
|
|
|
sub All { |
|
74
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
|
75
|
1
|
|
|
|
|
3
|
$self->all(0); |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub all { |
|
79
|
134
|
|
|
134
|
1
|
1544
|
my $self = shift; |
|
80
|
134
|
100
|
|
|
|
406
|
my $depth = @_ ? shift(@_) : $self->_deep ? 0 : 1; |
|
|
|
100
|
|
|
|
|
|
|
81
|
134
|
|
|
|
|
286
|
my $first = not @_; |
|
82
|
134
|
|
|
|
|
210
|
my @all; |
|
83
|
134
|
|
|
|
|
343
|
while (my $io = $self->next) { |
|
84
|
314
|
|
|
|
|
691
|
push @all, $io; |
|
85
|
314
|
100
|
100
|
|
|
1350
|
push(@all, $io->all($depth - 1, 1)) |
|
86
|
|
|
|
|
|
|
if $depth != 1 and $io->is_dir; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
134
|
100
|
|
|
|
437
|
@all = grep {&{$self->filter}} @all |
|
|
20
|
|
|
|
|
30
|
|
|
|
20
|
|
|
|
|
39
|
|
|
89
|
|
|
|
|
|
|
if $self->filter; |
|
90
|
134
|
100
|
66
|
|
|
799
|
return @all unless $first and $self->_sort; |
|
91
|
39
|
|
|
|
|
210
|
return sort {$a->pathname cmp $b->pathname} @all; |
|
|
633
|
|
|
|
|
1635
|
|
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub All_Dirs { |
|
95
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
|
96
|
3
|
|
|
|
|
9
|
$self->all_dirs(0); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub all_dirs { |
|
100
|
11
|
|
|
11
|
1
|
29
|
my $self = shift; |
|
101
|
11
|
|
|
|
|
38
|
grep {$_->is_dir} $self->all(@_); |
|
|
82
|
|
|
|
|
201
|
|
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub All_Files { |
|
105
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
|
106
|
3
|
|
|
|
|
12
|
$self->all_files(0); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub all_files { |
|
110
|
13
|
|
|
13
|
1
|
33
|
my $self = shift; |
|
111
|
13
|
|
|
|
|
54
|
grep {$_->is_file} $self->all(@_); |
|
|
112
|
|
|
|
|
344
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub All_Links { |
|
115
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
116
|
0
|
|
|
|
|
0
|
$self->all_links(0); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub all_links { |
|
120
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
121
|
0
|
|
|
|
|
0
|
grep {$_->is_link} $self->all(@_); |
|
|
0
|
|
|
|
|
0
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub chdir { |
|
125
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
|
126
|
1
|
|
|
|
|
11
|
require Cwd; |
|
127
|
1
|
|
|
|
|
6102
|
$self->chdir_from(Cwd::cwd()); |
|
128
|
1
|
|
|
|
|
11
|
CORE::chdir($self->pathname); |
|
129
|
1
|
|
|
|
|
14
|
return $self; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub empty { |
|
133
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
134
|
1
|
|
|
|
|
2
|
my $dh; |
|
135
|
1
|
50
|
|
|
|
7
|
opendir($dh, $self->pathname) or die; |
|
136
|
1
|
|
|
|
|
35
|
while (my $dir = readdir($dh)) { |
|
137
|
2
|
50
|
|
|
|
16
|
return 0 unless $dir =~ /^\.{1,2}$/; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
1
|
|
|
|
|
16
|
return 1; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub mkdir { |
|
143
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
144
|
1
|
50
|
0
|
|
|
7
|
defined($self->perms) |
|
|
|
|
50
|
|
|
|
|
|
145
|
|
|
|
|
|
|
? (CORE::mkdir($self->pathname, $self->perms) or die "mkdir failed: $!") |
|
146
|
|
|
|
|
|
|
: (CORE::mkdir($self->pathname) or die "mkdir failed: $!"); |
|
147
|
1
|
|
|
|
|
10
|
return $self; |
|
148
|
|
|
|
|
|
|
} |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub mkpath { |
|
151
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
152
|
0
|
|
|
|
|
0
|
require File::Path; |
|
153
|
0
|
|
|
|
|
0
|
File::Path::mkpath($self->pathname, @_); |
|
154
|
0
|
|
|
|
|
0
|
return $self; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
sub file { |
|
158
|
0
|
|
|
0
|
1
|
0
|
my ($self, @rest) = @_; |
|
159
|
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
0
|
return $self->_constructor->()->file($self->pathname, @rest) |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub next { |
|
164
|
472
|
|
|
472
|
1
|
889
|
my $self = shift; |
|
165
|
472
|
|
|
|
|
1348
|
$self->_assert_open; |
|
166
|
471
|
|
|
|
|
1297
|
my $name = $self->readdir; |
|
167
|
471
|
100
|
|
|
|
1495
|
return unless defined $name; |
|
168
|
335
|
|
|
|
|
1116
|
my $io = $self->_constructor->(File::Spec->catfile($self->pathname, $name)); |
|
169
|
335
|
100
|
|
|
|
1440
|
$io->absolute if $self->is_absolute; |
|
170
|
335
|
|
|
|
|
1246
|
return $io; |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub readdir { |
|
174
|
471
|
|
|
471
|
1
|
827
|
my $self = shift; |
|
175
|
471
|
|
|
|
|
1337
|
$self->_assert_open; |
|
176
|
471
|
50
|
|
|
|
1303
|
if (wantarray) { |
|
177
|
|
|
|
|
|
|
my @return = grep { |
|
178
|
0
|
|
|
|
|
0
|
not /^\.{1,2}$/ |
|
|
0
|
|
|
|
|
0
|
|
|
179
|
|
|
|
|
|
|
} $self->io_handle->read; |
|
180
|
0
|
|
|
|
|
0
|
$self->close; |
|
181
|
0
|
0
|
|
|
|
0
|
if ($self->_has_utf8) { utf8::decode($_) for (@return) } |
|
|
0
|
|
|
|
|
0
|
|
|
182
|
0
|
|
|
|
|
0
|
return @return; |
|
183
|
|
|
|
|
|
|
} |
|
184
|
471
|
|
|
|
|
1059
|
my $name = '.'; |
|
185
|
471
|
|
|
|
|
2457
|
while ($name =~ /^\.{1,2}$/) { |
|
186
|
743
|
|
|
|
|
2141
|
$name = $self->io_handle->read; |
|
187
|
743
|
100
|
|
|
|
9697
|
unless (defined $name) { |
|
188
|
136
|
|
|
|
|
677
|
$self->close; |
|
189
|
136
|
|
|
|
|
2521
|
return; |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
} |
|
192
|
335
|
50
|
|
|
|
1143
|
if ($self->_has_utf8) { utf8::decode($name) } |
|
|
0
|
|
|
|
|
0
|
|
|
193
|
335
|
|
|
|
|
868
|
return $name; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub rmdir { |
|
197
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
198
|
0
|
|
|
|
|
0
|
rmdir $self->pathname; |
|
199
|
|
|
|
|
|
|
} |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub rmtree { |
|
202
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
203
|
0
|
|
|
|
|
0
|
require File::Path; |
|
204
|
0
|
|
|
|
|
0
|
File::Path::rmtree($self->pathname, @_); |
|
205
|
|
|
|
|
|
|
} |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
sub glob { |
|
208
|
1
|
|
|
1
|
1
|
5
|
my ($self, @rest) = @_; |
|
209
|
|
|
|
|
|
|
|
|
210
|
1
|
|
|
|
|
4
|
map {; |
|
211
|
3
|
|
|
|
|
18
|
my $ret = $self->_constructor->($_); |
|
212
|
3
|
50
|
|
|
|
13
|
$ret->absolute if $self->is_absolute; |
|
213
|
3
|
|
|
|
|
21
|
$ret |
|
214
|
|
|
|
|
|
|
} bsd_glob $self->_spec_class->catdir( $self->pathname, @rest ); |
|
215
|
|
|
|
|
|
|
} |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
sub copy { |
|
218
|
0
|
|
|
0
|
1
|
0
|
my ($self, $new) = @_; |
|
219
|
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
0
|
require File::Copy::Recursive; |
|
221
|
|
|
|
|
|
|
|
|
222
|
0
|
0
|
|
|
|
0
|
File::Copy::Recursive::dircopy($self->name, $new) |
|
223
|
|
|
|
|
|
|
or die "failed to copy $self to $new: $!"; |
|
224
|
0
|
|
|
|
|
0
|
$self->_constructor->($new) |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub DESTROY { |
|
228
|
234
|
|
|
234
|
|
17543
|
my $self = shift; |
|
229
|
234
|
100
|
|
|
|
655
|
CORE::chdir($self->chdir_from) |
|
230
|
|
|
|
|
|
|
if $self->chdir_from; |
|
231
|
|
|
|
|
|
|
# $self->SUPER::DESTROY(@_); |
|
232
|
|
|
|
|
|
|
} |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
#=============================================================================== |
|
235
|
|
|
|
|
|
|
sub _overload_table { |
|
236
|
|
|
|
|
|
|
( |
|
237
|
4
|
|
|
4
|
|
28
|
'${} dir' => '_overload_as_scalar', |
|
238
|
|
|
|
|
|
|
'@{} dir' => '_overload_as_array', |
|
239
|
|
|
|
|
|
|
'%{} dir' => '_overload_as_hash', |
|
240
|
|
|
|
|
|
|
) |
|
241
|
|
|
|
|
|
|
} |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
sub _overload_as_scalar { |
|
244
|
1
|
|
|
1
|
|
9
|
\ $_[1]; |
|
245
|
|
|
|
|
|
|
} |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub _overload_as_array { |
|
248
|
1
|
|
|
1
|
|
6
|
[ $_[1]->all ]; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
sub _overload_as_hash { |
|
252
|
|
|
|
|
|
|
+{ |
|
253
|
|
|
|
|
|
|
map { |
|
254
|
2
|
|
|
2
|
|
10
|
(my $name = $_->pathname) =~ s/.*[\/\\]//; |
|
|
10
|
|
|
|
|
39
|
|
|
255
|
10
|
|
|
|
|
66
|
($name, $_); |
|
256
|
|
|
|
|
|
|
} $_[1]->all |
|
257
|
|
|
|
|
|
|
}; |
|
258
|
|
|
|
|
|
|
} |
|
259
|
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
1; |