line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::DirList;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20044
|
use strict;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
126
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter;
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export
|
11
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead.
|
12
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants.
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# This allows declaration use File::DirList ':all';
|
15
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
|
16
|
|
|
|
|
|
|
# will save memory.
|
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
) ] );
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = qw(
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
);
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.05';
|
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
874
|
use DirHandle;
|
|
1
|
|
|
|
|
1960
|
|
|
1
|
|
|
|
|
26
|
|
30
|
1
|
|
|
1
|
|
6
|
use Cwd;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
866
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my %sortSubs = ();
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$sortSubs{'s'} = sub { $_[0]->[7] <=> $_[1]->[7]; };
|
35
|
|
|
|
|
|
|
$sortSubs{'S'} = sub { $_[1]->[7] <=> $_[0]->[7]; };
|
36
|
|
|
|
|
|
|
$sortSubs{'a'} = sub { $_[0]->[8] <=> $_[1]->[8]; };
|
37
|
|
|
|
|
|
|
$sortSubs{'A'} = sub { $_[1]->[8] <=> $_[0]->[8]; };
|
38
|
|
|
|
|
|
|
$sortSubs{'m'} = sub { $_[0]->[9] <=> $_[1]->[9]; };
|
39
|
|
|
|
|
|
|
$sortSubs{'M'} = sub { $_[1]->[9] <=> $_[0]->[9]; };
|
40
|
|
|
|
|
|
|
$sortSubs{'c'} = sub { $_[0]->[10] <=> $_[1]->[10]; };
|
41
|
|
|
|
|
|
|
$sortSubs{'C'} = sub { $_[1]->[10] <=> $_[0]->[10]; };
|
42
|
|
|
|
|
|
|
$sortSubs{'n'} = sub { $_[0]->[13] cmp $_[1]->[13]; };
|
43
|
|
|
|
|
|
|
$sortSubs{'N'} = sub { $_[1]->[13] cmp $_[0]->[13]; };
|
44
|
|
|
|
|
|
|
$sortSubs{'i'} = sub { uc($_[0]->[13]) cmp uc($_[1]->[13]); };
|
45
|
|
|
|
|
|
|
$sortSubs{'I'} = sub { uc($_[1]->[13]) cmp uc($_[0]->[13]); };
|
46
|
|
|
|
|
|
|
$sortSubs{'d'} = sub { $_[1]->[14] <=> $_[0]->[14]; };
|
47
|
|
|
|
|
|
|
$sortSubs{'D'} = sub { $_[0]->[14] <=> $_[1]->[14]; };
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my $statFile = sub
|
51
|
|
|
|
|
|
|
{
|
52
|
|
|
|
|
|
|
return [lstat($_[0].'/'.$_[1]),
|
53
|
|
|
|
|
|
|
$_[1],
|
54
|
|
|
|
|
|
|
(-d _ ? (($_[1] eq '..') ? 2 : (($_[1] eq '.') ? 3 : 1)) : 0),
|
55
|
|
|
|
|
|
|
0,
|
56
|
|
|
|
|
|
|
undef
|
57
|
|
|
|
|
|
|
];
|
58
|
|
|
|
|
|
|
};
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $statLink = sub
|
61
|
|
|
|
|
|
|
{
|
62
|
|
|
|
|
|
|
my $res = &{$statFile}(@_);
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
if (-l _)
|
65
|
|
|
|
|
|
|
{
|
66
|
|
|
|
|
|
|
$res->[16] = readlink($_[0].'/'.$_[1]);
|
67
|
|
|
|
|
|
|
if (-e $res->[16])
|
68
|
|
|
|
|
|
|
{
|
69
|
|
|
|
|
|
|
$res->[15] = 1;
|
70
|
|
|
|
|
|
|
(@{$res}[0..12]) = stat(_);
|
71
|
|
|
|
|
|
|
$res->[14] = -d _;
|
72
|
|
|
|
|
|
|
$res->[15] = 1;
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
else
|
75
|
|
|
|
|
|
|
{
|
76
|
|
|
|
|
|
|
$res->[15] = -1;
|
77
|
|
|
|
|
|
|
};
|
78
|
|
|
|
|
|
|
};
|
79
|
|
|
|
|
|
|
return $res;
|
80
|
|
|
|
|
|
|
};
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub sortList($$)
|
83
|
|
|
|
|
|
|
{
|
84
|
1
|
|
|
1
|
1
|
6
|
my @sortMode = split(//, $_[1]);
|
85
|
76
|
|
|
|
|
64
|
my @result = sort {my $r = 0;
|
|
1
|
|
|
|
|
8
|
|
86
|
76
|
|
|
|
|
79
|
foreach my $m (@sortMode)
|
87
|
|
|
|
|
|
|
{
|
88
|
145
|
100
|
|
|
|
127
|
if (($r = &{$sortSubs{$m}}($a, $b)) != 0)
|
|
145
|
|
|
|
|
255
|
|
89
|
76
|
|
|
|
|
69
|
{ last; };
|
90
|
|
|
|
|
|
|
};
|
91
|
76
|
|
|
|
|
76
|
$r;
|
92
|
1
|
|
|
|
|
1
|
} @{$_[0]};
|
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
6
|
return \@result;
|
95
|
|
|
|
|
|
|
};
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub list($$@)
|
98
|
|
|
|
|
|
|
{
|
99
|
1
|
|
|
1
|
1
|
96
|
my ($dirName, $sortMode, $noLinks, $hideDotFiles, $showSelf) = @_;
|
100
|
|
|
|
|
|
|
|
101
|
1
|
|
|
|
|
3
|
my @list = ();
|
102
|
|
|
|
|
|
|
|
103
|
1
|
|
|
|
|
9
|
my $d = DirHandle->new($dirName);
|
104
|
|
|
|
|
|
|
|
105
|
1
|
50
|
|
|
|
130
|
if (!defined($d))
|
106
|
0
|
|
|
|
|
0
|
{ return undef; };
|
107
|
|
|
|
|
|
|
|
108
|
1
|
|
|
|
|
9
|
my $cwd = getcwd;
|
109
|
1
|
|
|
|
|
18
|
chdir($dirName);
|
110
|
|
|
|
|
|
|
|
111
|
1
|
50
|
|
|
|
4
|
my $statSub = $noLinks ? $statFile : $statLink;
|
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
5
|
while (defined(my $entry = $d->read()))
|
114
|
|
|
|
|
|
|
{
|
115
|
27
|
100
|
66
|
|
|
472
|
if ((($entry eq '.') && !$showSelf) || ($hideDotFiles && ($entry =~ m/^\../) && ($entry ne '..')))
|
|
|
|
66
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
33
|
|
|
|
|
116
|
3
|
|
|
|
|
9
|
{ next; };
|
117
|
|
|
|
|
|
|
|
118
|
24
|
|
|
|
|
23
|
push(@list, &{$statSub}($dirName, $entry));
|
|
24
|
|
|
|
|
32
|
|
119
|
|
|
|
|
|
|
};
|
120
|
|
|
|
|
|
|
|
121
|
1
|
|
|
|
|
10
|
undef $d;
|
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
5
|
chdir($cwd);
|
124
|
|
|
|
|
|
|
|
125
|
1
|
|
|
|
|
131
|
return sortList(\@list, $sortMode);
|
126
|
|
|
|
|
|
|
};
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Preloaded methods go here.
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1;
|
131
|
|
|
|
|
|
|
__END__
|