template.pm

filter: Statementstmt 7.7% 11 / 142 Branchbran 0.0% 0 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 25.0% 3 / 12 Podpod 100% 9 / 9 totaltotal 11.2% 23 / 205 CC 22 SCAR 41.3
CC
22
Cov
6%
new
156.0
delSet
12.0
init
12.0
CRAP 62.0
« template/GUI.pm ↑ Summary DevTemplate.pm »
1 package ZConf::template;
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 ZConf;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 ZConf::template -
10  
11 =head1 VERSION
12  
13 Version 0.0.0
14  
15 =cut
16  
17 4 our $VERSION = '0.0.0';
18  
19 =head1 SYNOPSIS
20  
21 Quick summary of what the module does.
22  
23 Perhaps a little code snippet.
24  
25 use ZConf::template;
26  
27 my $foo = ZConf::template->new();
28 ...
29  
30 =head1 METHODS
31  
32 =head2 new
33  
34 This initializes it.
35  
36 One arguement is taken and that is a hash.
37  
38 =head3 hash values
39  
40 =head4 zconf
41  
42 If this is defined, it will be used instead of creating
43 a new ZConf object.
44  
45 my $foo=ZConf::template->new;
46 if($foo->error){
47 warn('error '.$foo->error.': '.$foo->errorString);
48 }
49  
50 =cut
51  
52 0 ▶sub new{
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
53 0 my %args;
54 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
55 0 %args= %{$_[1]};
56 }
57 0 my $method='new';
58  
59 0 my $self={error=>undef,
60 perror=>undef,
61 errorString=>undef,
62 zconfconfig=>'%%%ZCONFCONFIG%%%',
63 module=>'ZConf-template',
64 };
65 0 bless $self;
66
67 #get the ZConf object
68 0 ▶ if (!defined($args{zconf})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'zconf'}) { } 0 0 0
69 #creates the ZConf object
70 0 $self->{zconf}=ZConf->new();
71 0 ▶ if(defined($self->{zconf}->{error})){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"zconf"}{"error"}) 0 0 0
72 0 $self->{error}=1;
73 0 $self->{perror}=1;
74 $self->{errorString}="Could not initiate ZConf. It failed with '"
75 .$self->{zconf}->{error}."', '".
76 0 $self->{zconf}->{errorString}."'";
77 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
78 0 return $self;
79 }
80 }else {
81 0 $self->{zconf}=$args{zconf};
82 }
83  
84 #check if the config exists
85 0 my $returned = $self->{zconf}->configExists($self->{zconfconfig});
86 0 ▶ if (!$self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"zconf"}{"error"}) 0 0 0
87 0 $self->{error}=1;
88 0 $self->{perror}=1;
89 $self->{errorString}="Checking if '".$self."' exists failed. error='".
90 $self->{zconf}->{error}."', errorString='".
91 0 $self->{zconf}->{errorString}."'";
92 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
93 0 return $self;
94 }
95  
96 #initiate the config if it does not exist
97 0 ▶ if (!$returned) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $returned) { } 0 0 0
98 #create the config
99 0 $self->{zconf}->createConfig($self->{zconfconfig});
100 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
101 0 $self->{error}=1;
102 0 $self->{perror}=1;
103 $self->{errorString}="Checking if '".$self."' exists failed. error='".
104 $self->{zconf}->{error}."', errorString='".
105 0 $self->{zconf}->{errorString}."'";
106 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
107 0 return $self;
108 }
109  
110 #init it
111 0 $self->init;
112 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
113 0 $self->{perror}=1;
114 0 $self->{errorString}='Init failed.';
115 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
116 0 return $self;
117 }
118 }else {
119 #if we have a set, make sure we also have a set that will be loaded
120 0 $returned=$self->{zconf}->defaultSetExists($self->{zconfconfig});
121 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
122 0 $self->{error}=1;
123 0 $self->{perror}=1;
124 $self->{errorString}="Checking if '".$self."' exists failed. error='".
125 $self->{zconf}->{error}."', errorString='".
126 0 $self->{zconf}->{errorString}."'";
127 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
128 0 return $self;
129 }
130  
131 #initiliaze a the default set if needed.
132 0 ▶ if (!$returned) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($returned) 0 0 0
133 #init it
134 0 $self->init;
135 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
136 0 $self->{perror}=1;
137 0 $self->{errorString}='Init failed.';
138 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
139 0 return $self;
140 }
141 }
142 }
143  
144  
145 #read the config
146 0 $self->{zconf}->read({config=>$self->{zconfconfig}});
147 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
148 0 $self->{error}=1;
149 0 $self->{perror}=1;
150 $self->{errorString}="Checking if the default set for '".$self."' exists failed. error='".
151 $self->{zconf}->{error}."', errorString='".
152 0 $self->{zconf}->{errorString}."'";
153 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
154 0 return $self;
155 }
156  
157 0 return $self;
158 }
159  
160 =head2 delSet
161  
162 This removes the specified ZConf set.
163  
164 $foo->delSet('someSet');
165 if($foo->{error}){
166 warn('error '.$foo->error.': '.$foo->errorString);
167 }
168  
169 =cut
170  
171 0 ▶sub delSet{
Subroutine delSet: not called CC=3 SCAR=24.8
Pod documented
172 0 my $self=$_[0];
173 0 my $set=$_[1];
174 0 my $method='init';
175  
176 0 $self->errorblank;
177 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
178 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
179 0 return undef;
180 }
181  
182 0 $self->{zconf}->delSet($self->{zconfconfg}, $set);
183 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
184 0 $self->{error}=1;
185 $self->{errorString}='ZConf getAvailableSets failed. error="'.
186 $self->{zconf}->{error}.'", errorString="'.
187 0 $self->{zconf}->{errorString}.'"';
188 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
189 0 return $self;
190 }
191  
192  
193 0 return 1;
194 }
195  
196 =head2 getZConf
197  
198 This returns the ZConf object.
199  
200 The only time this will error is if a permanent error is set.
201  
202 my $zconf=$foo->getZConf;
203 if ($foo->error){
204 warn('error '.$foo->error.': '.$foo->errorString);
205 }
206  
207 =cut
208  
209 0 ▶sub getZConf{
Subroutine getZConf: not called CC=2 SCAR=17.9
Pod documented
210 0 my $self=$_[0];
211 0 my $method='getZConf';
212  
213 0 $self->errorblank;
214 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
215 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
216 0 return undef;
217 }
218  
219 0 return $self->{zconf};
220 }
221  
222 =head2 init
223  
224 This initiates a new set. If a set already exists, it will be overwritten.
225  
226 If the set specified is undefined, the default will be used.
227  
228 The set is not automatically read.
229  
230 $foo->init($set);
231 if($foo->{error}){
232 warn('error '.$foo->error.': '.$foo->errorString);
233 }
234  
235 =cut
236  
237 0 ▶sub init{
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
238 0 my $self=$_[0];
239 0 my $set=$_[1];
240 0 my $method='init';
241  
242 0 $self->errorblank;
243 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
244 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
245 0 return undef;
246 }
247  
248 #the that what will be used for creating the new ZConf config
249 0 my %hash=();
250  
251 0 $self->{zconf}->writeSetFromHash({config=>$self->{zconfconfig}, set=>$set},\%hash);
252 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
253 0 $self->{error}=1;
254 $self->{errorString}='ZConf writeSetFromHash failed. error="'.
255 $self->{zconf}->{error}.'", errorString="'.
256 0 $self->{zconf}->{errorString}.'"';
257 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
258 0 return $self;
259 }
260  
261 0 return 1;
262 }
263  
264 =head2 listSets
265  
266 This lists the available sets for the ZConf config.
267  
268 my @sets=$foo->listSets;
269 if($foo->{error}){
270 warn('error '.$foo->error.': '.$foo->errorString);
271 }
272  
273 =cut
274  
275 0 ▶sub listSets{
Subroutine listSets: not called CC=3 SCAR=24.8
Pod documented
276 0 my $self=$_[0];
277 0 my $method='listSets';
278  
279 0 $self->errorblank;
280 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
281 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
282 0 return undef;
283 }
284  
285 0 my @sets=$self->{zconf}->getAvailableSets($self->{zconfconfig});
286 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
287 0 $self->{error}=1;
288 $self->{errorString}='ZConf getAvailableSets failed. error="'.
289 $self->{zconf}->{error}.'", errorString="'.
290 0 $self->{zconf}->{errorString}.'"';
291 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
292 0 return $self;
293 }
294  
295 0 return @sets;
296 }
297  
298 =head2 readSet
299  
300 This reads a specified ZConf set.
301  
302 If no set is specified, the default is used.
303  
304 $foo->readSet('someSet');
305 if($foo->{error}){
306 warn('error '.$foo->error.': '.$foo->errorString);
307 }
308  
309 =cut
310  
311 0 ▶sub readSet{
Subroutine readSet: not called CC=3 SCAR=24.8
Pod documented
312 0 my $self=$_[0];
313 0 my $set=$_[1];
314 0 my $method='readSet';
315  
316 0 $self->errorblank;
317 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
318 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
319 0 return undef;
320 }
321  
322 #read the config
323 0 $self->{zconf}->read({config=>$self->{zconfconfig}, set=>$set});
324 0 ▶ if ($self->{zconf}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"zconf"}{"error"}) 0 0 0
325 0 $self->{error}=1;
326 $self->{errorString}='Failed to read the set. error="'.
327 $self->{zconf}->{error}.'", errorString="'.
328 0 $self->{zconf}->{errorString}.'"';
329 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
330 0 return $self;
331 }
332  
333 0 return 1;
334 }
335  
336 =head1 ERROR RELATED METHODS
337  
338 =head2 error
339  
340 This returns the current error code if one is set. If undef/evaulates as false
341 then no error is present. Other wise one is.
342  
343 if($foo->error){
344 warn('error '.$foo->error.': '.$foo->errorString);
345 }
346  
347 =cut
348  
349 0 ▶sub error{
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
350 0 return $_[0]->{error};
351 }
352  
353 =head2 errorString
354  
355 This returns the current error string. A return of "" means no error is present.
356  
357 my $errorString=$foo->errorString;
358  
359 =cut
360  
361 0 ▶sub errorString{
Subroutine errorString: not called CC=1 SCAR=6.9
Pod documented
362 0 return $_[0]->{errorString};
363 }
364  
365 =head2 errorblank
366  
367 This blanks the error storage and is only meant for internal usage.
368  
369 It does the following.
370  
371 $foo->{error}=undef;
372 $foo->{errorString}="";
373  
374 =cut
375  
376 #blanks the error flags
377 0 ▶sub errorblank{
Subroutine errorblank: not called CC=2 SCAR=17.9
Pod documented
378 0 my $self=$_[0];
379  
380 0 ▶ if ($self->{perror}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"perror"}) 0 0 0
381 0 warn('ZConf-DevTemplate errorblank: A permanent error is set');
382 0 return undef;
383 }
384  
385 0 $self->{error}=undef;
386 0 $self->{errorString}="";
387
388 0 return 1;
389 }
390  
391 =head2 ERROR CODES
392  
393 =head3 1
394  
395 ZConf errored.
396  
397 =head1 AUTHOR
398  
399 %%%%AUTHOR%%%, C<< <%%%EMAIL%%%> >>
400  
401 =head1 BUGS
402  
403 Please report any bugs or feature requests to C<bug-zconf-devtemplate at rt.cpan.org>, or through
404 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ZConf-template>. I will be notified, and then you'll
405 automatically be notified of progress on your bug as I make changes.
406  
407 =head1 SUPPORT
408  
409 You can find documentation for this module with the perldoc command.
410  
411 perldoc ZConf::template
412  
413  
414 You can also look for information at:
415  
416 =over 4
417  
418 =item * RT: CPAN's request tracker
419  
420 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=ZConf-template>
421  
422 =item * AnnoCPAN: Annotated CPAN documentation
423  
424 L<http://annocpan.org/dist/ZConf-template>
425  
426 =item * CPAN Ratings
427  
428 L<http://cpanratings.perl.org/d/ZConf-template>
429  
430 =item * Search CPAN
431  
432 L<http://search.cpan.org/dist/ZConf-template/>
433  
434 =back
435  
436  
437 =head1 ACKNOWLEDGEMENTS
438  
439  
440 =head1 COPYRIGHT & LICENSE
441  
442 Copyright 2009 %%%AUTHOR%%%, all rights reserved.
443  
444 This program is free software; you can redistribute it and/or modify it
445 under the same terms as Perl itself.
446  
447  
448 =cut
449  
450 4 1; # End of ZConf::template
« template/GUI.pm ↑ Summary DevTemplate.pm »