blib/lib/File/DirList.pm

filter: Statementstmt 75.2% 67 / 89 Branchbran 65.0% 13 / 20 Conditioncond 75.0% 9 / 12 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 40.9% 9 / 22 Podpod 100% 2 / 2 totaltotal 68.0% 102 / 150 CC 16 SCAR 13.8
CC
16
Cov
74%
list
9.4
__ANON__
5.9
__ANON__
4.0
CRAP 4.0
↑ Summary
1 package File::DirList;
2
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 1 require Exporter;
7
8 1 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 1 our %EXPORT_TAGS = ( 'all' => [ qw(
18
19 ) ] );
20
21 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
22
23 1 our @EXPORT = qw(
24
25 );
26
27 1 our $VERSION = '0.05';
28
29 1 ▶use DirHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
31
32 1 my %sortSubs = ();
33
34 0 ▶$sortSubs{'s'} = sub { $_[0]->[7] <=> $_[1]->[7]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
35 0 ▶$sortSubs{'S'} = sub { $_[1]->[7] <=> $_[0]->[7]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
36 0 ▶$sortSubs{'a'} = sub { $_[0]->[8] <=> $_[1]->[8]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
37 0 ▶$sortSubs{'A'} = sub { $_[1]->[8] <=> $_[0]->[8]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
38 0 ▶$sortSubs{'m'} = sub { $_[0]->[9] <=> $_[1]->[9]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
39 0 ▶$sortSubs{'M'} = sub { $_[1]->[9] <=> $_[0]->[9]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
40 0 ▶$sortSubs{'c'} = sub { $_[0]->[10] <=> $_[1]->[10]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
41 0 ▶$sortSubs{'C'} = sub { $_[1]->[10] <=> $_[0]->[10]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
42 0 ▶$sortSubs{'n'} = sub { $_[0]->[13] cmp $_[1]->[13]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
43 0 ▶$sortSubs{'N'} = sub { $_[1]->[13] cmp $_[0]->[13]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
44 0 ▶$sortSubs{'i'} = sub { uc($_[0]->[13]) cmp uc($_[1]->[13]); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
45 0 ▶$sortSubs{'I'} = sub { uc($_[1]->[13]) cmp uc($_[0]->[13]); };
Subroutine __ANON__: not called CC=1 SCAR=1.2
46 3 ▶$sortSubs{'d'} = sub { $_[1]->[14] <=> $_[0]->[14]; };
Subroutine __ANON__: called CC=1 SCAR=0.0
47 0 ▶$sortSubs{'D'} = sub { $_[0]->[14] <=> $_[1]->[14]; };
Subroutine __ANON__: not called CC=1 SCAR=1.2
48
49
50 my $statFile = sub
51 3 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.0
52 3 ▶ return [lstat($_[0].'/'.$_[1]),
Branch: 3 branches
BranchTrueFalseTotal
-d _ ? : 3 0 3
$_[1] eq '..' ? : 1 2 3
$_[1] eq '.' ? : 1 1 2
53 $_[1],
54 (-d _ ? (($_[1] eq '..') ? 2 : (($_[1] eq '.') ? 3 : 1)) : 0),
55 0,
56 undef
57 ];
58 1 };
59
60 my $statLink = sub
61 3 ▶ {
Subroutine __ANON__: called CC=3 SCAR=17.8
62 3 my $res = &{$statFile}(@_);
63
64 3 ▶ if (-l _)
Branch: 1 branch
BranchTrueFalseTotal
if (-l _) 0 3 3
65 {
66 0 $res->[16] = readlink($_[0].'/'.$_[1]);
67 0 ▶ if (-e $res->[16])
Branch: 1 branch
BranchTrueFalseTotal
if (-e $res->[16]) { } 0 0 0
68 {
69 0 $res->[15] = 1;
70 0 (@{$res}[0..12]) = stat(_);
71 0 $res->[14] = -d _;
72 0 $res->[15] = 1;
73 }
74 else
75 {
76 0 $res->[15] = -1;
77 };
78 };
79 3 return $res;
80 1 };
81
82 sub sortList($$)
83 1 ▶ {
Subroutine sortList: called CC=3 SCAR=11.0
Pod documented
84 1 my @sortMode = split(//, $_[1]);
85 3 my @result = sort {my $r = 0;
86 3 foreach my $m (@sortMode)
87 {
88 3 ▶ if (($r = &{$sortSubs{$m}}($a, $b)) != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (($r = &{$sortSubs{$m};}($a, $b)) != 0) 3 0 3
89 3 { last; };
90 };
91 $r;
92 1 } @{$_[0]};
93
94 1 return \@result;
95 };
96
97 sub list($$@)
98 1 ▶ {
Subroutine list: called CC=9 SCAR=22.4
Pod documented
99 1 my ($dirName, $sortMode, $noLinks, $hideDotFiles, $showSelf) = @_;
100
101 1 my @list = ();
102
103 1 my $d = DirHandle->new($dirName);
104
105 1 ▶ if (!defined($d))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $d) 0 1 1
106 0 { return undef; };
107
108 1 my $cwd = getcwd;
109 1 chdir($dirName);
110
111 1 ▶ my $statSub = $noLinks ? $statFile : $statLink;
Branch: 1 branch
BranchTrueFalseTotal
$noLinks ? : 0 1 1
112
113 1 ▶ while (defined(my $entry = $d->read()))
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = $d->read)) 7 1 8
114 {
115 7 ▶ if ((($entry eq '.') && !$showSelf) || ($hideDotFiles && ($entry =~ m/^\../) && ($entry ne '..')))
Branch: 1 branch
BranchTrueFalseTotal
if ($entry eq "." and not $showSelf or $hideDotFiles and $entry =~ /^\../ and $entry ne "..") 4 3 7
Condition75%9/12
$entry eq "." and not $showSelf or $hideDotFiles and $entry =~ /^\../ and $entry ne ".."
l!l&&r!l&&!r
043
$entry eq "." and not $showSelf
!ll&&!rl&&r
610
$hideDotFiles and $entry =~ /^\../ and $entry ne ".."
!ll&&!rl&&r
214
$hideDotFiles and $entry =~ /^\../
!ll&&!rl&&r
025
MC/DC40%2/5
$entry eq "." and not $showSelf or $hideDotFiles and $entry =~ /^\../ and $entry ne ".."
$entry eq "." not $showSelf $hideDotFiles $entry =~ /^\../ $entry ne ".."
Truth table44%4/9
A and not(B) or C and D and E
A= $entry eq "."B= not $showSelfC= $hideDotFilesD= $entry =~ /^\../E= $entry ne ".."
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
116 4 { next; };
117
118 3 push(@list, &{$statSub}($dirName, $entry));
119 };
120
121 1 undef $d;
122
123 1 chdir($cwd);
124
125 1 return sortList(\@list, $sortMode);
126 };
127
128 # Preloaded methods go here.
129
130 1 1;
131 __END__
↑ Summary