line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::EmptyDirs; |
2
|
2
|
|
|
2
|
|
46003
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
70
|
|
3
|
2
|
|
|
2
|
|
11
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
232
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
2
|
|
|
2
|
|
10
|
use vars qw/@ISA @EXPORT_OK $VERSION/; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
125
|
|
6
|
2
|
|
|
2
|
|
3191
|
use File::Find::Rule::DirectoryEmpty; |
|
2
|
|
|
|
|
21574
|
|
|
2
|
|
|
|
|
21
|
|
7
|
2
|
|
|
2
|
|
101
|
use Cwd; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
632
|
|
8
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
9
|
|
|
|
|
|
|
@EXPORT_OK = qw/remove_empty_dirs/; |
10
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)/g; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub remove_empty_dirs { |
13
|
5
|
|
|
5
|
1
|
111746
|
my $abs = shift; |
14
|
5
|
100
|
50
|
|
|
1084
|
-d $abs or Carp::cluck("argument [$abs] is not a dir.") and return; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
|
|
21
|
my @empty_dirs_removed; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
4
|
|
|
|
|
30
|
my $found_empty_subdirs=1; # startflag |
20
|
4
|
|
|
|
|
32
|
while ($found_empty_subdirs){ |
21
|
8
|
|
|
|
|
21
|
$found_empty_subdirs=0; # assume we will not find empty subdirs to continue with |
22
|
|
|
|
|
|
|
|
23
|
8
|
|
|
|
|
559
|
my @empty_dirs = File::Find::Rule::DirectoryEmpty->directoryempty->in($abs) ; |
24
|
|
|
|
|
|
|
|
25
|
8
|
|
|
|
|
15737
|
EMPTY_DIR: for my $d (@empty_dirs){ |
26
|
|
|
|
|
|
|
|
27
|
5
|
100
|
|
|
|
950
|
next if (Cwd::abs_path($d) eq Cwd::abs_path($abs)); |
28
|
|
|
|
|
|
|
|
29
|
4
|
|
|
|
|
6
|
$found_empty_subdirs++; |
30
|
|
|
|
|
|
|
|
31
|
4
|
50
|
0
|
|
|
667
|
rmdir($d) |
32
|
|
|
|
|
|
|
or Carp::cluck("cannot rmdir '$d', check permissions? '$!'") |
33
|
|
|
|
|
|
|
and next EMPTY_DIR; |
34
|
|
|
|
|
|
|
|
35
|
4
|
|
|
|
|
25
|
push @empty_dirs_removed, $d; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
4
|
100
|
|
|
|
47
|
wantarray ? ( @empty_dirs_removed ) : ( scalar @empty_dirs_removed ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |