line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Directory::Iterator::PP; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24868
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
78
|
|
5
|
1
|
|
|
1
|
|
5
|
use File::Spec; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
727
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.001004'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
8
|
|
|
8
|
1
|
11676
|
my $class = shift; |
11
|
8
|
|
|
|
|
17
|
my $dir = shift; |
12
|
|
|
|
|
|
|
|
13
|
8
|
|
|
|
|
85
|
my $sep = File::Spec->join('x','x'); |
14
|
8
|
|
|
|
|
56
|
$dir =~ s:$sep$::; |
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
|
|
25
|
$sep =~ y/x//d; |
17
|
8
|
|
|
|
|
53
|
my %self = (file=>undef, dir=>$dir, dirs=>[], ds=>$sep, recurse=>1); |
18
|
8
|
50
|
|
|
|
434
|
opendir($self{dh},$dir) or croak "$dir: $!"; |
19
|
8
|
|
|
|
|
62
|
bless \%self, $class; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub show_dotfiles { |
23
|
2
|
|
|
2
|
1
|
11
|
my $self = shift; |
24
|
2
|
|
|
|
|
4
|
my $arg = shift; |
25
|
2
|
100
|
|
|
|
12
|
$self->{show_dotfiles} = $arg? 1 : 0; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub show_directories { |
29
|
4
|
|
|
4
|
1
|
22
|
my $self = shift; |
30
|
4
|
|
|
|
|
8
|
my $arg = shift; |
31
|
4
|
100
|
|
|
|
20
|
$self->{show_directories} = $arg? 1 : 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub recursive { |
35
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
36
|
1
|
|
|
|
|
2
|
my $arg = shift; |
37
|
1
|
|
|
|
|
25
|
$self->{recurse} = $arg; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub get { |
41
|
42
|
|
|
42
|
1
|
112
|
my $self = shift; |
42
|
42
|
|
|
|
|
1057
|
return $self->{file}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _scan { |
46
|
46
|
|
|
46
|
|
57
|
my $self = shift; |
47
|
46
|
|
|
|
|
397
|
while (my $de = readdir $self->{dh}) { |
48
|
72
|
100
|
|
|
|
147
|
if ($self->{show_dotfiles}) { |
49
|
10
|
100
|
100
|
|
|
73
|
next if ($de eq '.' or $de eq '..'); |
50
|
|
|
|
|
|
|
} else { |
51
|
62
|
100
|
|
|
|
467
|
next if ( $de =~ m/^\./ ); |
52
|
|
|
|
|
|
|
} |
53
|
37
|
|
|
|
|
491
|
my $path = File::Spec->join("$self->{dir}", $de); |
54
|
37
|
50
|
|
|
|
1372
|
return undef unless lstat($path); |
55
|
37
|
100
|
66
|
|
|
178
|
if ( -d _ and ! -l _ ) { |
|
|
50
|
|
|
|
|
|
56
|
9
|
100
|
|
|
|
33
|
push @{$self->{dirs}}, $path |
|
8
|
|
|
|
|
27
|
|
57
|
|
|
|
|
|
|
if $self->{recurse}; |
58
|
|
|
|
|
|
|
|
59
|
9
|
100
|
|
|
|
41
|
if ($self->{show_directories}) { |
60
|
4
|
|
|
|
|
13
|
$self->{is_dir} = 1; |
61
|
4
|
|
|
|
|
77
|
return $self->{file} = $path; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ( -f _ ) { |
65
|
28
|
|
|
|
|
48
|
$self->{is_dir} = undef; |
66
|
28
|
|
|
|
|
98
|
return $self->{file} = $path; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
14
|
|
|
|
|
31
|
return undef; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub is_directory { |
73
|
11
|
|
|
11
|
1
|
44
|
return $_[0]{is_dir}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub prune_directory { |
77
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
78
|
1
|
|
|
|
|
1
|
pop @{$self->{dirs}}; |
|
1
|
|
|
|
|
18
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub next { |
82
|
40
|
|
|
40
|
1
|
10986
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
40
|
100
|
|
|
|
164
|
if ($self->{dh}) { |
85
|
39
|
|
|
|
|
82
|
my $rv = $self->_scan; |
86
|
39
|
100
|
|
|
|
82
|
if( defined $rv ) { |
87
|
25
|
|
|
|
|
106
|
return $rv; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
else { |
90
|
14
|
|
|
|
|
33
|
$self->{dh} = undef; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
15
|
|
|
|
|
282
|
while ( @{ $self->{dirs} } ) { |
|
15
|
|
|
|
|
55
|
|
95
|
7
|
|
|
|
|
12
|
$self->{dir} = pop @{ $self->{dirs} }; |
|
7
|
|
|
|
|
23
|
|
96
|
7
|
50
|
|
|
|
242
|
opendir( $self->{dh}, $self->{dir} ) or carp "$self->{dir}: $!"; |
97
|
7
|
50
|
|
|
|
28
|
if ( $self->{dh} ) { |
98
|
7
|
|
|
|
|
20
|
my $rv = $self->_scan; |
99
|
7
|
50
|
|
|
|
45
|
return $rv if defined $rv; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
8
|
|
|
|
|
33
|
return undef; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub prune { |
106
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
107
|
1
|
|
|
|
|
5
|
undef $self->{dh}; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# while ($self->{dirs}[-1] =~ m/$self->{dir}$self->{sep}/) { |
110
|
|
|
|
|
|
|
# pop @{ $self->{dirs} }; |
111
|
|
|
|
|
|
|
# } |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
1
|
|
1663
|
use overload '<>' => \&next, '""' => \&get; |
|
1
|
|
|
|
|
1192
|
|
|
1
|
|
|
|
|
9
|
|
115
|
|
|
|
|
|
|
1; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |