blib/lib/File/RDir.pm

filter: Statementstmt 100% 53 / 53 Branchbran 83.3% 15 / 18 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 92.9% 79 / 85 CC 11 SCAR 17.5
CC
11
Cov
96%
match
9.0
new
2.0
read_rdir
2.0
CRAP 5.8
↑ Summary
1 package File::RDir;
2 1 $File::RDir::VERSION = '0.01';
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 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 require Exporter;
9  
10 1 our @ISA = qw(Exporter);
11 1 our %EXPORT_TAGS = ( 'all' => [ qw(read_rdir) ] );
12 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
13 1 our @EXPORT = qw();
14  
15 sub new {
16 1 ▶ my $pkg = shift;
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
17 1 my ($dir) = @_;
18 1 $dir =~ s{\\}'/'xmsg;
19  
20 1 ▶ opendir my $hdl, $dir or croak "Can't opendir '$dir' because $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $hdl, $dir or croak("Can't opendir '${dir}' because $!") 0 1 1
21  
22 1 my $self = { 'root' => $dir, 'ndir' => '', 'dlist' => [], 'hdl' => $hdl };
23  
24 1 bless $self, $pkg;
25 }
26  
27 sub match {
28 9 ▶ my $self = shift;
Subroutine match: called CC=9 SCAR=22.0
Pod undocumented
29 9 ▶ return unless $self->{'hdl'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"hdl"} 0 9 9
30  
31 9 my $ele;
32 9 my $full_dir = $self->{'root'}.$self->{'ndir'};
33  
34 LOOP1: {
35 9 $ele = readdir $self->{'hdl'};
36  
37 39 ▶ unless (defined $ele) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ele) 8 31 39
38 8 closedir $self->{'hdl'};
39 8 $self->{'hdl'} = undef;
40  
41 8 my $ndir = shift @{$self->{'dlist'}};
42 8 ▶ last LOOP1 unless defined $ndir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ndir 1 7 8
43  
44 7 $self->{'ndir'} = $ndir;
45  
46 7 $full_dir = $self->{'root'}.$self->{'ndir'};
47 7 ▶ opendir $self->{'hdl'}, $full_dir or croak "Can't opendir '$full_dir' because $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir $self->{"hdl"}, $full_dir or croak("Can't opendir '${full_dir}' because $!") 0 7 7
48 7 redo LOOP1;
49 }
50  
51 31 ▶ redo LOOP1 if $ele eq '.' or $ele eq '..'; # <-- This is highly important !!!
Branch: 1 branch
BranchTrueFalseTotal
if $ele eq "." or $ele eq ".." 16 15 31
Condition100%3/3
$ele eq "." or $ele eq ".."
l!l&&r!l&&!r
8815
MC/DC100%2/2
$ele eq "." or $ele eq ".."
$ele eq "." $ele eq ".."
Truth table100%3/3
A or B
A= $ele eq "."B= $ele eq ".."
ABresult
1X1
011
000
52  
53 15 my $full_ele = $full_dir.'/'.$ele;
54  
55 15 ▶ if (-d $full_ele) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $full_ele) 7 8 15
56 7 push @{$self->{'dlist'}}, $self->{'ndir'}.'/'.$ele;
57 7 redo LOOP1;
58 }
59 }
60  
61 9 ▶ return unless defined $ele;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ele 1 8 9
62  
63 8 return $self->{'ndir'}.'/'.$ele;
64 }
65  
66 sub read_rdir {
67 1 ▶ my ($dir) = @_;
Subroutine read_rdir: called CC=2 SCAR=6.9
Pod undocumented
68  
69 1 my @FList;
70  
71 1 my $obj = File::RDir->new($dir);
72  
73 1 ▶ while (defined(my $file = $obj->match)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $file = $obj->match)) 8 1 9
74 8 push @FList, $file;
75 }
76  
77 1 return @FList;
78 }
79  
80 1 1;
81  
82 __END__
↑ Summary