Toader.pm

filter: Statementstmt 21.2% 35 / 165 Branchbran 0.0% 0 / 46 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.0% 11 / 20 Podpod 100% 9 / 9 totaltotal 22.9% 55 / 240 CC 24 SCAR 39.1
CC
24
Cov
17%
new
156.0
setOutputDir
30.0
getDirObj
12.0
CRAP 49.8
« Toader/Render/Page/backends/pod.pm ↑ Summary Toader/Gallery.pm »
1 package Toader;
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 Toader::findToaderRoot;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Toader::pathHelper;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Toader::findToaderRoot;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Toader::Directory;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Sys::Hostname;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Toader::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Toader::VCS;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 Toader - A CMS meant to be integrated with a versioning system.
18  
19 =head1 VERSION
20  
21 Version 1.2.1
22  
23 =cut
24  
25 1 our $VERSION = '1.2.1';
26  
27 =head1 SYNOPSIS
28  
29 use Toader;
30  
31 my $foo = Toader->new({dir=>$toaderDir});
32 if ( $foo->error ){
33 warn('Error:'.$foo->error.': '.$foo->errorString);
34 }
35  
36 =head1 METHODS
37  
38 =head2 new
39  
40 =head3 args hash ref
41  
42 =head4 dir
43  
44 This is the directory to intiate in.
45  
46 This is required and needs to be a Toader directory.
47  
48 =head4 outputdir
49  
50 This is the output directory to use when rendering.
51  
52 my $toader=Toader->new(\%args);
53 if ( $toader->error ){
54 warn('Error:'.$toader->error.':'.$toader->errorFlag.': '.$toader->errorString);
55 }
56  
57 =cut
58  
59 0 ▶sub new{
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
60 0 my %args;
61 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
62 0 %args= %{$_[1]};
63 };
64  
65 0 my $self={
66 error=>undef,
67 errorString=>'',
68 isatd=>Toader::isaToaderDir->new,
69 perror=>undef,
70 outputdir=>undef,
71 errorExtra=>{
72 flags=>{
73 1=>'noDirSpecified',
74 2=>'isaToaderDirError',
75 3=>'notAtoaderDir',
76 4=>'outputIsAtoaderDir',
77 5=>'DirectoryInitError',
78 6=>'ConfigInitError',
79 7=>'PathHerlerInitError',
80 8=>'VCSinitError',
81 9=>'VCSusableError',
82 },
83 },
84 };
85 0 bless $self;
86  
87 #makes sure we have a directory
88 0 ▶ if (!defined( $args{dir} )) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"dir"}) 0 0 0
89 0 $self->{error}=1;
90 0 $self->{errorString}='No directory specified';
91 0 $self->warn;
92 0 return $self;
93 }
94  
95 #makes sure it is a Toader directory
96 0 my $results=$self->{isatd}->isaToaderDir($args{dir});
97 0 ▶ if ($self->{isatd}->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"isatd"}->error) 0 0 0
98 0 $self->{error}=2;
99 $self->{errorString}='$self->{isatd}->isaToaderDir($args{dir}) errored. error='.$self->{isatd}->error.
100 0 ' errorString="'.$self->{isatd}->errorString.'"';
101 0 $self->warn;
102 0 return $self;
103 }
104 0 ▶ if (!$results) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($results) 0 0 0
105 0 $self->{error}=3;
106 0 $self->{errorString}='"'.$args{dir}.'" is not a Toader directory';
107 0 $self->warn;
108 0 return $self;
109 }
110 0 $self->{dir}=$args{dir};
111  
112 #finds the Toader root
113 0 my $findroot=Toader::findToaderRoot->new;
114 0 $self->{dir}=$findroot->findToaderRoot( $self->{dir} );
115  
116 #make sure it is clean
117 0 $self->{pathHelper}=Toader::pathHelper->new( $self->{dir} );
118 0 $self->{dir}=$self->{pathHelper}->cleanup( $self->{dir} );
119  
120 #handles the output directory if specified
121 0 ▶ if( defined( $args{outputdir} ) ){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"outputdir"}) 0 0 0
122 0 $results=$self->{isatd}->isaToaderDir( $args{outputdir} );
123 0 ▶ if( $self->{isatd}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"isatd"}->error) 0 0 0
124 0 $self->{perror}=1;
125 0 $self->{error}=2;
126 $self->{errorString}='$self->{isatd}->isaToaderDir($args{outputdir}) errored. error='
127 0 .$self->{isatd}->error.' errorString="'.$self->{isatd}->errorString.'"';
128 0 $self->warn;
129 0 return $self;
130 }
131 0 ▶ if ($results) {
Branch: 1 branch
BranchTrueFalseTotal
if ($results) 0 0 0
132 0 $self->{perror}=1;
133 0 $self->{error}=4;
134 0 $self->{errorString}='"'.$args{outputdir}.'" can not be used as a out put directory'.
135 ' as it is a Toader directory';
136 0 $self->warn;
137 0 return $self;
138 }
139 0 $self->{outputdir}=$args{outputdir};
140 }
141  
142 # intialize the VCS integration
143 0 $self->{vcs}=Toader::VCS->new($self);
144 0 ▶ if ( $self->{vcs}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vcs"}->error) 0 0 0
145 0 $self->{perror}=1;
146 0 $self->{error}=8;
147 $self->{errorString}='Failed to initiate VCS. error="'.
148 0 $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"';
149 0 $self->warn;
150 0 return $self;
151 }
152 # VCS usable
153 0 $self->{VCSusable}=$self->{vcs}->usable;
154 0 ▶ if ( $self->{vcs}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"vcs"}->error) 0 0 0
155 0 $self->{perror}=1;
156 0 $self->{error}=9;
157 $self->{errorString}='Toader::VCS->usable errored. error="'.
158 0 $self->{vcs}->error.'" errorString="'.$self->{vcs}->errorString.'"';
159 0 $self->warn;
160 0 return $self;
161 }
162  
163 # initialize the config
164 0 $self->{config}=Toader::Config->new( $self );
165 0 ▶ if ( $self->{config}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"config"}->error) 0 0 0
166 0 $self->{perror}=1;
167 0 $self->{error}=6;
168 $self->{errorString}='Failed to initialize Toader::Config. error="'
169 0 .$self->{config}->error.'" errorString="'.$self->{config}->errorString.'"';
170 0 $self->warn;
171 0 return $self;
172 }
173  
174 # initialize the path helper
175 0 $self->{ph}=Toader::pathHelper->new( $self->{dir} );
176 0 ▶ if ( $self->{ph}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ph"}->error) 0 0 0
177 0 $self->{perror}=1;
178 0 $self->{error}=7;
179 $self->{errorString}='Failed to initiate pathHelper. error="'.
180 0 $self->{ph}->error.'" errorString="'.$self->{ph}->errorString.'"';
181 0 $self->warn;
182 0 return $self;
183 }
184  
185 0 return $self;
186 }
187  
188 =head2 getConfig
189  
190 This returns the L<Config::Tiny> object storing the Toader
191 config.
192  
193 There is no need to do any error checking as long as
194 Toader new suceeded with out issue.
195  
196 my $config=$toader->getConfig;
197 if ( $toader->error ){
198 warn('Error:'.$toader->error.':'.$toader->errorFlag.': '.$toader->errorString);
199 }
200  
201 =cut
202  
203 0 ▶sub getConfig{
Subroutine getConfig: not called CC=2 SCAR=17.9
Pod documented
204 0 my $self=$_[0];
205
206 #blank any previous errors
207 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
208 0 return undef;
209 }
210  
211 0 return $self->{config}->getConfig;
212 }
213  
214 =head2 getConfigObj
215  
216 This returns the L<Toader::Config> object that was created
217 when this module was created.
218  
219 my $configObj=$toader->getConfigObj;
220 if ( $toader->error ){
221 warn('Error:'.$toader->error.':'.$toader->errorFlag.': '.$toader->errorString);
222 }
223  
224 =cut
225  
226 0 ▶sub getConfigObj{
Subroutine getConfigObj: not called CC=2 SCAR=17.9
Pod documented
227 0 my $self=$_[0];
228
229 #blank any previous errors
230 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
231 0 return undef;
232 }
233  
234 0 return $self->{config};
235 }
236  
237 =head2 getDirObj
238  
239 This returns a L<Toader::Directory> object with the directory
240 set to the Toader root.
241  
242 my $dirobj=$toader->getDirObj;
243 if ( $toader->error ){
244 warn('Error:'.$toader->error.':'.$toader->errorFlag.': '.$toader->errorString);
245 }
246  
247 =cut
248  
249 0 ▶sub getDirObj{
Subroutine getDirObj: not called CC=3 SCAR=24.8
Pod documented
250 0 my $self=$_[0];
251
252 #blank any previous errors
253 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
254 0 return undef;
255 }
256  
257 0 my $dirobj=Toader::Directory->new( $self );
258  
259 0 $dirobj->dirSet( $self->{dir} );
260 0 ▶ if ( $dirobj->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($dirobj->error) 0 0 0
261 0 $self->{error}=5;
262 $self->{errorString}='Could not set the directory for the newly created '.
263 0 'Toader::Directory object to "'.$self->{dir}.'"';
264 0 $self->warn;
265 0 return undef;
266 }
267  
268 0 return $dirobj;
269 }
270  
271 =head2 getOutputDir
272  
273 This returns the output directory.
274  
275 If none is specified, undef is returned.
276  
277 There is no reason for check for errors if new
278 succeeded with out error.
279  
280 my $outputdir=$toader->getOutputDir;
281 if( defined( $outputdir ) ){
282 print "outputdir='".$outputdir."'\n";
283 }else{
284 print "No output directory defined.\n";
285 }
286  
287 =cut
288  
289 0 ▶sub getOutputDir{
Subroutine getOutputDir: not called CC=2 SCAR=17.9
Pod documented
290 0 my $self=$_[0];
291
292 #blank any previous errors
293 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
294 0 return undef;
295 }
296  
297 0 return $self->{outputdir};
298 }
299  
300 =head2 getPathHelper
301  
302 This returns a L<Toader::pathHelper> object for this Toader object.
303  
304 If the Toader object initialized with out issue, then there is no reason
305 to check for an error.
306  
307 my $pathHelper=$toader->getPathHelper;
308 if ( $toader->error ){
309 warn('Error:'.$toader->error.':'.$toader->errorFlag.': '.$toader->errorString);
310 }
311  
312 =cut
313  
314 0 ▶sub getPathHelper{
Subroutine getPathHelper: not called CC=2 SCAR=17.9
Pod documented
315 0 my $self=$_[0];
316
317 #blank any previous errors
318 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
319 0 return undef;
320 }
321  
322 0 return $self->{ph};
323 }
324  
325 =head2 getRootDir
326  
327 This returns the root directory for what Toader is using.
328  
329 If the returned value is not defined, one has not been set yet.
330  
331 my $rootdir=$toader->getRootDir;
332 if ( $foo->error ){
333 warn('Error:'.$foo->error.':'.$toader->errorFlag.': '.$foo->errorString);
334 }
335  
336 =cut
337  
338 0 ▶sub getRootDir{
Subroutine getRootDir: not called CC=2 SCAR=17.9
Pod documented
339 0 my $self=$_[0];
340 0 my $dir=$_[1];
341
342 #blank any previous errors
343 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
344 0 return undef;
345 }
346  
347 0 return $self->{dir};
348 }
349  
350 =head2 setOutputDir
351  
352 This sets the output directory.
353  
354 $foo->setOutputDir( $dir );
355 if ( $foo->error ){
356 warn('Error:'.$foo->error.':'.$toader->errorFlag.': '.$foo->errorString);
357 }
358  
359 =cut
360  
361 0 ▶sub setOutputDir{
Subroutine setOutputDir: not called CC=5 SCAR=34.0
Pod documented
362 0 my $self=$_[0];
363 0 my $dir=$_[1];
364
365 #blank any previous errors
366 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
367 0 return undef;
368 }
369  
370 #makes sure it is a directory
371 0 ▶ if ( ! defined($dir) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
372 0 $self->{error}=1;
373 0 $self->{errorString}='No directory defined';
374 0 $self->warn;
375 0 return undef;
376 }
377  
378 0 my $results=$self->{isatd}->isaToaderDir( $dir );
379 0 ▶ if( $self->{isatd}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"isatd"}->error) 0 0 0
380 0 $self->{perror}=1;
381 0 $self->{error}=2;
382 $self->{errorString}='$self->{isatd}->isaToaderDir($args{outputdir}) errored. error='
383 0 .$self->{isatd}->error.' errorString="'.$self->{isatd}->errorString.'"';
384 0 $self->warn;
385 0 return undef;
386 }
387 0 ▶ if ($results) {
Branch: 1 branch
BranchTrueFalseTotal
if ($results) 0 0 0
388 0 $self->{error}=4;
389 0 $self->{errorString}='"'.$dir.'" can not be used as a out put directory'.
390 'as it is a Toader directory';
391 0 $self->warn;
392 0 return undef;
393 }
394 0 $self->{outputdir}=$dir;
395  
396 0 return 1;
397 }
398  
399 =head2 getVCS
400  
401 This returns to the L<Toader::VCS> object.
402  
403 my $vcs=$toader->getVCS;
404 if ( $toader->error ){
405 warn('Error:'.$toader->error.':'.$toader->errorFlag.': '.$toader->errorString);
406 }
407  
408 =cut
409  
410 0 ▶sub getVCS{
Subroutine getVCS: not called CC=2 SCAR=17.9
Pod documented
411 0 my $self=$_[0];
412
413 #blank any previous errors
414 0 ▶ if(!$self->errorblank){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
415 0 return undef;
416 }
417  
418 0 return $self->{vcs};
419 }
420  
421 =head1 ERROR CODES
422  
423 =head2 1, noDirSpecified
424  
425 No directory specified.
426  
427 =head2 2, isaToaderDirError
428  
429 Toader::isaToaderDir->isaToaderDir errored.
430  
431 =head2 3, notAtoaderDir
432  
433 The specified directory is not a Toader directory.
434  
435 =head2 4, outputIsAtoaderDir
436  
437 The specified output directory is a Toader directory.
438  
439 =head2 5, DirectoryInitError
440  
441 Could initialize the L<Toader::Directory> object.
442  
443 =head2 6, ConfigInitError
444  
445 Failed to initialize L<Toader::Config>.
446  
447 =head2 7, PathHerlerInitError
448  
449 Failed to initiate the path helper.
450  
451 =head2 8, VCSinitError
452  
453 Failed to initiate VCS integration.
454  
455 =head2 9, VCSusableError
456  
457 Toader::VCS->usable errored.
458  
459 =head1 AUTHOR
460  
461 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
462  
463  
464 =head1 BUGS
465  
466 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
467 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll
468 automatically be notified of progress on your bug as I make changes.
469  
470  
471  
472  
473 =head1 SUPPORT
474  
475 You can find documentation for this module with the perldoc command.
476  
477 perldoc Toader
478  
479  
480 You can also look for information at:
481  
482 =over 4
483  
484 =item * RT: CPAN's request tracker
485  
486 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
487  
488 =item * AnnoCPAN: Annotated CPAN documentation
489  
490 L<http://annocpan.org/dist/Toader>
491  
492 =item * CPAN Ratings
493  
494 L<http://cpanratings.perl.org/d/Toader>
495  
496 =item * Search CPAN
497  
498 L<http://search.cpan.org/dist/Toader/>
499  
500 =back
501  
502  
503 =head1 ACKNOWLEDGEMENTS
504  
505  
506 =head1 LICENSE AND COPYRIGHT
507  
508 Copyright 2013 Zane C. Bowers-Hadley
509  
510 This program is free software; you can redistribute it and/or modify it
511 under the terms of either: the GNU General Public License as published
512 by the Free Software Foundation; or the Artistic License.
513  
514 See http://dev.perl.org/licenses/ for more information.
515  
516  
517 =cut
518  
519 1 1; # End of Toader
« Toader/Render/Page/backends/pod.pm ↑ Summary Toader/Gallery.pm »