line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Toader::findToaderDirs; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20792
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
5
|
1
|
|
|
1
|
|
502
|
use Toader::isaToaderDir; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
6
|
1
|
|
|
1
|
|
6
|
use base 'Error::Helper'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
801
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new{ |
44
|
0
|
|
|
0
|
1
|
|
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 directories under the path. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
One argument is taken and it a L 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
|
|
|
|
|
|
|
sub findToaderDirs{ |
82
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
83
|
0
|
|
|
|
|
|
my $dir=$_[1]; |
84
|
0
|
|
|
|
|
|
my $recursive=$_[2]; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#blank any previous errors |
87
|
0
|
0
|
|
|
|
|
if(!$self->errorblank){ |
88
|
0
|
|
|
|
|
|
return undef; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# Makes sure a directory is specified. |
92
|
0
|
0
|
|
|
|
|
if (!defined( $dir )) { |
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
|
0
|
|
|
|
|
if (! -d $dir ) { |
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
|
0
|
|
|
|
|
if ($self->{isatd}->error) { |
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
|
0
|
|
|
|
|
if (!$returned) { |
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] ) ){ |
131
|
0
|
|
|
|
|
|
push( @dirs, $dir.'/'.$sdirs[$int] ); |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$int++; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
#prevents duplicates |
136
|
0
|
0
|
|
|
|
|
if( ! $recursive ){ |
137
|
0
|
|
|
|
|
|
push(@dirs, $dir); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
#process each subdir |
141
|
0
|
|
|
|
|
|
$int=0; |
142
|
0
|
|
|
|
|
|
while( defined( $sdirs[$int] ) ){ |
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 directories under a specified L 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
|
|
|
|
|
|
|
sub findToaderSubDirs{ |
172
|
0
|
|
|
0
|
1
|
|
my $self=$_[0]; |
173
|
0
|
|
|
|
|
|
my $dir=$_[1]; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
#blank any previous errors |
176
|
0
|
0
|
|
|
|
|
if(!$self->errorblank){ |
177
|
0
|
|
|
|
|
|
return undef; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
# Makes sure a directory is specified. |
181
|
0
|
0
|
|
|
|
|
if (!defined( $dir )) { |
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
|
0
|
|
|
|
|
if (! -d $dir ) { |
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
|
0
|
|
|
|
|
if ($isatd->error) { |
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
|
0
|
|
|
|
|
if (!$returned) { |
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
|
0
|
|
|
|
|
if(!opendir($dh,$dir)){ |
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)){ |
226
|
0
|
0
|
0
|
|
|
|
if ( |
|
|
|
0
|
|
|
|
|
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 directory. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 4, isaToaderDirErrored |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
L->isaToaderDir errored. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head2 5, rootIsAtoaderDir |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
"/" is the directory and it appears to be a L 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<< >> |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 BUGS |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
275
|
|
|
|
|
|
|
the web interface at L. 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 |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
L |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item * CPAN Ratings |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
L |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
=item * Search CPAN |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
L |
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; # End of Toader::findToaderDirs |