Toader/Render/Entry/backends/pod.pm

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