template/GUI.pm

filter: Statementstmt 8.0% 14 / 173 Branchbran 0.0% 0 / 60 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 28.5% 4 / 14 Podpod 100% 10 / 10 totaltotal 10.8% 28 / 257 CC 31 SCAR 42.3
CC
31
Cov
6%
new
182.0
hasDialog
42.0
hasWindow
42.0
CRAP 68.4
↑ Summary template.pm »
1 package ZConf::template::GUI;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use ZConf::GUI;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use ZConf::template;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 ZConf::template::GUI -
11  
12 =head1 VERSION
13  
14 Version 0.0.0
15  
16 =cut
17  
18 3 our $VERSION = '0.0.0';
19  
20  
21 =head1 SYNOPSIS
22  
23 Quick summary of what the module does.
24  
25 Perhaps a little code snippet.
26  
27 use ZConf::template::GUI;
28  
29 my $foogui = ZConf::template::GUI->new();
30 ...
31  
32 =head1 METHODS
33  
34 =head2 new
35  
36 =head3 args hash
37  
38 =head4 obj
39  
40 This is object returned by %%%PARENT%%%.
41  
42 my $foogui=ZConf::template::GUI->new({obj=>$obj});
43 if($foogui->{error}){
44 print "Error!\n";
45 }
46  
47 =cut
48  
49 0 ▶sub new{
Subroutine new: not called CC=13 SCAR=52.0
Pod documented
50 0 my %args;
51 0 ▶ if(defined($_[1])){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[1]) 0 0 0
52 0 %args= %{$_[1]};
53 }
54 0 my $method='new';
55  
56 0 my $self={error=>undef,
57 perror=>undef,
58 errorString=>undef,
59 module=>'ZConf-template-GUI',
60 };
61 0 bless $self;
62  
63 #gets the object or initiate it
64 0 ▶ if (!defined($args{obj})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{'obj'}) { } 0 0 0
65 0 $self->{obj}=ZConf::template->new;
66 0 ▶ if ($self->{obj}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"obj"}) 0 0 0
67 0 $self->{error}=1;
68 0 $self->{perror}=1;
69 $self->{errorString}='Failed to initiate %%%PARENT%%%. error="'.
70 0 $self->{obj}->{error}.'" errorString="'.$self->{obj}->{errorString}.'"';
71 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
72 0 return $self;
73 }
74 }else {
75 0 $self->{obj}=$args{obj};
76 }
77  
78 #gets the zconf object
79 0 $self->{zconf}=$self->{obj}->{zconf};
80  
81 #gets the gui
82 0 $self->{gui}=ZConf::GUI->new({zconf=>$self->{zconf}});
83 0 ▶ if ($self->{obj}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"obj"}) 0 0 0
84 0 $self->{error}=2;
85 0 $self->{perror}=1;
86 $self->{errorString}='Failed to initiate ZConf::GUI. error="'.
87 0 $self->{gui}->{error}.'" errorString="'.$self->{gui}->{errorString}.'"';
88 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
89 0 return $self;
90 }
91  
92 0 $self->{useX}=$self->{gui}->useX('%%%PARENT%%%');
93  
94 0 my @preferred=$self->{gui}->which('%%%PARENT%%%');
95 0 ▶ if ($self->{gui}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"gui"}{"error"}) 0 0 0
96 0 $self->{error}=3;
97 0 $self->{perror}=1;
98 $self->{errorString}='Failed to get the preferred backend list. error="'.
99 0 $self->{gui}->{error}.'" errorString="'.$self->{gui}->{errorString}.'"';
100 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
101 0 return $self;
102 }
103  
104 #make sure we have something
105 0 ▶ if (!defined($preferred[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $preferred[0]) 0 0 0
106 0 $self->{error}=6;
107 0 $self->{perror}=1;
108 0 $self->{errorString}='Which did not return any preferred backends';
109 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
110 0 return $self;
111 }
112  
113 #try the backends till we get one
114 0 my $int=0;
115 0 my $loop=1;
116 0 ▶ while ($loop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($loop) 0 0 0
117  
118  
119 0 ▶ if (defined($preferred[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $preferred[0]) { } 0 0 0
120 #initiate the backend
121 0 my $toeval='use ZConf::template::GUI::'.$preferred[$int].';'."\n".
122 '$self->{be}=ZConf::template::GUI::'.$preferred[$int].
123 '->new({zconf=>$self->{zconf}, useX=>$self->{useX},'.
124 'zcgui=>$self->{gui}, zcrunner=>$self->{zcr}}); return 1';
125 0 my $er=eval($toeval);
126 }else {
127 0 $loop=0;
128 }
129  
130 #if it returned something, see if it errored
131 0 ▶ if (defined($self->{be})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"be"}) 0 0 0
132 0 ▶ if (!$self->{be}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"be"}{"error"}) 0 0 0
133 #stop the loop and continue that we loaded a working one
134 0 $loop=0;
135 }
136 }
137
138 0 $int++;
139 }
140
141 #failed to initiate the backend
142 0 ▶ if (!defined($self->{be})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"be"}) 0 0 0
143 0 $self->{error}=4;
144 0 $self->{perror}=1;
145 0 $self->{errorString}='The backend returned undefined';
146 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
147 0 return $self;
148 }
149  
150 #backend errored
151 0 ▶ if (!$self->{be}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"be"}{"error"}) 0 0 0
152 0 $self->{error}=4;
153 0 $self->{perror}=1;
154 $self->{errorString}='The backend returned undefined. error="'.
155 0 $self->{be}->{error}.'" errorString="'.$self->{be}->{errorString}.'"';
156 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
157 0 return $self;
158 }
159  
160 0 return $self;
161 }
162  
163 =head2 app
164  
165 Runs some application.
166  
167 $foogui->app;
168 if($foogui->{error}){
169 warn('error '.$foogui->error.': '.$foogui->errorString);
170 }
171  
172 =cut
173  
174 0 ▶sub app{
Subroutine app: not called CC=2 SCAR=17.9
Pod documented
175 0 my $self=$_[0];
176 0 my $method='app';
177  
178 0 $self->errorblank;
179 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
180 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
181 0 return undef;
182 }
183  
184 0 $self->{be}->app;
185  
186 }
187  
188 =head2 hasApp
189  
190 If this returns true, it means it has a application.
191  
192 my $hasApp=$foogui->hasApp;
193 if($foogui->{error}){
194 warn('error '.$foogui->error.': '.$foogui->errorString);
195 }else{
196 if($hasApp){
197 print "Yes\n";
198 }
199 }
200  
201 =cut
202  
203 0 ▶sub hasApp{
Subroutine hasApp: not called CC=3 SCAR=24.8
Pod documented
204 0 my $self=$_[0];
205 0 my $method='hasApp';
206  
207 0 $self->errorblank;
208 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
209 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
210 0 return undef;
211 }
212  
213 0 my $hasApp=$self->{be}->hasApp;
214 0 ▶ if ($self->{be}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"be"}{"error"}) 0 0 0
215 0 $self->{error}=5;
216 $self->{errorString}='The backend errored. error="'.
217 0 $self->{be}->{error}.'" errorString="'.$self->{be}->{errorString}.'"';
218 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
219 0 return undef;
220 }
221  
222 0 return $hasApp;
223 }
224  
225 =head1 DIALOG/WINDOW METHODS
226  
227 =head2 dialogs
228  
229 This returns a array of available dialogs.
230  
231 my @dialogs=$foogui->dialogs;
232 if($foogui->{error}){
233 warn('error '.$foogui->error.': '.$foogui->errorString);
234 }
235  
236 =cut
237  
238 0 ▶sub dialogs{
Subroutine dialogs: not called CC=3 SCAR=24.8
Pod documented
239 0 my $self=$_[0];
240 0 my $method='dialogs';
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 0 my @dialogs=$self->{be}->dialogs;
249 0 ▶ if ($self->{be}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"be"}{"error"}) 0 0 0
250 0 $self->{error}=5;
251 $self->{errorString}='The backend errored. error="'.
252 0 $self->{be}->{error}.'" errorString="'.$self->{be}->{errorString}.'"';
253 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
254 0 return undef;
255 }
256  
257 0 return @dialogs;
258 }
259  
260 =head2 hasDialog
261  
262 This checks if the loaded backend supports a specific dialog.
263  
264 my $supported=$foogui->hasDialog($dialogName);
265 if($foogui->error){
266 warn('error '.$foogui->error.': '.$foogui->errorString);
267 }
268 if(!supported){
269 warn($dialogName.' is not supported');
270 }
271  
272 =cut
273  
274 0 ▶sub hasDialog{
Subroutine hasDialog: not called CC=6 SCAR=37.4
Pod documented
275 0 my $self=$_[0];
276 0 my $dialog=$_[1];
277 0 my $method='hasDialog';
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 ▶ if (!defined($dialog)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dialog) 0 0 0
286 0 $self->{error}=7;
287 0 $self->{errorString}='No dialog specified';
288 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
289 }
290  
291 #try to fetch the supported dialogs
292 0 my @dialogs=$self->dialogs;
293 0 ▶ if ($self->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
294 0 warn($self->{module}.' '.$method.': $self->dialogs errored');
295 0 return undef;
296 }
297  
298 #look for a match
299 0 my $int=0;
300 0 ▶ while (defined($dialogs[$int])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dialogs[$int]) 0 0 0
301 #return true if a match is found
302 0 ▶ if ($dialogs[$int] eq $dialog) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialogs[$int] eq $dialog) 0 0 0
303 0 return 1;
304 }
305 0 $int++;
306 }
307  
308 0 return 0;
309 }
310  
311 =head2 hasWindow
312  
313 This checks if the loaded backend supports a specific window.
314  
315 my $supported=$foogui->hasWindow($windowName);
316 if($foogui->error){
317 warn('error '.$foogui->error.': '.$foogui->errorString);
318 }
319 if(!supported){
320 warn($windowName.' is not supported');
321 }
322  
323 =cut
324  
325 0 ▶sub hasWindow{
Subroutine hasWindow: not called CC=6 SCAR=37.4
Pod documented
326 0 my $self=$_[0];
327 0 my $dialog=$_[1];
328 0 my $method='hasDialog';
329  
330 0 $self->errorblank;
331 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
332 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
333 0 return undef;
334 }
335  
336 0 ▶ if (!defined($dialog)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dialog) 0 0 0
337 0 $self->{error}=7;
338 0 $self->{errorString}='No dialog specified';
339 0 warn($self->{module}.' '.$method.':'.$self->{error}.': '.$self->{errorString});
340 }
341  
342 #try to fetch the supported dialogs
343 0 my @dialogs=$self->dialogs;
344 0 ▶ if ($self->error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->error) 0 0 0
345 0 warn($self->{module}.' '.$method.': $self->dialogs errored');
346 0 return undef;
347 }
348  
349 #look for a match
350 0 my $int=0;
351 0 ▶ while (defined($dialogs[$int])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dialogs[$int]) 0 0 0
352 #return true if a match is found
353 0 ▶ if ($dialogs[$int] eq $dialog) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialogs[$int] eq $dialog) 0 0 0
354 0 return 1;
355 }
356 0 $int++;
357 }
358  
359 0 return 0;
360 }
361  
362 =head2 windows
363  
364 This returns a array of available dialogs.
365  
366 my @windows=$foogui->windows;
367 if($foogui->{error}){
368 warn('error '.$foogui->error.': '.$foogui->errorString);
369 }
370  
371 =cut
372  
373 0 ▶sub windows{
Subroutine windows: not called CC=3 SCAR=24.8
Pod documented
374 0 my $self=$_[0];
375 0 my $method='windows';
376  
377 0 $self->errorblank;
378 0 ▶ if ($self->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"error"}) 0 0 0
379 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
380 0 return undef;
381 }
382  
383 0 my @windows=$self->{be}->windows;
384 0 ▶ if ($self->{be}->{error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"be"}{"error"}) 0 0 0
385 0 $self->{error}=5;
386 $self->{errorString}='The backend errored. error="'.
387 0 $self->{be}->{error}.'" errorString="'.$self->{be}->{errorString}.'"';
388 0 warn($self->{module}.' '.$method.': A permanent error is set. error="'.$self->{error}.'" errorString="'.$self->{errorString}.'"');
389 0 return undef;
390 }
391  
392 0 return @windows;
393 }
394  
395 =head1 ERROR RELATED METHODS
396  
397 =head2 error
398  
399 This returns the current error code if one is set. If undef/evaulates as false
400 then no error is present. Other wise one is.
401  
402 if($foogui->error){
403 warn('error '.$foogui->error.': '.$foogui->errorString);
404 }
405  
406 =cut
407  
408 0 ▶sub error{
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
409 0 return $_[0]->{error};
410 }
411  
412 =head2 errorString
413  
414 This returns the current error string. A return of "" means no error is present.
415  
416 my $errorString=$foogui->errorString;
417  
418 =cut
419  
420 0 ▶sub errorString{
Subroutine errorString: not called CC=1 SCAR=6.9
Pod documented
421 0 return $_[0]->{errorString};
422 }
423  
424 =head2 errorblank
425  
426 This blanks the error storage and is only meant for internal usage.
427  
428 It does the following.
429  
430 $foogui->{error}=undef;
431 $foogui->{errorString}="";
432  
433 =cut
434  
435 #blanks the error flags
436 0 ▶sub errorblank{
Subroutine errorblank: not called CC=2 SCAR=17.9
Pod documented
437 0 my $self=$_[0];
438  
439 0 ▶ if ($self->{perror}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"perror"}) 0 0 0
440 0 warn('ZConf-DevTemplate errorblank: A permanent error is set');
441 0 return undef;
442 }
443  
444 0 $self->{error}=undef;
445 0 $self->{errorString}="";
446
447 0 return 1;
448 }
449  
450 =head1 ERROR CODES
451  
452 =head2 1
453  
454 Failed to initiate %%%PARENT%%%.
455  
456 =head2 2
457  
458 Failed to initiate ZConf::GUI.
459  
460 =head2 3
461  
462 Failed to get the preferred.
463  
464 =head2 4
465  
466 Failed to initiate the backend.
467  
468 =head2 5
469  
470 Backend errored.
471  
472 =head2 6
473  
474 No backend found via ZConf::GUI->which.
475  
476 =head2 7
477  
478 No dialog specified.
479  
480 =head1 AUTHOR
481  
482 %%%AUTHOR%%%, C<< <%%%EMAIL%%%> >>
483  
484 =head1 BUGS
485  
486 Please report any bugs or feature requests to C<bug-zconf-devtemplate at rt.cpan.org>, or through
487 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=ZConf-template>. I will be notified, and then you'll
488 automatically be notified of progress on your bug as I make changes.
489  
490  
491  
492  
493 =head1 SUPPORT
494  
495 You can find documentation for this module with the perldoc command.
496  
497 perldoc ZConf::template::GUI
498  
499  
500 You can also look for information at:
501  
502 =over 4
503  
504 =item * RT: CPAN's request tracker
505  
506 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=%%%PARENT%%%>
507  
508 =item * AnnoCPAN: Annotated CPAN documentation
509  
510 L<http://annocpan.org/dist/%%%PARENT%%%>
511  
512 =item * CPAN Ratings
513  
514 L<http://cpanratings.perl.org/d/%%%PARENT%%%>
515  
516 =item * Search CPAN
517  
518 L<http://search.cpan.org/dist/%%%PARENT%%%/>
519  
520 =back
521  
522  
523 =head1 ACKNOWLEDGEMENTS
524  
525  
526 =head1 COPYRIGHT & LICENSE
527  
528 Copyright 2009 %%%AUTHOR%%%, all rights reserved.
529  
530 This program is free software; you can redistribute it and/or modify it
531 under the same terms as Perl itself.
532  
533  
534 =cut
535  
536 3 1; # End of ZConf::template::GUI
↑ Summary template.pm »