line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::RDir; |
2
|
|
|
|
|
|
|
$File::RDir::VERSION = '0.01'; |
3
|
1
|
|
|
1
|
|
678
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
12
|
use Carp qw(croak); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
564
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(read_rdir) ] ); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
13
|
|
|
|
|
|
|
our @EXPORT = qw(); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
1
|
|
|
1
|
0
|
1
|
my $pkg = shift; |
17
|
1
|
|
|
|
|
2
|
my ($dir) = @_; |
18
|
1
|
|
|
|
|
3
|
$dir =~ s{\\}'/'xmsg; |
19
|
|
|
|
|
|
|
|
20
|
1
|
50
|
|
|
|
45
|
opendir my $hdl, $dir or croak "Can't opendir '$dir' because $!"; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
5
|
my $self = { 'root' => $dir, 'ndir' => '', 'dlist' => [], 'hdl' => $hdl }; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
4
|
bless $self, $pkg; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub match { |
28
|
9
|
|
|
9
|
0
|
13
|
my $self = shift; |
29
|
9
|
50
|
|
|
|
24
|
return unless $self->{'hdl'}; |
30
|
|
|
|
|
|
|
|
31
|
9
|
|
|
|
|
11
|
my $ele; |
32
|
9
|
|
|
|
|
18
|
my $full_dir = $self->{'root'}.$self->{'ndir'}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
LOOP1: { |
35
|
9
|
|
|
|
|
11
|
$ele = readdir $self->{'hdl'}; |
|
39
|
|
|
|
|
212
|
|
36
|
|
|
|
|
|
|
|
37
|
39
|
100
|
|
|
|
110
|
unless (defined $ele) { |
38
|
8
|
|
|
|
|
57
|
closedir $self->{'hdl'}; |
39
|
8
|
|
|
|
|
13
|
$self->{'hdl'} = undef; |
40
|
|
|
|
|
|
|
|
41
|
8
|
|
|
|
|
18
|
my $ndir = shift @{$self->{'dlist'}}; |
|
8
|
|
|
|
|
55
|
|
42
|
8
|
100
|
|
|
|
20
|
last LOOP1 unless defined $ndir; |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
12
|
$self->{'ndir'} = $ndir; |
45
|
|
|
|
|
|
|
|
46
|
7
|
|
|
|
|
11
|
$full_dir = $self->{'root'}.$self->{'ndir'}; |
47
|
7
|
50
|
|
|
|
134
|
opendir $self->{'hdl'}, $full_dir or croak "Can't opendir '$full_dir' because $!"; |
48
|
7
|
|
|
|
|
12
|
redo LOOP1; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
31
|
100
|
100
|
|
|
117
|
redo LOOP1 if $ele eq '.' or $ele eq '..'; # <-- This is highly important !!! |
52
|
|
|
|
|
|
|
|
53
|
15
|
|
|
|
|
25
|
my $full_ele = $full_dir.'/'.$ele; |
54
|
|
|
|
|
|
|
|
55
|
15
|
100
|
|
|
|
188
|
if (-d $full_ele) { |
56
|
7
|
|
|
|
|
9
|
push @{$self->{'dlist'}}, $self->{'ndir'}.'/'.$ele; |
|
7
|
|
|
|
|
23
|
|
57
|
7
|
|
|
|
|
13
|
redo LOOP1; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
9
|
100
|
|
|
|
19
|
return unless defined $ele; |
62
|
|
|
|
|
|
|
|
63
|
8
|
|
|
|
|
31
|
return $self->{'ndir'}.'/'.$ele; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub read_rdir { |
67
|
1
|
|
|
1
|
0
|
778
|
my ($dir) = @_; |
68
|
|
|
|
|
|
|
|
69
|
1
|
|
|
|
|
2
|
my @FList; |
70
|
|
|
|
|
|
|
|
71
|
1
|
|
|
|
|
4
|
my $obj = File::RDir->new($dir); |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
5
|
while (defined(my $file = $obj->match)) { |
74
|
8
|
|
|
|
|
24
|
push @FList, $file; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
24
|
return @FList; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |