Toader/findToaderDirs.pm

filter: Statementstmt 14.7% 14 / 95 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 14.3% 21 / 146 CC 19 SCAR 45.1
CC
19
Cov
11%
findToaderSubDirs
132.0
findToaderDirs
90.0
new
2.0
CRAP 90.7
« Toader/Render/Entry.pm ↑ Summary Toader/VCS.pm »
1 package Toader::findToaderDirs;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Toader::isaToaderDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Toader::findToaderDirs - Finds all Toader directories under a specified Toader directory.
11  
12 =head1 VERSION
13  
14 Version 0.1.0
15  
16 =cut
17  
18 1 our $VERSION = '0.1.0';
19  
20 =head1 SYNOPSIS
21  
22 use Toader::findToaderDirs;
23  
24 my $foo = Toader::findToaderDirs->new();
25  
26 my @dirs=$foo->findToaderDirs($directory);
27 if($foo->error){
28 warn('Error '.$foo->error.': '.$foo->errorString);
29 }else{
30 print join("\n", @dirs)."\n";
31 }
32  
33 =head1 METHODS
34  
35 =head2 new
36  
37 This initiates the object.
38  
39 my $foo = Toader::findToaderDirs->new();
40  
41 =cut
42  
43 0 ▶sub new{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
44 0 my $self={
45 error=>undef,
46 errorString=>'',
47 isatd=>Toader::isaToaderDir->new,
48 errorExtra=>{
49 flags=>{
50 1=>'noDirSpecified',
51 2=>'notAdir',
52 3=>'notAtoaderDir',
53 4=>'isaToaderDirErrored',
54 5=>'rootIsAtoaderDir',
55 6=>'dirOpenFailed',
56 },
57 },
58 };
59 0 bless $self;
60  
61 0 return $self;
62 }
63  
64 =head2 findToaderDirs
65  
66 This returns all found L<Toader> directories under the path.
67  
68 One argument is taken and it a L<Toader> directory.
69  
70 The returned array will also include the one it started in.
71  
72 my @dirs=$foo->findToaderDirs($directory);
73 if($foo->error){
74 warn('Error '.$foo->error.': '.$foo->errorString);
75 }else{
76 print join("\n", @dirs)."\n";
77 }
78  
79 =cut
80  
81 0 ▶sub findToaderDirs{
Subroutine findToaderDirs: not called CC=9 SCAR=45.0
Pod documented
82 0 my $self=$_[0];
83 0 my $dir=$_[1];
84 0 my $recursive=$_[2];
85  
86 #blank any previous errors
87 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
88 0 return undef;
89 }
90  
91 # Makes sure a directory is specified.
92 0 ▶ if (!defined( $dir )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
93 0 $self->{error}=1;
94 0 $self->{errorString}='No directory defined';
95 0 $self->warn;
96 0 return undef;
97 }
98  
99 # Make sure the what is a directory.
100 0 ▶ if (! -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
101 0 $self->{error}=2;
102 0 $self->{errorString}='The specified item is not a directory';
103 0 $self->warn;
104 0 return undef;
105 }
106  
107 #make sure the directory we were passed is a Toader directory
108 0 my $returned=$self->{isatd}->isaToaderDir($dir);
109 0 ▶ if ($self->{isatd}->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"isatd"}->error) 0 0 0
110 0 $self->{error}=4;
111 0 $self->{errorString}='isaToaderDir returned "'.$self->{isatd}->error.'", "'.$self->{isatd}->errorString.'"';
112 0 $self->warn;
113 0 return undef;
114 }
115 0 ▶ if (!$returned) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($returned) 0 0 0
116 0 $self->{error}=3;
117 0 $self->{errorString}='"'.$dir.'" is not a Toader directory';
118 0 $self->warn;
119 0 return undef;
120 }
121  
122 #this returns a list of found directories
123 0 my @dirs;
124  
125 #gets the subdirs to start
126 0 my @sdirs=$self->findToaderSubDirs($dir);
127  
128 #puts together the first one
129 0 my $int=0;
130 0 ▶ while( defined( $sdirs[$int] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sdirs[$int]) 0 0 0
131 0 push( @dirs, $dir.'/'.$sdirs[$int] );
132  
133 0 $int++;
134 }
135 #prevents duplicates
136 0 ▶ if( ! $recursive ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($recursive) 0 0 0
137 0 push(@dirs, $dir);
138 }
139  
140 #process each subdir
141 0 $int=0;
142 0 ▶ while( defined( $sdirs[$int] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sdirs[$int]) 0 0 0
143 0 my $newdir=$dir.'/'.$sdirs[$int];
144  
145 #set the recursive arg to true as we don't want to add it twice
146 0 my @newdirs=$self->findToaderDirs( $newdir, '1' );
147
148 0 push( @dirs, @newdirs );
149  
150 0 $int++;
151 }
152  
153 0 return @dirs;
154 }
155  
156 =head2 findToaderSubDirs
157  
158 This lists all sub L<Toader> directories under a specified L<Toader> directory.
159  
160 This only returns the found directory names under the directory.
161  
162 my @sub=$foo->findToaderSubDirs($dir);
163 if($foo->error){
164 warn('Error '.$foo->error.': '.$foo->errorString);
165 }else{
166 print join("\n", @dirs)."\n";
167 }
168  
169 =cut
170  
171 0 ▶sub findToaderSubDirs{
Subroutine findToaderSubDirs: not called CC=11 SCAR=48.8
Pod documented
172 0 my $self=$_[0];
173 0 my $dir=$_[1];
174  
175 #blank any previous errors
176 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
177 0 return undef;
178 }
179  
180 # Makes sure a directory is specified.
181 0 ▶ if (!defined( $dir )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
182 0 $self->{error}=1;
183 0 $self->{errorString}='No directory defined';
184 0 $self->warn;
185 0 return undef;
186 }
187  
188 # Make sure the what is a directory.
189 0 ▶ if (! -d $dir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
190 0 $self->{error}=2;
191 0 $self->{errorString}='The specified item is not a directory';
192 0 $self->warn;
193 0 return undef;
194 }
195  
196 #initiates the directory checker
197 0 my $isatd=Toader::isaToaderDir->new;
198  
199 #make sure the directory we were passed is a Toader directory
200 0 my $returned=$isatd->isaToaderDir($dir);
201 0 ▶ if ($isatd->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isatd->error) 0 0 0
202 0 $self->{error}=4;
203 0 $self->{errorString}='isaToaderDir returned "'.$isatd->error.'", "'.$isatd->errorString.'"';
204 0 $self->warn;
205 0 return undef;
206 }
207 0 ▶ if (!$returned) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($returned) 0 0 0
208 0 $self->{error}=3;
209 0 $self->{errorString}='"'.$dir.'" is not a Toader directory';
210 0 $self->warn;
211 0 return undef;
212 }
213  
214 0 my @dirs;
215  
216 #opens the directory handle
217 my $dh;
218 0 ▶ if(!opendir($dh,$dir)){
Branch: 1 branch
BranchTrueFalseTotal
unless (opendir $dh, $dir) 0 0 0
219 0 $self->{error}=6;
220 0 $self->{errorString}='Unable to open the specified directory';
221 0 $self->warn;
222 0 return undef;
223 }
224 #process each item
225 0 ▶ while(readdir($dh)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readdir $dh)) 0 0 0
226 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($_ ne "." and $_ ne ".." and -d $dir . '/' . $_ . '/.toader') 0 0 0
Condition0%0/6
$_ ne "." and $_ ne ".." and -d $dir . '/' . $_ . '/.toader'
!ll&&!rl&&r
000
$_ ne "." and $_ ne ".."
!ll&&!rl&&r
000
MC/DC0%0/3
$_ ne "." and $_ ne ".." and -d $dir . '/' . $_ . '/.toader'
$_ ne "." $_ ne ".." -d $dir . '/' . $_ . '/.toader'
Truth table0%0/4
A and B and C
A= $_ ne "."B= $_ ne ".."C= -d $dir . '/' . $_ . '/.toader'
ABCresult
0XX0
10X0
1100
1111
227 ( $_ ne '.' ) &&
228 ( $_ ne '..' ) &&
229 ( -d $dir.'/'.$_.'/.toader' )
230 ) {
231 0 push(@dirs, $_);
232 }
233 }
234 #done with the directory handle
235 0 closedir($dh);
236  
237 0 return @dirs;
238 }
239  
240 =head1 ERROR CODES
241  
242 =head2 1, noDirSpecified
243  
244 No directory specified.
245  
246 =head2 2, notAdir
247  
248 Not a directory.
249  
250 =head2 3, notAtoaderDir
251  
252 Not a L<Toader> directory.
253  
254 =head2 4, isaToaderDirErrored
255  
256 L<Toader::isaToaderDir>->isaToaderDir errored.
257  
258 =head2 5, rootIsAtoaderDir
259  
260 "/" is the directory and it appears to be a L<Toader> directory.
261  
262 This is a major WTF and should not be even if '/.toader' exists.
263  
264 =head2 6, dirOpenFailed
265  
266 Could not open one of the directories.
267  
268 =head1 AUTHOR
269  
270 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
271  
272 =head1 BUGS
273  
274 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
275 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll
276 automatically be notified of progress on your bug as I make changes.
277  
278 =head1 SUPPORT
279  
280 You can find documentation for this module with the perldoc command.
281  
282 perldoc Toader::findToaderDirs
283  
284  
285 You can also look for information at:
286  
287 =over 4
288  
289 =item * RT: CPAN's request tracker
290  
291 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
292  
293 =item * AnnoCPAN: Annotated CPAN documentation
294  
295 L<http://annocpan.org/dist/Toader>
296  
297 =item * CPAN Ratings
298  
299 L<http://cpanratings.perl.org/d/Toader>
300  
301 =item * Search CPAN
302  
303 L<http://search.cpan.org/dist/Toader/>
304  
305 =back
306  
307  
308 =head1 ACKNOWLEDGEMENTS
309  
310  
311 =head1 LICENSE AND COPYRIGHT
312  
313 Copyright 2013 Zane C. Bowers-Hadley.
314  
315 This program is free software; you can redistribute it and/or modify it
316 under the terms of either: the GNU General Public License as published
317 by the Free Software Foundation; or the Artistic License.
318  
319 See http://dev.perl.org/licenses/ for more information.
320  
321  
322 =cut
323  
324 1 1; # End of Toader::findToaderDirs
« Toader/Render/Entry.pm ↑ Summary Toader/VCS.pm »