All/Dir.pm

filter: Statementstmt 80.0% 116 / 145 Branchbran 79.6% 43 / 54 Conditioncond 72.0% 18 / 25 MC/DCmcdc 57.1% 8 / 14 Subroutinesub 75.6% 28 / 37 Podpod 91.6% 22 / 24 totaltotal 78.6% 235 / 299 CC 37 SCAR 14.6
CC
37
Cov
79%
dir
9.0
all
9.0
dir_handle
6.0
CRAP 4.3
« All/Socket.pm ↑ Summary All/Base.pm »
1 17 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
2 package IO::All::Dir;
3  
4 17 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 17 ▶use File::Glob 'bsd_glob';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 17 ▶use IO::All::Filesys -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 17 ▶use IO::All -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 17 ▶use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 #===============================================================================
11 17 const type => 'dir';
12 17 option 'sort' => 1;
13 17 chain filter => undef;
14 17 option 'deep';
15 17 field 'chdir_from';
16  
17 #===============================================================================
18 sub dir {
19 233 ▶ my $self = shift;
Subroutine dir: called CC=9 SCAR=22.0
Pod documented
20 233 ▶ my $had_prev = blessed($self) && $self->pathname;
Condition66%2/3
builtin::blessed($self) && $self->pathname
!ll&&!rl&&r
02312
MC/DC50%1/2
builtin::blessed($self) && $self->pathname
builtin::blessed($self) $self->pathname
Truth table66%2/3
A && B
A= builtin::blessed($self)B= $self->pathname
ABresult
0X0
100
111
21  
22 233 ▶ bless $self, __PACKAGE__ unless $had_prev;
Branch: 1 branch
BranchTrueFalseTotal
unless $had_prev 231 2 233
23 233 ▶ if (@_ && @_ > 1 || @_ && $had_prev) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ and @_ > 1 or @_ and $had_prev) { } 12 221 233
elsif (@_) { } 220 1 221
Condition100%9/9
@_ and @_ > 1 or @_ and $had_prev
l!l&&r!l&&!r
111221
@_ and @_ > 1
!ll&&!rl&&r
122111
@_ and $had_prev
!ll&&!rl&&r
12201
MC/DC100%4/4
@_ and @_ > 1 or @_ and $had_prev
@_ @_ > 1 @_ $had_prev
Truth table57%4/7
A and B or C and D
A= @_B= @_ > 1C= @_D= $had_prev
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
24 12 ▶ $self->name(
Branch: 1 branch
BranchTrueFalseTotal
$self->pathname ? : 2 10 12
25 $self->_spec_class->catdir(
26 ($self->pathname ? ($self->pathname) : () ),
27 @_,
28 )
29 )
30 } elsif (@_) {
31 220 $self->name($_[0])
32 }
33 233 return $self->_init;
34 }
35  
36 sub dir_handle {
37 0 ▶ my $self = shift;
Subroutine dir_handle: not called CC=2 SCAR=17.9
Pod undocumented
38 0 bless $self, __PACKAGE__;
39 0 ▶ $self->_handle(shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
40 0 return $self->_init;
41 }
42  
43 #===============================================================================
44 sub _assert_open {
45 935 ▶ my $self = shift;
Subroutine _assert_open: called CC=2 SCAR=6.9
46 935 ▶ return if $self->is_open;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_open 798 137 935
47 137 $self->open;
48 }
49  
50 sub open {
51 137 ▶ my $self = shift;
Subroutine open: called CC=4 SCAR=14.2
Pod documented
52 137 $self->is_open(1);
53 137 ▶ $self->_assert_dirpath($self->pathname)
Branch: 1 branch
BranchTrueFalseTotal
if $self->pathname and $self->_assert 0 137 137
Condition33%1/3
$self->pathname and $self->_assert
!ll&&!rl&&r
01370
MC/DC0%0/2
$self->pathname and $self->_assert
$self->pathname $self->_assert
Truth table33%1/3
A and B
A= $self->pathnameB= $self->_assert
ABresult
0X0
100
111
54 if $self->pathname and $self->_assert;
55 137 my $handle = IO::Dir->new;
56 137 $self->io_handle($handle);
57 137 ▶ $handle->open($self->pathname)
Branch: 1 branch
BranchTrueFalseTotal
$handle->open($self->pathname) or $self->throw($self->open_msg) 1 136 137
58 or $self->throw($self->open_msg);
59 136 return $self;
60 }
61  
62 sub open_msg {
63 1 ▶ my $self = shift;
Subroutine open_msg: called CC=2 SCAR=7.1
Pod undocumented
64 1 ▶ my $name = defined $self->pathname
Branch: 1 branch
BranchTrueFalseTotal
defined $self->pathname ? : 1 0 1
65 ? " '" . $self->pathname . "'"
66 : '';
67 1 return qq{Can't open directory$name:\n$!};
68 }
69  
70 0 ▶sub exists { -d shift->pathname }
Subroutine exists: not called CC=1 SCAR=6.9
Pod documented
71  
72 #===============================================================================
73 sub All {
74 1 ▶ my $self = shift;
Subroutine All: called CC=1 SCAR=0.0
Pod documented
75 1 $self->all(0);
76 }
77  
78 sub all {
79 133 ▶ my $self = shift;
Subroutine all: called CC=9 SCAR=22.0
Pod documented
80 133 ▶ my $depth = @_ ? shift(@_) : $self->_deep ? 0 : 1;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 121 12 133
$self->_deep ? : 3 9 12
81 133 my $first = not @_;
82 133 my @all;
83 133 ▶ while (my $io = $self->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $io = $self->next) 311 133 444
84 311 push @all, $io;
85 311 ▶ push(@all, $io->all($depth - 1, 1))
Branch: 1 branch
BranchTrueFalseTotal
if $depth != 1 and $io->is_dir 95 216 311
Condition100%3/3
$depth != 1 and $io->is_dir
!ll&&!rl&&r
7514195
MC/DC100%2/2
$depth != 1 and $io->is_dir
$depth != 1 $io->is_dir
Truth table100%3/3
A and B
A= $depth != 1B= $io->is_dir
ABresult
0X0
100
111
86 if $depth != 1 and $io->is_dir;
87 }
88 133 ▶ @all = grep {&{$self->filter}} @all
Branch: 1 branch
BranchTrueFalseTotal
if $self->filter 2 131 133
89 if $self->filter;
90 133 ▶ return @all unless $first and $self->_sort;
Branch: 1 branch
BranchTrueFalseTotal
unless $first and $self->_sort 95 38 133
Condition66%2/3
$first and $self->_sort
!ll&&!rl&&r
95038
MC/DC50%1/2
$first and $self->_sort
$first $self->_sort
Truth table66%2/3
A and B
A= $firstB= $self->_sort
ABresult
0X0
100
111
91 38 return sort {$a->pathname cmp $b->pathname} @all;
92 }
93  
94 sub All_Dirs {
95 3 ▶ my $self = shift;
Subroutine All_Dirs: called CC=1 SCAR=0.0
Pod documented
96 3 $self->all_dirs(0);
97 }
98  
99 sub all_dirs {
100 11 ▶ my $self = shift;
Subroutine all_dirs: called CC=1 SCAR=0.0
Pod documented
101 11 grep {$_->is_dir} $self->all(@_);
102 }
103  
104 sub All_Files {
105 3 ▶ my $self = shift;
Subroutine All_Files: called CC=1 SCAR=0.0
Pod documented
106 3 $self->all_files(0);
107 }
108  
109 sub all_files {
110 13 ▶ my $self = shift;
Subroutine all_files: called CC=1 SCAR=0.0
Pod documented
111 13 grep {$_->is_file} $self->all(@_);
112 }
113  
114 sub All_Links {
115 0 ▶ my $self = shift;
Subroutine All_Links: not called CC=1 SCAR=6.9
Pod documented
116 0 $self->all_links(0);
117 }
118  
119 sub all_links {
120 0 ▶ my $self = shift;
Subroutine all_links: not called CC=1 SCAR=6.9
Pod documented
121 0 grep {$_->is_link} $self->all(@_);
122 }
123  
124 sub chdir {
125 1 ▶ my $self = shift;
Subroutine chdir: called CC=1 SCAR=0.0
Pod documented
126 1 require Cwd;
127 1 $self->chdir_from(Cwd::cwd());
128 1 CORE::chdir($self->pathname);
129 1 return $self;
130 }
131  
132 sub empty {
133 1 ▶ my $self = shift;
Subroutine empty: called CC=4 SCAR=14.0
Pod documented
134 1 my $dh;
135 1 ▶ opendir($dh, $self->pathname) or die;
Branch: 1 branch
BranchTrueFalseTotal
opendir $dh, $self->pathname or die 0 1 1
136 1 ▶ while (my $dir = readdir($dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dir = CORE::readdir $dh)) 2 1 3
137 2 ▶ return 0 unless $dir =~ /^\.{1,2}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir =~ /^\.{1,2}$/ 0 2 2
138 }
139 1 return 1;
140 }
141  
142 sub mkdir {
143 1 ▶ my $self = shift;
Subroutine mkdir: called CC=4 SCAR=16.9
Pod documented
144 1 ▶ defined($self->perms)
Branch: 1 branch
BranchTrueFalseTotal
defined $self->perms ? : 0 1 1
Condition25%1/4
CORE::mkdir $self->pathname, $self->perms or die "mkdir failed: $!"
l!l
00
CORE::mkdir $self->pathname or die "mkdir failed: $!"
l!l
10
MC/DC0%0/1
CORE::mkdir $self->pathname, $self->perms or die "mkdir failed: $!"
CORE::mkdir $self->pathname, $self->perms
MC/DC0%0/1
CORE::mkdir $self->pathname or die "mkdir failed: $!"
CORE::mkdir $self->pathname
Truth table0%0/2
A
A= CORE::mkdir $self->pathname, $self->perms
Aresult
11
00
Truth table50%1/2
A
A= CORE::mkdir $self->pathname
Aresult
11
00
145 ? (CORE::mkdir($self->pathname, $self->perms) or die "mkdir failed: $!")
146 : (CORE::mkdir($self->pathname) or die "mkdir failed: $!");
147 1 return $self;
148 }
149  
150 sub mkpath {
151 0 ▶ my $self = shift;
Subroutine mkpath: not called CC=1 SCAR=6.9
Pod documented
152 0 require File::Path;
153 0 File::Path::mkpath($self->pathname, @_);
154 0 return $self;
155 }
156  
157 sub file {
158 0 ▶ my ($self, @rest) = @_;
Subroutine file: not called CC=1 SCAR=6.9
Pod documented
159  
160 0 return $self->_constructor->()->file($self->pathname, @rest)
161 }
162  
163 sub next {
164 468 ▶ my $self = shift;
Subroutine next: called CC=3 SCAR=11.0
Pod documented
165 468 $self->_assert_open;
166 467 my $name = $self->readdir;
167 467 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 135 332 467
168 332 my $io = $self->_constructor->(File::Spec->catfile($self->pathname, $name));
169 332 ▶ $io->absolute if $self->is_absolute;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_absolute 16 316 332
170 332 return $io;
171 }
172  
173 sub readdir {
174 467 ▶ my $self = shift;
Subroutine readdir: called CC=4 SCAR=14.5
Pod documented
175 467 $self->_assert_open;
176 467 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 467 467
177 my @return = grep {
178 0 not /^\.{1,2}$/
179 } $self->io_handle->read;
180 0 $self->close;
181 0 return @return;
182 }
183 467 my $name = '.';
184 467 ▶ while ($name =~ /^\.{1,2}$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^\.{1,2}$/) 739 332 1071
185 739 $name = $self->io_handle->read;
186 739 ▶ unless (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 135 604 739
187 135 $self->close;
188 135 return;
189 }
190 }
191 332 return $name;
192 }
193  
194 sub rmdir {
195 0 ▶ my $self = shift;
Subroutine rmdir: not called CC=1 SCAR=6.9
Pod documented
196 0 rmdir $self->pathname;
197 }
198  
199 sub rmtree {
200 0 ▶ my $self = shift;
Subroutine rmtree: not called CC=1 SCAR=6.9
Pod documented
201 0 require File::Path;
202 0 File::Path::rmtree($self->pathname, @_);
203 }
204  
205 sub glob {
206 1 ▶ my ($self, @rest) = @_;
Subroutine glob: called CC=2 SCAR=7.0
Pod documented
207  
208 1 map {;
209 3 my $ret = $self->_constructor->($_);
210 3 ▶ $ret->absolute if $self->is_absolute;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_absolute 0 3 3
211 3 $ret
212 } bsd_glob $self->_spec_class->catdir( $self->pathname, @rest );
213 }
214  
215 sub copy {
216 0 ▶ my ($self, $new) = @_;
Subroutine copy: not called CC=2 SCAR=17.9
Pod documented
217  
218 0 require File::Copy::Recursive;
219  
220 0 ▶ File::Copy::Recursive::dircopy($self->name, $new)
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::Recursive::dircopy($self->name, $new) or die "failed to copy $self to ${new}: $!" 0 0 0
221 or die "failed to copy $self to $new: $!";
222 0 $self->_constructor->($new)
223 }
224  
225 sub DESTROY {
226 233 ▶ my $self = shift;
Subroutine DESTROY: called CC=2 SCAR=6.9
227 233 ▶ CORE::chdir($self->chdir_from)
Branch: 1 branch
BranchTrueFalseTotal
if $self->chdir_from 1 232 233
228 if $self->chdir_from;
229 # $self->SUPER::DESTROY(@_);
230 }
231  
232 #===============================================================================
233 sub _overload_table {
234 (
235 4 ▶ '${} dir' => '_overload_as_scalar',
Subroutine _overload_table: called CC=1 SCAR=0.0
236 '@{} dir' => '_overload_as_array',
237 '%{} dir' => '_overload_as_hash',
238 )
239 }
240  
241 sub _overload_as_scalar {
242 1 ▶ \ $_[1];
Subroutine _overload_as_scalar: called CC=1 SCAR=0.0
243 }
244  
245 sub _overload_as_array {
246 1 ▶ [ $_[1]->all ];
Subroutine _overload_as_array: called CC=1 SCAR=0.0
247 }
248  
249 sub _overload_as_hash {
250 +{
251 map {
252 2 ▶ (my $name = $_->pathname) =~ s/.*[\/\\]//;
Subroutine _overload_as_hash: called CC=1 SCAR=0.0
253 10 ($name, $_);
254 } $_[1]->all
255 };
256 }
257  
258 17 1;
« All/Socket.pm ↑ Summary All/Base.pm »