| 1 | package Toader::Render::Page::backends::pod; | ||||||||||
| 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 base 'Error::Helper'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Pod::Simple::HTML; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use File::Temp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | =head1 NAME | ||||||||||
| 11 | |||||||||||
| 12 | Toader::Render::Page::backends::pod - This handles the POD backend stuff for Toader::Page::Entry. | ||||||||||
| 13 | |||||||||||
| 14 | =head1 VERSION | ||||||||||
| 15 | |||||||||||
| 16 | Version 0.0.0 | ||||||||||
| 17 | |||||||||||
| 18 | =cut | ||||||||||
| 19 | |||||||||||
| 20 | 1 | our $VERSION = '0.0.0'; | |||||||||
| 21 | |||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||
| 23 | |||||||||||
| 24 | use Toader::Render::Page::backends::pod; | ||||||||||
| 25 | |||||||||||
| 26 | my $renderer=Toader::Render::Page::backends::pod->new({ toader=>$toader, obj=>$pageObj }); | ||||||||||
| 27 | my $rendered; | ||||||||||
| 28 | if ( $renderer->error ){ | ||||||||||
| 29 | warn( 'Error:'.$renderer->error.': '.$renderer->errorString ); | ||||||||||
| 30 | }else{ | ||||||||||
| 31 | $rendered=$renderer->render($torender); | ||||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | =head1 METHODS | ||||||||||
| 35 | |||||||||||
| 36 | =head2 new | ||||||||||
| 37 | |||||||||||
| 38 | This initiates the object. | ||||||||||
| 39 | |||||||||||
| 40 | =head3 args hash ref | ||||||||||
| 41 | |||||||||||
| 42 | =head4 obj | ||||||||||
| 43 | |||||||||||
| 44 | This is the L<Toader::Page> object to render. | ||||||||||
| 45 | |||||||||||
| 46 | =head4 toader | ||||||||||
| 47 | |||||||||||
| 48 | This is the L<Toader> object to use. | ||||||||||
| 49 | |||||||||||
| 50 | my $foo=Toader::Render::Page::backends::pod->new(\%args); | ||||||||||
| 51 | if($foo->error){ | ||||||||||
| 52 | warn('error: '.$foo->error.":".$foo->errorString); | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||
| 58 | 0 | my %args; | |||||||||
| 59 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | %args= %{$_[1]}; | |||||||||
| 61 | }; | ||||||||||
| 62 | |||||||||||
| 63 | 0 | my $self={ | |||||||||
| 64 | error=>undef, | ||||||||||
| 65 | errorString=>'', | ||||||||||
| 66 | perror=>undef, | ||||||||||
| 67 | }; | ||||||||||
| 68 | 0 | bless $self; | |||||||||
| 69 | |||||||||||
| 70 | #make sure we have a Toader::Page object. | ||||||||||
| 71 | 0 | ▶ | if ( ! defined( $args{obj} ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 0 | $self->{perror}=1; | |||||||||
| 73 | 0 | $self->{error}=1; | |||||||||
| 74 | 0 | $self->{errorString}='Nothing defined for the Toader::Page object'; | |||||||||
| 75 | 0 | $self->warn; | |||||||||
| 76 | 0 | return $self; | |||||||||
| 77 | } | ||||||||||
| 78 | 0 | ▶ | if ( ref( $args{obj} ) ne 'Toader::Page' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $self->{perror}=1; | |||||||||
| 80 | 0 | $self->{error}=1; | |||||||||
| 81 | $self->{errorString}='The specified object is not a Toader::Page object, but a "'. | ||||||||||
| 82 | 0 | ref( $args{obj} ).'"'; | |||||||||
| 83 | 0 | $self->warn; | |||||||||
| 84 | 0 | return $self; | |||||||||
| 85 | } | ||||||||||
| 86 | 0 | $self->{obj}=$args{obj}; | |||||||||
| 87 | |||||||||||
| 88 | #make sure the object does not have a permanent error set | ||||||||||
| 89 | 0 | ▶ | if( ! $self->{obj}->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | 0 | $self->{perror}=1; | |||||||||
| 91 | 0 | $self->{error}=3; | |||||||||
| 92 | 0 | $self->{errorString}='The Toader::Page object has a permanent error set'; | |||||||||
| 93 | 0 | $self->warn; | |||||||||
| 94 | 0 | return $self; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | #make sure a Toader object is given | ||||||||||
| 98 | 0 | ▶ | if ( ! defined( $args{toader} ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 0 | $self->{perror}=1; | |||||||||
| 100 | 0 | $self->{error}=2; | |||||||||
| 101 | 0 | $self->{errorString}='Nothing defined for the Toader object'; | |||||||||
| 102 | 0 | $self->warn; | |||||||||
| 103 | 0 | return $self; | |||||||||
| 104 | } | ||||||||||
| 105 | 0 | ▶ | if ( ref( $args{toader} ) ne 'Toader' ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 106 | 0 | $self->{perror}=1; | |||||||||
| 107 | 0 | $self->{error}=2; | |||||||||
| 108 | $self->{errorString}='The specified object is not a Toader object, but a "'. | ||||||||||
| 109 | 0 | ref( $args{toader} ).'"'; | |||||||||
| 110 | 0 | $self->warn; | |||||||||
| 111 | 0 | return $self; | |||||||||
| 112 | } | ||||||||||
| 113 | 0 | $self->{toader}=$args{toader}; | |||||||||
| 114 | |||||||||||
| 115 | #make sure the Toader object does not have a permanent error set | ||||||||||
| 116 | 0 | ▶ | if( ! $self->{toader}->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 0 | $self->{perror}=1; | |||||||||
| 118 | 0 | $self->{error}=4; | |||||||||
| 119 | 0 | $self->{errorString}='The Toader object has an permanent error set'; | |||||||||
| 120 | 0 | $self->warn; | |||||||||
| 121 | 0 | return $self; | |||||||||
| 122 | } | ||||||||||
| 123 | |||||||||||
| 124 | #make sure a directory is set | ||||||||||
| 125 | 0 | ▶ | if( ! defined( $self->{obj}->dirGet ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | 0 | $self->{perror}=1; | |||||||||
| 127 | 0 | $self->{error}=5; | |||||||||
| 128 | 0 | $self->{errorString}='The Toader::Page object does not have a directory set'; | |||||||||
| 129 | 0 | $self->warn; | |||||||||
| 130 | 0 | return $self; | |||||||||
| 131 | } | ||||||||||
| 132 | |||||||||||
| 133 | 0 | return $self; | |||||||||
| 134 | } | ||||||||||
| 135 | |||||||||||
| 136 | =head2 render | ||||||||||
| 137 | |||||||||||
| 138 | This renders the object. | ||||||||||
| 139 | |||||||||||
| 140 | One argument is taken and that is what is to be rendered. | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||
| 143 | |||||||||||
| 144 | 0 | ▶ | sub render{ | ||||||||
|
Subroutine
render: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 145 | 0 | my $self=$_[0]; | |||||||||
| 146 | 0 | my $torender=$_[1]; | |||||||||
| 147 | |||||||||||
| 148 | 0 | ▶ | if ( ! $self->errorblank ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | 0 | return undef; | |||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 0 | ▶ | if ( !defined( $torender ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 153 | 0 | $self->{error}=6; | |||||||||
| 154 | 0 | $self->{errorString}='Nothing to render specified'; | |||||||||
| 155 | 0 | $self->warn; | |||||||||
| 156 | 0 | return undef; | |||||||||
| 157 | } | ||||||||||
| 158 | |||||||||||
| 159 | #create a tmp file | ||||||||||
| 160 | 0 | my $tmpfile = File::Temp::tempnam( File::Spec->tmpdir, 'tdat' ); | |||||||||
| 161 | 0 | my $fh; | |||||||||
| 162 | 0 | ▶ | if ( ! open( $fh, '>', $tmpfile ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 163 | 0 | $self->{error}=7; | |||||||||
| 164 | 0 | $self->{errorString}='Failed to open a temp file, "'.$tmpfile.'",'; | |||||||||
| 165 | 0 | $self->warn; | |||||||||
| 166 | 0 | return undef; | |||||||||
| 167 | } | ||||||||||
| 168 | 0 | print $fh $torender; | |||||||||
| 169 | 0 | close( $fh ); | |||||||||
| 170 | |||||||||||
| 171 | #print `ls $tmpfile; cat $tmpfile`; | ||||||||||
| 172 | |||||||||||
| 173 | #renders it | ||||||||||
| 174 | 0 | my $p = Pod::Simple::HTML->new; | |||||||||
| 175 | 0 | my $html; | |||||||||
| 176 | 0 | $p->index(1); | |||||||||
| 177 | 0 | $p->output_string(\$html); | |||||||||
| 178 | 0 | $p->parse_file( $tmpfile ); | |||||||||
| 179 | |||||||||||
| 180 | #unlinks the file | ||||||||||
| 181 | 0 | ▶ | if (! unlink( $tmpfile ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 182 | 0 | $self->{error}=8; | |||||||||
| 183 | 0 | $self->{errorString}='Failed to unlink "'.$tmpfile.'"'; | |||||||||
| 184 | 0 | $self->warn; | |||||||||
| 185 | 0 | return undef; | |||||||||
| 186 | } | ||||||||||
| 187 | |||||||||||
| 188 | #makes sure something is returned for html | ||||||||||
| 189 | 0 | ▶ | if (! defined( $html ) ){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 190 | 0 | $self->{error}=9; | |||||||||
| 191 | 0 | $self->{errorString}='Failed to render the html'; | |||||||||
| 192 | 0 | $self->warn; | |||||||||
| 193 | 0 | return undef; | |||||||||
| 194 | } | ||||||||||
| 195 | |||||||||||
| 196 | 0 | return $html; | |||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | =head1 ERROR CODES | ||||||||||
| 200 | |||||||||||
| 201 | =head2 1 | ||||||||||
| 202 | |||||||||||
| 203 | No L<Toader::Page> object specified. | ||||||||||
| 204 | |||||||||||
| 205 | =head2 2 | ||||||||||
| 206 | |||||||||||
| 207 | No L<Toader> object specified. | ||||||||||
| 208 | |||||||||||
| 209 | =head2 3 | ||||||||||
| 210 | |||||||||||
| 211 | The L<Toader::Page> object has a permanent error set. | ||||||||||
| 212 | |||||||||||
| 213 | =head2 4 | ||||||||||
| 214 | |||||||||||
| 215 | The L<Toader> object has a permanent error set. | ||||||||||
| 216 | |||||||||||
| 217 | =head2 5 | ||||||||||
| 218 | |||||||||||
| 219 | The L<Toader::Page> object does not have a directory set. | ||||||||||
| 220 | |||||||||||
| 221 | =head2 6 | ||||||||||
| 222 | |||||||||||
| 223 | Nothing specified to render. | ||||||||||
| 224 | |||||||||||
| 225 | =head2 7 | ||||||||||
| 226 | |||||||||||
| 227 | Failed to open a temp file. | ||||||||||
| 228 | |||||||||||
| 229 | =head2 8 | ||||||||||
| 230 | |||||||||||
| 231 | Failed to unlink the the temporary file. | ||||||||||
| 232 | |||||||||||
| 233 | =head2 9 | ||||||||||
| 234 | |||||||||||
| 235 | Failed to render the HTML. | ||||||||||
| 236 | |||||||||||
| 237 | =head1 AUTHOR | ||||||||||
| 238 | |||||||||||
| 239 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >> | ||||||||||
| 240 | |||||||||||
| 241 | =head1 BUGS | ||||||||||
| 242 | |||||||||||
| 243 | Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through | ||||||||||
| 244 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will be notified, and then you'll | ||||||||||
| 245 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 246 | |||||||||||
| 247 | =head1 SUPPORT | ||||||||||
| 248 | |||||||||||
| 249 | You can find documentation for this module with the perldoc command. | ||||||||||
| 250 | |||||||||||
| 251 | perldoc Toader::Render::Page::backends::pod | ||||||||||
| 252 | |||||||||||
| 253 | |||||||||||
| 254 | You can also look for information at: | ||||||||||
| 255 | |||||||||||
| 256 | =over 4 | ||||||||||
| 257 | |||||||||||
| 258 | =item * RT: CPAN's request tracker | ||||||||||
| 259 | |||||||||||
| 260 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader> | ||||||||||
| 261 | |||||||||||
| 262 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 263 | |||||||||||
| 264 | L<http://annocpan.org/dist/Toader> | ||||||||||
| 265 | |||||||||||
| 266 | =item * CPAN Ratings | ||||||||||
| 267 | |||||||||||
| 268 | L<http://cpanratings.perl.org/d/Toader> | ||||||||||
| 269 | |||||||||||
| 270 | =item * Search CPAN | ||||||||||
| 271 | |||||||||||
| 272 | L<http://search.cpan.org/dist/Toader/> | ||||||||||
| 273 | |||||||||||
| 274 | =back | ||||||||||
| 275 | |||||||||||
| 276 | |||||||||||
| 277 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 278 | |||||||||||
| 279 | |||||||||||
| 280 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 281 | |||||||||||
| 282 | Copyright 2012. Zane C. Bowers-Hadley. | ||||||||||
| 283 | |||||||||||
| 284 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 285 | under the terms of either: the GNU General Public License as published | ||||||||||
| 286 | by the Free Software Foundation; or the Artistic License. | ||||||||||
| 287 | |||||||||||
| 288 | See http://dev.perl.org/licenses/ for more information. | ||||||||||
| 289 | |||||||||||
| 290 | |||||||||||
| 291 | =cut | ||||||||||
| 292 | |||||||||||
| 293 | 1 | 1; # End of Toader::Render::Page::backends::pod | |||||||||