Toader/Render/AutoDoc/Cleanup.pm

filter: Statementstmt 17.1% 17 / 99 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 2 / 2 totaltotal 17.9% 24 / 134 CC 14 SCAR 39.8
CC
14
Cov
14%
cleanup
90.0
new
42.0
BEGIN
1.0
CRAP 53.4
« Toader/findToaderRoot.pm ↑ Summary Toader/Render/Directory/backends/pod.pm »
1 package Toader::Render::AutoDoc::Cleanup;
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 base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Toader::pathHelper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use File::Path qw(remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Toader::Render::AutoDoc::Cleanup - This is used for cleaning up the output directory prior to rendering.
12  
13 =head1 VERSION
14  
15 Version 0.1.0
16  
17 =cut
18  
19 2 our $VERSION = '0.1.0';
20  
21 =head1 SYNOPSIS
22  
23 =head1 METHODS
24  
25 =head2 new
26  
27 This initiates the object.
28  
29 One argument is required and it is a L<Toader> object.
30  
31 my $foo=Toader::Render::AutoDoc::Cleanup->new($toader);
32 if($foo->error){
33 warn('error: '.$foo->error.":".$foo->errorString);
34 }
35  
36 =cut
37  
38 0 ▶sub new{
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
39 0 my $toader=$_[1];
40  
41 0 my $self={
42 error=>undef,
43 errorString=>'',
44 perror=>undef,
45 errorExtra=>{
46 flags=>{
47 1=>'noToaderObj',
48 2=>'notAtoaderObj',
49 3=>'toaderPerror',
50 4=>'notApageObj',
51 5=>'noObj',
52 6=>'noOutputdirSet',
53 7=>'outputDirDoesNotExist',
54 8=>'objPerror',
55 9=>'noDirSet',
56 10=>'pathhelperErrored',
57 11=>'autodocsDirCleanupFailed',
58 },
59 },
60 };
61 0 bless $self;
62  
63 #make sure something passed to this method
64 0 ▶ if ( ! defined( $toader ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toader) 0 0 0
65 0 $self->{error}=1;
66 0 $self->{errorString}='No Toader object passed';
67 0 $self->{perror}=1;
68 0 $self->warn;
69 0 return $self;
70 }
71  
72 #makes sure the object passed is a Toader object
73 0 ▶ if ( ref( $toader ) ne 'Toader' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $toader ne "Toader") 0 0 0
74 0 $self->{error}=2;
75 0 $self->{errorString}='The passed object is not a Toader object, but a "'
76 .ref( $toader ).'"';
77 0 $self->{perror}=1;
78 0 $self->warn;
79 0 return $self;
80 }
81  
82 #makes sure the toader object is not in a permanent error state
83 0 $toader->errorblank;
84 0 ▶ if ( $toader->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($toader->error) 0 0 0
85 0 $self->{perror}=1;
86 0 $self->{error}=3;
87 0 $self->{errorString}='The Toader object passed has a permanent error set. error="'.
88 $toader->error.'" errorString="'.$toader->errorString.'"';
89 0 $self->warn;
90 0 return $self;
91 }
92  
93 0 $self->{toader}=$toader;
94  
95 #makes sure a output directory is set
96 0 my $outputdir=$self->{toader}->getOutputDir;
97 0 ▶ if( ! defined( $outputdir ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $outputdir) 0 0 0
98 0 $self->{error}=6;
99 0 $self->{errorString}='The Toader object has not had a output directory set';
100 0 $self->warn;
101 0 return undef;
102 }
103 0 $self->{outputdir}=$outputdir;
104  
105 #make sure the output directory exists
106 0 ▶ if( ! -d $outputdir ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $outputdir) 0 0 0
107 0 $self->{error}=7;
108 0 $self->{errorString}='The output directory does not exist or does not appear to be a directory';
109 0 $self->warn;
110 0 return undef;
111 }
112  
113 #gets the pathhelper for later usage
114 0 $self->{pathhelper}=$self->{toader}->getPathHelper;
115  
116 0 return $self;
117 }
118  
119 =head2 cleanup
120  
121 This cleans up the output directory for a specified object.
122  
123 One argument is taken and that is the object to be cleaned from
124 the output directory.
125  
126 $foo->cleanup( $obj );
127 if($foo->error){
128 warn('error: '.$foo->error.":".$foo->errorString);
129 }
130  
131 =cut
132  
133 0 ▶sub cleanup{
Subroutine cleanup: not called CC=9 SCAR=45.0
Pod documented
134 0 my $self=$_[0];
135 0 my $obj=$_[1];
136  
137 0 ▶ if (!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
138 0 return undef;
139 }
140  
141 #make sure a object was passed
142 0 ▶ if ( ! defined( $obj ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 0 0 0
143 0 $self->{error}=5;
144 0 $self->{errorString}='No object passed';
145 0 $self->warn;
146 0 return $self;
147 }
148  
149 #make sure it is a supported type
150 0 ▶ if ( ref( $obj ) ne 'Toader::AutoDoc' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obj ne "Toader::AutoDoc") 0 0 0
151 0 $self->{error}=4;
152 0 $self->{errorString}='"'.ref( $obj ).'" is not a supported object type';
153 0 $self->warn;
154 0 return $self;
155 }
156  
157 #make sure a permanent error is not set
158 0 $obj->errorblank;
159 0 ▶ if( $obj->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->error) 0 0 0
160 0 $self->{error}=8;
161 0 $self->{errorString}='The object error has a permanent error set. error="'
162 .$obj->error.'" errorString="'.$obj->errorString.'"';
163 0 $self->warn;
164 0 return undef;
165 }
166  
167 #gets the directory
168 0 my $dir=$obj->dirGet;
169 0 ▶ if ( ! defined( $dir ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
170 0 $self->{error}=9;
171 0 $self->{errorString}='The object has not had a directory set for it';
172 0 $self->warn;
173 0 return undef;
174 }
175  
176 #puts together the base directory
177 0 $dir=$self->{outputdir}.'/'.$self->{pathhelper}->relative2root($dir).'/';
178 0 ▶ if( $self->{pathhelper}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"pathhelper"}->error) 0 0 0
179 0 $self->{error}=10;
180 $self->{errorString}='Toader::pathHelper errored. error="'.
181 $self->{pathhelper}->error.'" errorString="'.
182 0 $self->{pathhelper}->errorString.'"';
183 0 $self->warn;
184 0 return undef;
185 }
186 0 $dir=$dir.'.autodoc/';
187  
188 #if the directory does not exist, there is nothing to clean up
189 0 ▶ if ( ! -e $dir ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dir) 0 0 0
190 0 return 1;
191 }
192  
193 #remove it
194 0 my $err;
195 0 remove_tree( $dir, { error=>\$err } );
196 0 my @errors=@{ $err };
197 0 ▶ if ( defined( $errors[0] ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $errors[0]) 0 0 0
198 0 $self->{error}=11;
199 0 $self->{errorString}='Failed to remove "'.$dir.'"';
200 0 $self->warn;
201 0 return undef;
202 }
203  
204 0 return 1;
205 }
206  
207 =head1 ERROR CODES
208  
209 =head2 1, noToaderObj
210  
211 No L<Toader> object passed.
212  
213 =head2 2, notAtoaderObj
214  
215 The passed object is not a L<Toader> object.
216  
217 =head2 3, toaderPerror
218  
219 The L<Toader> object passed has a permanent error set.
220  
221 =head2 4, notApageObj
222  
223 The passed object is not a L<Toader::Page> object.
224  
225 =head2 5, noObj
226  
227 No object passed.
228  
229 =head2 6, noOutputDirSet
230  
231 The L<Toader> object has not had a output directory set.
232  
233 =head2 7, outputDirDoesNotExist
234  
235 The output directory does not appear to exist or is not a directory.
236  
237 =head2 8, objPerror
238  
239 The object has a permanent error set.
240  
241 =head2 9, noDirSet
242  
243 The object has not had a directory set for it.
244  
245 =head2 10, pathhelperErrored
246  
247 L<Toader::pathHelper> errored.
248  
249 =head2 11, autodocsDirCleanupFailed
250  
251 Failed to clean the autodocs directory.
252  
253 =head1 AUTHOR
254  
255 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
256  
257 =head1 BUGS
258  
259 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
260 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll
261 automatically be notified of progress on your bug as I make changes.
262  
263  
264  
265  
266 =head1 SUPPORT
267  
268 You can find documentation for this module with the perldoc command.
269  
270 perldoc Toader::Render::Page::Cleanup
271  
272 You can also look for information at:
273  
274 =over 4
275  
276 =item * RT: CPAN's request tracker
277  
278 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
279  
280 =item * AnnoCPAN: Annotated CPAN documentation
281  
282 L<http://annocpan.org/dist/Toader>
283  
284 =item * CPAN Ratings
285  
286 L<http://cpanratings.perl.org/d/Toader>
287  
288 =item * Search CPAN
289  
290 L<http://search.cpan.org/dist/Toader/>
291  
292 =back
293  
294  
295 =head1 ACKNOWLEDGEMENTS
296  
297  
298 =head1 LICENSE AND COPYRIGHT
299  
300 Copyright 2013. Zane C. Bowers-Hadley.
301  
302 This program is free software; you can redistribute it and/or modify it
303 under the terms of either: the GNU General Public License as published
304 by the Free Software Foundation; or the Artistic License.
305  
306 See http://dev.perl.org/licenses/ for more information.
307  
308 =cut
309  
310 2 1; # End of Toader::Render::Page::Cleanup
« Toader/findToaderRoot.pm ↑ Summary Toader/Render/Directory/backends/pod.pm »