| 1 | package Toader::Render; | ||||||||||
| 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::Render - This renders supported Toader objects. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | Version 0.1.0 | ||||||||||
| 15 | |||||||||||
| 16 | =cut | ||||||||||
| 17 | |||||||||||
| 18 | 1 | our $VERSION = '0.1.0'; | |||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | =head1 SYNOPSIS | ||||||||||
| 22 | |||||||||||
| 23 | use Toader::Render; | ||||||||||
| 24 | |||||||||||
| 25 | my $foo = Toader::Render->new(\%args); | ||||||||||
| 26 | |||||||||||
| 27 | =head1 METHODS | ||||||||||
| 28 | |||||||||||
| 29 | =head2 new | ||||||||||
| 30 | |||||||||||
| 31 | This initiates the object. | ||||||||||
| 32 | |||||||||||
| 33 | On argument is required and it is a L<Toader> object. | ||||||||||
| 34 | |||||||||||
| 35 | my $foo->new($toader); | ||||||||||
| 36 | if($foo->error){ | ||||||||||
| 37 | warn('error: '.$foo->error.":".$foo->errorString); | ||||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | =cut | ||||||||||
| 41 | |||||||||||
| 42 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 43 | 0 | my $toader=$_[1]; | |||||||||
| 44 | |||||||||||
| 45 | 0 | my $self={ | |||||||||
| 46 | error=>undef, | ||||||||||
| 47 | errorString=>'', | ||||||||||
| 48 | perror=>undef, | ||||||||||
| 49 | isatd=>Toader::isaToaderDir->new(), | ||||||||||
| 50 | toader=>undef, | ||||||||||
| 51 | outputdir=>undef, | ||||||||||
| 52 | errorExtra=>{ | ||||||||||
| 53 | flags=>{ | ||||||||||
| 54 | 1=>'noObj', | ||||||||||
| 55 | 2=>'noDirSet', | ||||||||||
| 56 | 3=>'noToaderObj', | ||||||||||
| 57 | 4=>'notAtoaderObj', | ||||||||||
| 58 | 5=>'noOutputDirSet', | ||||||||||
| 59 | 6=>'outputDirDoesNotExist', | ||||||||||
| 60 | 7=>'notAuserableObj', | ||||||||||
| 61 | 8=>'rendererInitErrored', | ||||||||||
| 62 | 9=>'renderErrored', | ||||||||||
| 63 | 10=>'renderReturnedUndef', | ||||||||||
| 64 | 11=>'rendererInitReturnedUndef', | ||||||||||
| 65 | }, | ||||||||||
| 66 | }, | ||||||||||
| 67 | }; | ||||||||||
| 68 | 0 | bless $self; | |||||||||
| 69 | |||||||||||
| 70 | #make sure that a Toader object is specifed | ||||||||||
| 71 | 0 | ▶ | if(!defined( $toader )){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $self->{perror}=1; | |||||||||
| 73 | 0 | $self->{error}=3; | |||||||||
| 74 | 0 | $self->{errorString}='No Toader object specified'; | |||||||||
| 75 | 0 | $self->warn; | |||||||||
| 76 | 0 | return $self; | |||||||||
| 77 | } | ||||||||||
| 78 | #make sure that a Toader object is specifed | ||||||||||
| 79 | 0 | ▶ | if( ref( $toader ) ne 'Toader' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 0 | $self->{perror}=1; | |||||||||
| 81 | 0 | $self->{error}=4; | |||||||||
| 82 | 0 | $self->{errorString}='The passed Toader object is not really a Toader object'; | |||||||||
| 83 | 0 | $self->warn; | |||||||||
| 84 | 0 | return $self; | |||||||||
| 85 | } | ||||||||||
| 86 | 0 | $self->{toader}=$toader; | |||||||||
| 87 | |||||||||||
| 88 | #get the output dir | ||||||||||
| 89 | 0 | ▶ | if(!defined( $toader->getOutputDir )){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | $self->{perror}=1; | |||||||||
| 91 | 0 | $self->{error}=5; | |||||||||
| 92 | 0 | $self->{errorString}='No outputdir defined'; | |||||||||
| 93 | 0 | $self->warn; | |||||||||
| 94 | 0 | return $self; | |||||||||
| 95 | } | ||||||||||
| 96 | 0 | $self->{outputdir}=$toader->getOutputDir; | |||||||||
| 97 | |||||||||||
| 98 | #make sure the output directory is really a directory | ||||||||||
| 99 | 0 | ▶ | if( ! -d $self->{outputdir} ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 100 | 0 | $self->{perror}=1; | |||||||||
| 101 | 0 | $self->{error}=6; | |||||||||
| 102 | 0 | $self->{errorString}='The outputdir is not a directory or does not exist'; | |||||||||
| 103 | 0 | $self->warn; | |||||||||
| 104 | 0 | return $self; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | 0 | return $self; | |||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | =head2 isAsupportedObj | ||||||||||
| 111 | |||||||||||
| 112 | This checks if a object is supported. | ||||||||||
| 113 | |||||||||||
| 114 | A return of true means it is supported, otherwise it is false. | ||||||||||
| 115 | |||||||||||
| 116 | This does not mean that the object is usable. For that use the | ||||||||||
| 117 | method isAusableObj. | ||||||||||
| 118 | |||||||||||
| 119 | my $supported=$self->isAsupportedObj($someObject); | ||||||||||
| 120 | if(!$supported){ | ||||||||||
| 121 | warn('The object is not supported.') | ||||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | =cut | ||||||||||
| 125 | |||||||||||
| 126 | 0 | ▶ | sub isAsupportedObj{ | ||||||||
|
Subroutine
isAsupportedObj: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 127 | 0 | my $self=$_[0]; | |||||||||
| 128 | 0 | my $obj=$_[1]; | |||||||||
| 129 | |||||||||||
| 130 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 131 | 0 | return undef; | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | #make sure we have a object | ||||||||||
| 135 | 0 | ▶ | if (!defined($obj)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 0 | $self->{error}=1; | |||||||||
| 137 | 0 | $self->{errorString}='No object specified'; | |||||||||
| 138 | 0 | $self->warn; | |||||||||
| 139 | 0 | return undef; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | #error if it is a string... this avoids possible injections | ||||||||||
| 143 | 0 | ▶ | if ( ref($obj) eq 'STRING' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 144 | 0 | return undef; | |||||||||
| 145 | } | ||||||||||
| 146 | |||||||||||
| 147 | #test if it is renderable | ||||||||||
| 148 | 0 | my $renderable=0; | |||||||||
| 149 | 0 | my $test='$renderable=$obj->toaderRenderable;'; | |||||||||
| 150 | 0 | eval($test); | |||||||||
| 151 | 0 | ▶ | if ( ! $renderable ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 152 | 0 | return undef; | |||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 0 | return 1; | |||||||||
| 156 | } | ||||||||||
| 157 | |||||||||||
| 158 | =head2 isAusableObj | ||||||||||
| 159 | |||||||||||
| 160 | This checks if a object is supported and usable. | ||||||||||
| 161 | |||||||||||
| 162 | A return of true means it is supported, otherwise it is false. | ||||||||||
| 163 | |||||||||||
| 164 | my $supported=$self->isAsupportedObj($someObject); | ||||||||||
| 165 | if(!$supported){ | ||||||||||
| 166 | warn('The object is not supported.') | ||||||||||
| 167 | } | ||||||||||
| 168 | |||||||||||
| 169 | =cut | ||||||||||
| 170 | |||||||||||
| 171 | 0 | ▶ | sub isAusableObj{ | ||||||||
|
Subroutine
isAusableObj: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 172 | 0 | my $self=$_[0]; | |||||||||
| 173 | 0 | my $obj=$_[1]; | |||||||||
| 174 | |||||||||||
| 175 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 176 | 0 | return undef; | |||||||||
| 177 | } | ||||||||||
| 178 | |||||||||||
| 179 | #make sure we have a object | ||||||||||
| 180 | 0 | ▶ | if (!defined($obj)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 181 | 0 | $self->{error}=1; | |||||||||
| 182 | 0 | $self->{errorString}='No object specified'; | |||||||||
| 183 | 0 | $self->warn; | |||||||||
| 184 | 0 | return undef; | |||||||||
| 185 | } | ||||||||||
| 186 | |||||||||||
| 187 | #makes sure it is supported | ||||||||||
| 188 | 0 | my $supported=$self->isAsupportedObj($obj); | |||||||||
| 189 | 0 | ▶ | if ( ! $supported ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 190 | 0 | return undef; | |||||||||
| 191 | } | ||||||||||
| 192 | |||||||||||
| 193 | #makes sure the object has a directory specified | ||||||||||
| 194 | 0 | my $dir=$obj->dirGet; | |||||||||
| 195 | 0 | ▶ | if (!defined($dir)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 196 | 0 | $self->{error}=2; | |||||||||
| 197 | 0 | $self->{errorString}='The object does not have a directory associated with it'; | |||||||||
| 198 | 0 | $self->warn; | |||||||||
| 199 | 0 | return undef; | |||||||||
| 200 | } | ||||||||||
| 201 | |||||||||||
| 202 | #makes sure the directory is really a toader directory | ||||||||||
| 203 | 0 | my $returned=$self->{isatd}->isaToaderDir($dir); | |||||||||
| 204 | 0 | ▶ | if (!$returned) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 205 | 0 | $self->{error}=3; | |||||||||
| 206 | 0 | $self->{errorString}='"'.$dir.'" is not a Toader directory'; | |||||||||
| 207 | 0 | $self->warn; | |||||||||
| 208 | 0 | return undef; | |||||||||
| 209 | } | ||||||||||
| 210 | |||||||||||
| 211 | 0 | return 1; | |||||||||
| 212 | } | ||||||||||
| 213 | |||||||||||
| 214 | =head2 renderObj | ||||||||||
| 215 | |||||||||||
| 216 | This renders a object. | ||||||||||
| 217 | |||||||||||
| 218 | $foo->renderObj($obj); | ||||||||||
| 219 | |||||||||||
| 220 | =cut | ||||||||||
| 221 | |||||||||||
| 222 | 0 | ▶ | sub renderObj{ | ||||||||
|
Subroutine
renderObj: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||
| 223 | 0 | my $self=$_[0]; | |||||||||
| 224 | 0 | my $obj=$_[1]; | |||||||||
| 225 | |||||||||||
| 226 | 0 | ▶ | if (!$self->errorblank){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 227 | 0 | return undef; | |||||||||
| 228 | } | ||||||||||
| 229 | |||||||||||
| 230 | 0 | ▶ | if(!defined($obj)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 231 | 0 | $self->{error}=1; | |||||||||
| 232 | 0 | $self->{errorString}='No object specified'; | |||||||||
| 233 | 0 | $self->warn; | |||||||||
| 234 | 0 | return undef; | |||||||||
| 235 | } | ||||||||||
| 236 | |||||||||||
| 237 | 0 | ▶ | if(!$self->isAusableObj($obj)){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 238 | 0 | $self->{error}=7; | |||||||||
| 239 | 0 | $self->{errorString}='"'.ref($obj).'" is not a usable object'; | |||||||||
| 240 | 0 | $self->warn; | |||||||||
| 241 | 0 | return undef; | |||||||||
| 242 | } | ||||||||||
| 243 | |||||||||||
| 244 | #gets what object to use for rendering | ||||||||||
| 245 | 0 | my $renderUsing; | |||||||||
| 246 | 0 | my $rendererGet='$renderUsing=$obj->renderUsing;'; | |||||||||
| 247 | 0 | eval( $rendererGet ); | |||||||||
| 248 | 0 | ▶ | if ( ! defined( $renderUsing ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 249 | 0 | $self->{error}=10; | |||||||||
| 250 | 0 | $self->{errorString}='Failed to get the renderer to use. obj="'.ref($obj).'"'; | |||||||||
| 251 | 0 | $self->warn; | |||||||||
| 252 | 0 | return undef; | |||||||||
| 253 | } | ||||||||||
| 254 | |||||||||||
| 255 | #initiates the renderer | ||||||||||
| 256 | 0 | my $renderer; | |||||||||
| 257 | 0 | my $rendererInit='use '.$renderUsing.'; $renderer='.$renderUsing.'->new( { obj=>$obj, toader=>$self->{toader} } );'; | |||||||||
| 258 | 0 | eval( $rendererInit ); | |||||||||
| 259 | 0 | ▶ | if ( ! defined( $renderer ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 260 | 0 | $self->{error}=11; | |||||||||
| 261 | 0 | $self->{errorString}='Rendering initialize resulted in a undef. init string="'.$rendererInit.'"'; | |||||||||
| 262 | 0 | $self->warn; | |||||||||
| 263 | 0 | return undef; | |||||||||
| 264 | } | ||||||||||
| 265 | 0 | ▶ | if($renderer->error){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 266 | 0 | $self->{error}=8; | |||||||||
| 267 | 0 | $self->{errorString}='Unable to initialize the renderer. render="'.ref($obj).'" '. | |||||||||
| 268 | 'error="'.$renderer->error.'" errorString="'.$renderer->errorString.'"'; | ||||||||||
| 269 | 0 | $self->warn; | |||||||||
| 270 | 0 | return undef; | |||||||||
| 271 | } | ||||||||||
| 272 | |||||||||||
| 273 | 0 | $renderer->render; | |||||||||
| 274 | 0 | ▶ | if($renderer->error){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 275 | 0 | $self->{error}=9; | |||||||||
| 276 | 0 | $self->{errorString}='Rendering failed. render="'.ref($obj).'" '. | |||||||||
| 277 | 'error="'.$renderer->error.'" errorString="'.$renderer->errorString.'"'; | ||||||||||
| 278 | 0 | $self->warn; | |||||||||
| 279 | 0 | return undef; | |||||||||
| 280 | } | ||||||||||
| 281 | |||||||||||
| 282 | 0 | return 1; | |||||||||
| 283 | } | ||||||||||
| 284 | |||||||||||
| 285 | =head1 ERROR CODES | ||||||||||
| 286 | |||||||||||
| 287 | =head2 1, noObj | ||||||||||
| 288 | |||||||||||
| 289 | No object specified. | ||||||||||
| 290 | |||||||||||
| 291 | =head2 2, noDirSet | ||||||||||
| 292 | |||||||||||
| 293 | The object does not have a directory associated with it. | ||||||||||
| 294 | |||||||||||
| 295 | =head2 3, noToaderObj | ||||||||||
| 296 | |||||||||||
| 297 | No Toader object specified. | ||||||||||
| 298 | |||||||||||
| 299 | =head2 4, notAtoaderObj | ||||||||||
| 300 | |||||||||||
| 301 | The object passed as a L<Toader> object is not a L<Toader> object. | ||||||||||
| 302 | |||||||||||
| 303 | =head2 5, noOutputDirSet | ||||||||||
| 304 | |||||||||||
| 305 | No outputdir specified. | ||||||||||
| 306 | |||||||||||
| 307 | =head2 6, outputDirDoesNotExist | ||||||||||
| 308 | |||||||||||
| 309 | The specified outputdir does not exist or is not a directory. | ||||||||||
| 310 | |||||||||||
| 311 | =head2 7, notAusableObj | ||||||||||
| 312 | |||||||||||
| 313 | The specified object is not usable. | ||||||||||
| 314 | |||||||||||
| 315 | =head2 8, rendererInitErrored | ||||||||||
| 316 | |||||||||||
| 317 | Unable to initialize the render for the object. | ||||||||||
| 318 | |||||||||||
| 319 | =head2 9, renderErrored | ||||||||||
| 320 | |||||||||||
| 321 | Rendering failed at rendering the object. | ||||||||||
| 322 | |||||||||||
| 323 | =head2 10, renderReturnedUndef | ||||||||||
| 324 | |||||||||||
| 325 | Renderer returned undef. | ||||||||||
| 326 | |||||||||||
| 327 | =head2 11, rendererInitReturnedUndef | ||||||||||
| 328 | |||||||||||
| 329 | Attempting to initialize the renderer returned undefined. | ||||||||||
| 330 | |||||||||||
| 331 | =head1 AUTHOR | ||||||||||
| 332 | |||||||||||
| 333 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||
| 334 | |||||||||||
| 335 | =head1 BUGS | ||||||||||
| 336 | |||||||||||
| 337 | Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through | ||||||||||
| 338 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll | ||||||||||
| 339 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 340 | |||||||||||
| 341 | |||||||||||
| 342 | |||||||||||
| 343 | |||||||||||
| 344 | =head1 SUPPORT | ||||||||||
| 345 | |||||||||||
| 346 | You can find documentation for this module with the perldoc command. | ||||||||||
| 347 | |||||||||||
| 348 | perldoc Toader::Render | ||||||||||
| 349 | |||||||||||
| 350 | |||||||||||
| 351 | You can also look for information at: | ||||||||||
| 352 | |||||||||||
| 353 | =over 4 | ||||||||||
| 354 | |||||||||||
| 355 | =item * RT: CPAN's request tracker | ||||||||||
| 356 | |||||||||||
| 357 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader> | ||||||||||
| 358 | |||||||||||
| 359 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 360 | |||||||||||
| 361 | L<http://annocpan.org/dist/Toader> | ||||||||||
| 362 | |||||||||||
| 363 | =item * CPAN Ratings | ||||||||||
| 364 | |||||||||||
| 365 | L<http://cpanratings.perl.org/d/Toader> | ||||||||||
| 366 | |||||||||||
| 367 | =item * Search CPAN | ||||||||||
| 368 | |||||||||||
| 369 | L<http://search.cpan.org/dist/Toader/> | ||||||||||
| 370 | |||||||||||
| 371 | =back | ||||||||||
| 372 | |||||||||||
| 373 | |||||||||||
| 374 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 375 | |||||||||||
| 376 | |||||||||||
| 377 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 378 | |||||||||||
| 379 | Copyright 2013. Zane C. Bowers-Hadley. | ||||||||||
| 380 | |||||||||||
| 381 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 382 | under the terms of either: the GNU General Public License as published | ||||||||||
| 383 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 384 | |||||||||||
| 385 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 386 | |||||||||||
| 387 | |||||||||||
| 388 | =cut | ||||||||||
| 389 | |||||||||||
| 390 | 1 | 1; # End of Toader::Render | |||||||||