blib/lib/POD/Walker.pm

filter: Statementstmt 17.4% 26 / 149 Branchbran 0.0% 0 / 90 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 13.5% 36 / 266 CC 49 SCAR 67.8
CC
49
Cov
10%
process
1332.0
run
210.0
BEGIN
1.0
CRAP 877.6
↑ Summary
1 package POD::Walker;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Script::isAperlScript;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Pod::Html;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Pod::LaTeX;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Pod::Man;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Pod::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 POD::Walker - Walks a directory and runs any Perl files through the specified POD converter.
15  
16 =head1 VERSION
17  
18 Version 0.0.0
19  
20 =cut
21  
22 2 our $VERSION = '0.0.0';
23  
24  
25 =head1 SYNOPSIS
26  
27 use POD::Walker;
28 my $returned=POD::Walker->run({in=>"/input/path", out=>"/output/path", format=>"html" });
29 if($returned->{error}){
30 print "Error: ".$returned->{error}."\n";
31 }
32  
33 =head1 FUNCTION
34  
35 =head2 run
36  
37 Process a directory try and ignore any hidden directories or files.
38  
39 The returned value is a hash. See the section "RETURN HASH" for more information.
40  
41 =head3 args hash ref
42  
43 =head4 changesCopy
44  
45 This copies any "Changes" files.
46  
47 This defaults to "1".
48  
49 =head4 in
50  
51 The directory to start in.
52  
53 =head4 format
54  
55 The output type. This can be any of the ones listed below.
56  
57 html
58 latex
59 man
60 text
61  
62 If one is not specified, 'html' will be used.
63  
64 =head4 manifestCopy
65  
66 This copies any "MANIFEST" files.
67  
68 This defaults to "1".
69  
70 =head4 readmeCopy
71  
72 This copies any "README" files.
73  
74 This defaults to "1".
75  
76 =head4 out
77  
78 This is the directory to output to.
79  
80 =cut
81  
82 0 ▶sub run{
Subroutine run: not called CC=14 SCAR=53.5
Pod documented
83 #make sure we have something passed to us
84 0 ▶ if (!defined($_[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[1]) 0 0 0
85 0 return {error=>1};
86 }
87 0 my %args=%{$_[1]};
88  
89 #make sure all arguements are defined
90 0 ▶ if (!defined($args{in})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"in"}) 0 0 0
91 0 return {error=>2};
92 }
93 0 ▶ if (!defined($args{out})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"out"}) 0 0 0
94 0 return {error=>3};
95 }
96 0 ▶ if (!defined($args{format})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"format"}) 0 0 0
97 0 $args{format}='html';
98 }
99  
100 #make sure the input directory is usable
101 0 ▶ if (! -d $args{in}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $args{"in"}) 0 0 0
102 0 return {error=>4};
103 }
104 0 ▶ if (! -r $args{in}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $args{"in"}) 0 0 0
105 0 return {error=>5};
106 }
107  
108 #make sure the output directory is usable
109 0 ▶ if (! -d $args{out}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $args{"out"}) 0 0 0
110 0 ▶ if (!mkdir($args{out})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (mkdir $args{"out"}) 0 0 0
111 0 return {error=>6};
112 }
113 }
114 0 ▶ if (! -w $args{out}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $args{"out"}) 0 0 0
115 0 return {error=>7};
116 }
117 0 ▶ if (! -w $args{out}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $args{"out"}) 0 0 0
118 0 return {error=>8};
119 }
120  
121 #default to 1 for MANIFEST copying
122 0 ▶ if (!defined( $args{manifestCopy} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"manifestCopy"}) 0 0 0
123 0 $args{manifestCopy}=1;
124 }
125  
126 #default to 1 for README copying
127 0 ▶ if (!defined( $args{readmeCopy} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"readmeCopy"}) 0 0 0
128 0 $args{readmeCopy}=1;
129 }
130  
131 #default to 1 for Changes copying
132 0 ▶ if (!defined( $args{changesCopy} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"changesCopy"}) 0 0 0
133 0 $args{changesCopy}=1;
134 }
135  
136 #starts processing and returns it
137 0 return process(\%args);
138 }
139  
140 =head2 process
141  
142 This is a internal function.
143  
144 =cut
145  
146 0 ▶sub process{
Subroutine process: not called CC=36 SCAR=71.9
Pod documented
147 0 my %args=%{$_[0]};
148  
149 #inits the return value
150 0 my %toreturn;
151 0 $toreturn{error}=undef;
152  
153 #holds any thing that errored
154 0 my @errored;
155  
156 #make sure all arguements are defined
157 0 ▶ if (!defined($args{in})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"in"}) 0 0 0
158 0 $toreturn{errored}=\@errored;
159 0 $toreturn{error}=2;
160 0 return \%toreturn;
161 }
162 0 ▶ if (!defined($args{out})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"out"}) 0 0 0
163 0 $toreturn{errored}=\@errored;
164 0 $toreturn{error}=3;
165 0 return \%toreturn;
166 }
167 0 ▶ if (!defined($args{format})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"format"}) 0 0 0
168 0 $args{format}='html';
169 }
170  
171 #make sure the input directory is usable
172 0 ▶ if (! -d $args{in}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $args{"in"}) 0 0 0
173 0 $toreturn{errored}=\@errored;
174 0 $toreturn{error}=4;
175 0 return \%toreturn;
176 }
177 0 ▶ if (! -r $args{in}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $args{"in"}) 0 0 0
178 0 $toreturn{errored}=\@errored;
179 0 $toreturn{error}=5;
180 0 return \%toreturn;
181 }
182  
183 #make sure the output directory is usable
184 0 ▶ if (! -d $args{out}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $args{"out"}) 0 0 0
185 0 ▶ if (!mkdir($args{out})){
Branch: 1 branch
BranchTrueFalseTotal
unless (mkdir $args{"out"}) 0 0 0
186 0 $toreturn{errored}=\@errored;
187 0 $toreturn{error}=6;
188 0 return \%toreturn;
189 }
190 }
191 0 ▶ if (! -w $args{out}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $args{"out"}) 0 0 0
192 0 $toreturn{errored}=\@errored;
193 0 $toreturn{error}=7;
194 0 return \%toreturn;
195 }
196 0 ▶ if (! -w $args{out}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-w $args{"out"}) 0 0 0
197 0 $toreturn{errored}=\@errored;
198 0 $toreturn{error}=8;
199 0 return \%toreturn;
200 }
201  
202 #processes the input directory
203 0 my $dir;
204 0 ▶ if (opendir($dir, $args{in})) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir $dir, $args{'in'}) { } 0 0 0
205 #removes hidden files/directories
206 0 my @dirEntries=grep(!/^\./ , readdir($dir));
207 0 closedir($dir);
208  
209 #process each entry
210 0 my $int=0;
211 0 ▶ while (defined( $dirEntries[$int] )) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dirEntries[$int]) 0 0 0
212 0 my %newArgs=%args;
213 0 $newArgs{in}=$args{in}.'/'.$dirEntries[$int];
214 0 $newArgs{out}=$args{out}.'/'.$dirEntries[$int];
215
216 #The directory and file stuff like this is split to simplify handling odd stuff the path in question.
217 #handles directories
218 0 ▶ if (-d $newArgs{in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $newArgs{"in"}) 0 0 0
219 #process it if it was a directory
220 0 my $returned=process(\%newArgs);
221 #push what failed onto the list, if needed
222 0 ▶ if ($returned->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($returned->{"error"}) 0 0 0
223 0 my @errors=@{$returned->{errored}};
224  
225 0 print $returned->{error}." ".$newArgs{in}."\n";
226  
227 0 push(@errored, @errors);
228 0 push(@errored, $newArgs{in});
229 }
230 }
231 #handles files
232 0 ▶ if (-f $newArgs{in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $newArgs{"in"}) 0 0 0
233 #we don't process a file by default
234 0 my $process=0;
235  
236 #checks if we should process a file
237 0 ▶ if ( $newArgs{in} =~ /\.[Pp][Mm]$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newArgs{"in"} =~ /\.[Pp][Mm]$/) 0 0 0
238 0 $process=1;
239 }
240 0 ▶ if ( ( $newArgs{in} =~ /\.[Pp][Ll]$/ ) && (!$process) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newArgs{"in"} =~ /\.[Pp][Ll]$/ and not $process) 0 0 0
Condition0%0/3
$newArgs{"in"} =~ /\.[Pp][Ll]$/ and not $process
!ll&&!rl&&r
000
MC/DC0%0/2
$newArgs{"in"} =~ /\.[Pp][Ll]$/ and not $process
$newArgs{"in"} =~ /\.[Pp][Ll]$/ not $process
Truth table0%0/3
A and not(B)
A= $newArgs{"in"} =~ /\.[Pp][Ll]$/B= not $process
ABresult
0X0
100
111
241 0 $process=1;
242 }
243 0 ▶ if ( ( $newArgs{in} =~ /\.[Pp][Oo][Dd]$/ ) && (!$process) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newArgs{"in"} =~ /\.[Pp][Oo][Dd]$/ and not $process) 0 0 0
Condition0%0/3
$newArgs{"in"} =~ /\.[Pp][Oo][Dd]$/ and not $process
!ll&&!rl&&r
000
MC/DC0%0/2
$newArgs{"in"} =~ /\.[Pp][Oo][Dd]$/ and not $process
$newArgs{"in"} =~ /\.[Pp][Oo][Dd]$/ not $process
Truth table0%0/3
A and not(B)
A= $newArgs{"in"} =~ /\.[Pp][Oo][Dd]$/B= not $process
ABresult
0X0
100
111
244 0 $process=1;
245 }
246 0 ▶ if ( ( -x $newArgs{in} ) && (!$process) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-x $newArgs{"in"} and not $process) 0 0 0
Condition0%0/3
-x $newArgs{"in"} and not $process
!ll&&!rl&&r
000
MC/DC0%0/2
-x $newArgs{"in"} and not $process
-x $newArgs{"in"} not $process
Truth table0%0/3
A and not(B)
A= -x $newArgs{"in"}B= not $process
ABresult
0X0
100
111
247 0 ▶ if ( !isAperlScript( $newArgs{in} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (isAperlScript($newArgs{"in"})) 0 0 0
248 0 $process=1;
249 }
250 }
251  
252 #handles it if it is one of the copy types
253 0 ▶ if ($dirEntries[$int] eq "Changes") {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirEntries[$int] eq "Changes") 0 0 0
254 0 ▶ if ($args{changesCopy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"changesCopy"}) 0 0 0
255 0 copy($newArgs{in}, $newArgs{out});
256 }
257 }
258 0 ▶ if ($dirEntries[$int] eq "README") {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirEntries[$int] eq "README") 0 0 0
259 0 ▶ if ($args{readmeCopy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"readmeCopy"}) 0 0 0
260 0 copy($newArgs{in}, $newArgs{out});
261 }
262 }
263 0 ▶ if ($dirEntries[$int] eq "MANIFEST") {
Branch: 1 branch
BranchTrueFalseTotal
if ($dirEntries[$int] eq "MANIFEST") 0 0 0
264 0 ▶ if ($args{manifestCopy}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"manifestCopy"}) 0 0 0
265 0 copy($newArgs{in}, $newArgs{out});
266 }
267 }
268  
269 #process a file if needed
270 0 ▶ if ($process) {
Branch: 1 branch
BranchTrueFalseTotal
if ($process) 0 0 0
271 0 ▶ if ($args{format} eq "html") {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"format"} eq "html") 0 0 0
272 0 pod2html("--flush", "--infile=".$newArgs{in}, "--outfile=".$newArgs{out}.".html");
273 0 ▶ if (-f "pod2htmd.tmp") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "pod2htmd.tmp") 0 0 0
274 0 unlink("pod2htmd.tmp");
275 }
276 0 ▶ if (-f "pod2htmi.tmp") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "pod2htmi.tmp") 0 0 0
277 0 unlink("pod2htmi.tmp");
278 }
279 }
280  
281 0 ▶ if ($args{format} eq "latex") {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"format"} eq "latex") 0 0 0
282 0 my $parser = Pod::LaTeX->new;
283 0 $parser->parse_from_file ($newArgs{in}, $newArgs{out}.".latex");
284 }
285  
286 0 ▶ if ($args{format} eq "man") {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"format"} eq "man") 0 0 0
287 0 my $parser = Pod::Man->new;
288 0 $parser->parse_from_file ($newArgs{in}, $newArgs{out}.".man");
289 }
290  
291 0 ▶ if ($args{format} eq "text") {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"format"} eq "text") 0 0 0
292 0 my $parser = Pod::Text->new;
293 0 $parser->parse_from_file ($newArgs{in}, $newArgs{out}.".text");
294 }
295  
296 }
297  
298 }
299  
300 0 $int++;
301 }
302  
303 }else {
304 0 $toreturn{errored}=\@errored;
305 0 $toreturn{error}=9;
306 0 return \%toreturn;
307 }
308  
309 0 $toreturn{errored}=\@errored;
310  
311 0 return \%toreturn;
312 }
313  
314 =head1 RETURN HASH
315  
316 =head2 error
317  
318 This integer represents if there is a error or note.
319  
320 This is set to true if there was an error is set to a
321 integet greater than or equal to "1".
322  
323 =head3 error codes
324  
325 =head4 1
326  
327 No arguements passed.
328  
329 =head4 2
330  
331 No in directory specified.
332  
333 =head4 3
334  
335 No in directory specified.
336  
337 =head4 4
338  
339 The input directory does not exist or is not a directory.
340  
341 =head4 5
342  
343 The input directory is not readable.
344  
345 =head4 6
346  
347 The specified outpbut directory does not exist, is is not
348 a directory, or could not be created.
349  
350 =head4 7
351  
352 The output directory is not readable.
353  
354 =head4 8
355  
356 The output directory is not writable.
357  
358 =head4 9
359  
360 Failed to open the input directory.
361  
362 =head2 errored
363  
364 This contains a list of files or directories that could not be processed.
365  
366 =head1 AUTHOR
367  
368 Zane C. Bowers, C<< <vvelox at vvelox.net> >>
369  
370 =head1 BUGS
371  
372 Please report any bugs or feature requests to C<bug-pod-walker at rt.cpan.org>, or through
373 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POD-Walker>. I will be notified, and then you'll
374 automatically be notified of progress on your bug as I make changes.
375  
376  
377  
378  
379 =head1 SUPPORT
380  
381 You can find documentation for this module with the perldoc command.
382  
383 perldoc POD::Walker
384  
385  
386 You can also look for information at:
387  
388 =over 4
389  
390 =item * RT: CPAN's request tracker
391  
392 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POD-Walker>
393  
394 =item * AnnoCPAN: Annotated CPAN documentation
395  
396 L<http://annocpan.org/dist/POD-Walker>
397  
398 =item * CPAN Ratings
399  
400 L<http://cpanratings.perl.org/d/POD-Walker>
401  
402 =item * Search CPAN
403  
404 L<http://search.cpan.org/dist/POD-Walker/>
405  
406 =back
407  
408  
409 =head1 ACKNOWLEDGEMENTS
410  
411  
412 =head1 COPYRIGHT & LICENSE
413  
414 Copyright 2010 Zane C. Bowers, all rights reserved.
415  
416 This program is free software; you can redistribute it and/or modify it
417 under the same terms as Perl itself.
418  
419  
420 =cut
421  
422 2 1; # End of POD::Walker
↑ Summary