Toader/Render/CSS.pm

filter: Statementstmt 16.6% 14 / 84 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 17.8% 21 / 118 CC 13 SCAR 33.8
CC
13
Cov
13%
render
56.0
new
20.0
renderCSS
20.0
CRAP 29.3
« Toader/Entry/Helper.pm ↑ Summary Toader/pathHelper.pm »
1 package Toader::Render::CSS;
2  
3 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Toader::Templates;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use base 'Error::Helper';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Toader::Render::CSS - This renders the CSS file for Toader.
11  
12 =head1 VERSION
13  
14 Version 0.1.0
15  
16 =cut
17  
18 4 our $VERSION = '0.1.0';
19  
20 =head1 SYNOPSIS
21  
22 use Toader::Render::CSS;
23  
24 my $foo = Toader::Render::CSS->new($toader);
25  
26 #renders it to a string
27 my $css=$foo->renderCSS;
28 if ( $foo->error ){
29 warn('error: '.$foo->error.":".$foo->errorString);
30 }
31
32 #this renders it to a file... this unlike renderCSS
33 #requires a output directory set
34 $toader->setOutputDir('/foo/bar');
35 if ( $toader->error ){
36 #do something
37 }
38 $foo->render;
39 if ( $foo->error ){
40 warn('error: '.$foo->error.":".$foo->errorString);
41 }
42  
43 =head1 METHODS
44  
45 =head2 new
46  
47 This initiates the object.
48  
49 One argument is taken. That is the a L<Toader> object.
50  
51 my $foo=Toader::Render::CSS->new($toader);
52 if($foo->error){
53 warn('error: '.$foo->error.":".$foo->errorString);
54 }
55  
56 =cut
57  
58 0 ▶sub new{
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
59 0 my $toader=$_[1];
60  
61 0 my $self={
62 error=>undef,
63 errorString=>'',
64 perror=>undef,
65 errorExtra=>{
66 flags=>{
67 1=>'noObj',
68 2=>'noToaderObj',
69 3=>'toaderObjPerror',
70 4=>'noOutputDirSet',
71 5=>'templateFillFailed',
72 6=>'outputDirDoesNotExist',
73 7=>'outputWriteFailed',
74 },
75 },
76 };
77 0 bless $self;
78  
79 #make sure a Toader object is given
80 0 ▶ if ( ! defined( $toader ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $toader) 0 0 0
81 0 $self->{perror}=1;
82 0 $self->{error}=1;
83 0 $self->{errorString}='Nothing defined for the Toader object';
84 0 $self->warn;
85 0 return $self;
86 }
87 0 ▶ if ( ref( $toader ) ne 'Toader' ){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $toader ne "Toader") 0 0 0
88 0 $self->{perror}=1;
89 0 $self->{error}=2;
90 0 $self->{errorString}='The specified object is not a Toader object, but a "'.
91 ref( $toader ).'"';
92 0 $self->warn;
93 0 return $self;
94 }
95 0 $self->{toader}=$toader;
96  
97 #make sure the object does not have a permanent error set
98 0 ▶ if( ! $self->{toader}->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"toader"}->errorblank) 0 0 0
99 0 $self->{perror}=1;
100 0 $self->{error}=3;
101 0 $self->{errorString}='The Toader object has a permanent error set';
102 0 $self->warn;
103 0 return $self;
104 }
105  
106 $self->{templates}=Toader::Templates->new( {
107 dir=>$self->{toader}->getRootDir,
108 0 toader=>$toader,
109 } );
110  
111 0 return $self;
112 }
113  
114 =head2 renderCSS
115  
116 This processes the CSS template.
117  
118 No arguments are accepted.
119  
120 my $css=$foo->renderCSS;
121  
122 =cut
123  
124 0 ▶sub renderCSS{
Subroutine renderCSS: not called CC=4 SCAR=30.0
Pod documented
125 0 my $self=$_[0];
126  
127 0 ▶ if ( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
128 0 return undef;
129 }
130  
131 0 my $config=$self->{toader}->getConfig;
132 my $css=$self->{templates}->fill_in( 'css',
133 {
134 c=>\$config,
135 toader=>\$self->{toader},
136 0 });
137
138 0 ▶ if ( $self->{templates}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"templates"}->error) 0 0 0
139 0 $self->{error}=5;
140 $self->{errorString}='Failed to render the template. error="'.
141 $self->{templates}->error.'" errorString="'.
142 0 $self->{templates}->errorString.'"';
143 0 $self->warn;
144 0 return undef;
145 }
146  
147 my $cssInclude=$self->{templates}->fill_in( 'cssInclude',
148 {
149 c=>\$config,
150 toader=>\$self->{toader},
151 0 });
152  
153 0 ▶ if ( $self->{templates}->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"templates"}->error) 0 0 0
154 0 $self->{error}=5;
155 $self->{errorString}='Failed to render the template. error="'.
156 $self->{templates}->error.'" errorString="'.
157 0 $self->{templates}->errorString.'"';
158 0 $self->warn;
159 0 return undef;
160 }
161  
162  
163 0 return $css.$cssInclude;
164 }
165  
166 =head2 render
167  
168 This renders it to the output directory.
169  
170 No arguments are taken.
171  
172 $foo->render;
173  
174 =cut
175  
176 0 ▶sub render{
Subroutine render: not called CC=7 SCAR=40.3
Pod documented
177 0 my $self=$_[0];
178  
179 0 ▶ if ( ! $self->errorblank ){
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->errorblank) 0 0 0
180 0 return undef;
181 }
182  
183 0 my $dir=$self->{toader}->getOutputDir;
184 0 ▶ if ( ! defined( $dir ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
185 0 $self->{error}=4;
186 0 $self->{errorString}='The Toader object does not have a output directory set';
187 0 $self->warn;
188 0 return undef;
189 }
190  
191 0 my $css=$self->renderCSS;
192 0 ▶ if ( $self->error ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
193 0 $self->warnString( 'renderCSS errored' );
194 0 return undef;
195 }
196  
197 0 ▶ if ( ! -d $dir ){
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dir) 0 0 0
198 0 ▶ if ( ! mkdir( $dir )){
Branch: 1 branch
BranchTrueFalseTotal
unless (mkdir $dir) 0 0 0
199 0 $self->{error}=6;
200 0 $self->{errorString}='The output directory,"'.$dir
201 .'", does not exist and it could be created';
202 0 $self->warn;
203 0 return undef;
204 }
205 }
206  
207 0 my $file=$dir.'/toader.css';
208 0 my $fh;
209 0 ▶ if ( ! open( $fh, '>', $file ) ){
Branch: 1 branch
BranchTrueFalseTotal
unless (open $fh, ">", $file) 0 0 0
210 0 $self->{error}=7;
211 0 $self->{errorString}='Failed to open "'.$file.'" for writing';
212 0 $self->warn;
213 0 return undef;
214 }
215 0 print $fh $css;
216 0 close( $fh );
217  
218 0 return 1;
219 }
220  
221 =head1 ERROR CODES
222  
223 =head2 1, noObj
224  
225 Nothing defined for the L<Toader> object.
226  
227 =head2 2, noToaderObj
228  
229 The specified object is not a L<Toader> object.
230  
231 =head2 3, toaderObjPerror
232  
233 The L<Toader> object has a permanent error set.
234  
235 =head2 4, noOutputDirSet
236  
237 The L<Toader> object does not have a output directory set.
238  
239 =head2 5, templateFillFailed
240  
241 Failed to fill in the CSS template.
242  
243 =head2 6, outputDirDoesNotExist
244  
245 The output directory did not exist and could not be created.
246  
247 =head2 7, outputWriteFailed
248  
249 Failed to write the file out to the output directory.
250  
251 =head1 AUTHOR
252  
253 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
254  
255 =head1 BUGS
256  
257 Please report any bugs or feature requests to C<bug-toader at rt.cpan.org>, or through
258 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Toader>. I will
259 be notified, and then you'll automatically be notified of progress on your bug as I
260 make changes.
261  
262 =head1 SUPPORT
263  
264 You can find documentation for this module with the perldoc command.
265  
266 perldoc Toader::Render:CSS
267  
268 You can also look for information at:
269  
270 =over 4
271  
272 =item * RT: CPAN's request tracker
273  
274 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Toader>
275  
276 =item * AnnoCPAN: Annotated CPAN documentation
277  
278 L<http://annocpan.org/dist/Toader>
279  
280 =item * CPAN Ratings
281  
282 L<http://cpanratings.perl.org/d/Toader>
283  
284 =item * Search CPAN
285  
286 L<http://search.cpan.org/dist/Toader/>
287  
288 =back
289  
290 =head1 ACKNOWLEDGEMENTS
291  
292 =head1 LICENSE AND COPYRIGHT
293  
294 Copyright 2011. Zane C. Bowers-Hadley.
295  
296 This program is free software; you can redistribute it and/or modify it
297 under the terms of either: the GNU General Public License as published
298 by the Free Software Foundation; or the Artistic License.
299  
300 See http://dev.perl.org/licenses/ for more information.
301  
302  
303 =cut
304  
305 4 1; # End of Toader::Render::CSS
« Toader/Entry/Helper.pm ↑ Summary Toader/pathHelper.pm »