CWidget.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 71 CC 5 SCAR 25.5
CC
5
Cov
0%
configureSubwidgets
30.0
Populate
2.0
subwidgets
2.0
CRAP 12.8
1 package Tk::CWidget;
2  
3 use strict;
4 use Carp;
5 use Tk qw(Ev);
6 use Tk::CWidget::Util::Boolean qw(IsTrue);
7  
8 use vars qw($VERSION);
9 $VERSION = "0.01";
10  
11 use base qw(Tk::Frame);
12 Tk::Widget->Construct('CWidget');
13  
14 ############################################################
15 ## Configuration Methods - support Widget creation and
16 ## the configure method.
17 ############################################################
18  
19 sub Populate
20 {
21 my ($cw, $args) = @_;
22 $cw->SUPER::Populate($args);
23 $cw->ConfigSpecs(-subwidgets => [qw/METHOD/]);
24 }
25  
26 sub subwidgets
27 {
28 my ($cw, $configAR) = @_;
29 $cw->afterIdle(['configureSubwidgets', $cw, $configAR]);
30 return;
31 }
32  
33 ############################################################
34 ## "public" methods
35 ############################################################
36  
37 ############################################################################
38 ## Convenience method for configuring one or more Subwidgets. This
39 ## method one or more pairs of arguments. The first item in each pair
40 ## is expected to be either the name of one Subwidget, or an Array
41 ## reference containing multiple Subwidgets names, and the second in
42 ## the pair should be a Hash reference containing one or more
43 ## configuration parameters that will be passed to the named Subwidget(s).
44 ############################################################################
45 sub configureSubwidgets
46 {
47 my $cw = shift;
48 my @args;
49 if (@_ > 1) { (@args) = @_; }
50 else { (@args) = @{$_[0]}; }
51  
52 while (@args) {
53 my $key = shift @args;
54 my $valHR = shift @args;
55 my $type = ref($key);
56  
57 my @widgets;
58 if (!$type) { @widgets = ($key); }
59 elsif ($type eq "ARRAY") { @widgets = @{$key}; }
60 else {
61 carp "Invalid parameter: expected Subwidget name or ARRAY ref";
62 return;
63 }
64  
65 foreach my $w (@widgets) {
66 my $sw = $cw->Subwidget($w);
67 if (defined($sw)) { $sw->configure(%$valHR); }
68 else { carp "Subwidget: $w does not exist!";}
69 }
70 }
71 }
72  
73 1;