blib/lib/Script/Toolbox/Util/Menus.pm

filter: Statementstmt 3.9% 10 / 255 Branchbran 0.0% 0 / 104 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 5.2% 2 / 38 Podpod 0.0% 0 / 27 totaltotal 2.7% 12 / 434 CC 67 SCAR 31.9
CC
67
Cov
3%
run
72.0
_invalidParam
56.0
getMatching
56.0
CRAP 24.2
↑ Summary blib/lib/Script/Toolbox/Util/Menues.pm »
1 package Script::Toolbox::Util::Menus;
2  
3 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 21 require Exporter;
7  
8 21 @ISA = qw(Exporter);
9 # Items to export into callers namespace by default. Note: do not export
10 # names by default without a very good reason. Use EXPORT_OK instead.
11 # Do not simply export all your public functions/methods/constants.
12 21 @EXPORT = qw(
13
14 );
15  
16  
17 # Preloaded methods go here.
18  
19 #-----------------------------------------------------------------------------
20 # {'menueName>' =>[{label=>,value=>,jump=>,argv=>},...]}
21 #-----------------------------------------------------------------------------
22 sub new
23 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
24 0 my $classname = shift;
25 0 my $self = {};
26 0 bless( $self, $classname );
27 0 $self->_init( @_ );
28 0 return $self;
29 }
30  
31 #-----------------------------------------------------------------------------
32 # {'<menueName>' =>[{label=>,value=>,jump=>,argv=>},...]}
33 #-----------------------------------------------------------------------------
34 sub _init
35 0 ▶{
Subroutine _init: not called CC=2 SCAR=17.9
36 0 my ($self, $newDef) = @_;
37  
38 0 $self->{'def'} = {};
39 0 ▶ return if( ref $newDef ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $newDef ne "HASH" 0 0 0
40 0 $self->addMenu($newDef);
41 }
42  
43 #------------------------------------------------------------------------------
44 #------------------------------------------------------------------------------
45 0 ▶sub _getHead($){
Subroutine _getHead: not called CC=4 SCAR=30.0
46 0 my ($self,$def) = @_;
47 0 my $s = '';
48 0 foreach my $k ( @{$def} ) {
49 0 ▶ next if( ! defined $k->{'header'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k->{"header"} 0 0 0
50 0 $s .= sprintf "%s", $k->{'header'};
51 }
52 0 ▶ return $s ne '' ? $s : undef;
Branch: 1 branch
BranchTrueFalseTotal
$s ne '' ? : 0 0 0
53 }
54 #------------------------------------------------------------------------------
55 #------------------------------------------------------------------------------
56 0 ▶sub _getFoot($){
Subroutine _getFoot: not called CC=4 SCAR=30.0
57 0 my ($self,$def) = @_;
58 0 my $s = '';
59 0 foreach my $k ( @{$def} ) {
60 0 ▶ next if( ! defined $k->{'footer'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k->{"footer"} 0 0 0
61 0 $s .= sprintf "%s", $k->{'footer'};
62 }
63 0 ▶ return $s ne '' ? $s : undef;
Branch: 1 branch
BranchTrueFalseTotal
$s ne '' ? : 0 0 0
64 }
65  
66 #------------------------------------------------------------------------------
67 # ...
68 # {'label'=>'Call the submenue 1','jump'=>'SubMenu1'}
69 # SubMenu1: is the name of a previous defined menue in the same menues container
70 #------------------------------------------------------------------------------
71 0 ▶sub _resolveSubmenue($){
Subroutine _resolveSubmenue: not called CC=3 SCAR=24.8
72 0 my ($self,$opt) = @_;
73  
74 0 ▶ return if( !defined $opt->{'jump'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opt->{"jump"} 0 0 0
75 0 ▶ return if( ref \$opt->{'jump'} ne 'SCALAR' );
Branch: 1 branch
BranchTrueFalseTotal
if ref \$opt->{"jump"} ne "SCALAR" 0 0 0
76  
77 0 my $subName = $opt->{'jump'};
78 0 $opt->{'jump'} = \&Script::Toolbox::Util::Menus::run;
79 0 $opt->{'argv'} = [$self,$subName];
80 0 return;
81 }
82  
83 #------------------------------------------------------------------------------
84 # [{label=>,value=>,jump=>,argv=>},...]}
85 #------------------------------------------------------------------------------
86 0 ▶sub _getOpts($){
Subroutine _getOpts: not called CC=3 SCAR=24.8
87 0 my ($self,$def) = @_;
88 0 my @s;
89 0 foreach my $k ( @{$def} ) {
90 0 ▶ next if( ! defined $k->{'label'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k->{"label"} 0 0 0
91 0 $self->_resolveSubmenue($k);
92 0 push @s, $k;
93 }
94 0 return \@s;
95 }
96  
97 #------------------------------------------------------------------------------
98 # <menueName>, [{label=>,value=>,jump=>,argv=>},...]}
99 #------------------------------------------------------------------------------
100 0 ▶sub addMenu($){
Subroutine addMenu: not called CC=3 SCAR=24.8
Pod undocumented
101 0 my ($self,$newDef) = @_;
102  
103 0 ▶ return if( ref $newDef ne 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $newDef ne "HASH" 0 0 0
104  
105 0 foreach my $name ( keys %{$newDef} ){
106 0 my $def = $newDef->{$name};
107 0 $self->{'def'}{$name}{'head'} = $self->_getHead($def);
108 0 $self->{'def'}{$name}{'foot'} = $self->_getFoot($def);
109 0 $self->{'def'}{$name}{'opts'} = $self->_getOpts($def);
110 }
111 0 return;
112 }
113  
114 #------------------------------------------------------------------------------
115 # <menueName>, <HeaderString>
116 #------------------------------------------------------------------------------
117 0 ▶sub setHeader($$){
Subroutine setHeader: not called CC=1 SCAR=6.9
Pod undocumented
118 0 my ($self,$name,$head) = @_;
119  
120 0 $self->{'def'}{$name}{'head'} = $head;
121 0 return;
122 }
123  
124  
125 #------------------------------------------------------------------------------
126 # <menueName>, <HeaderString>
127 #------------------------------------------------------------------------------
128 0 ▶sub setAutoHeader($){
Subroutine setAutoHeader: not called CC=3 SCAR=24.8
Pod undocumented
129 0 my ($self,$name) = @_;
130
131 0 ▶ if( defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 0 0
132 0 $self->{'def'}{$name}{'autohead'} = 1;
133 0 return;
134 }
135 0 foreach my $n (keys %{$self->{'def'}} ){
136 0 $self->{'def'}{$n}{'autohead'} = 1;
137 }
138 }
139  
140 #------------------------------------------------------------------------------
141 #------------------------------------------------------------------------------
142 0 ▶sub _delAutoHead($){
Subroutine _delAutoHead: not called CC=2 SCAR=17.9
143 0 my ($ah) = @_;
144 0 ▶ delete $ah->{'autohead'} if( defined $ah->{'autohead'} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $ah->{"autohead"} 0 0 0
145 }
146  
147 #------------------------------------------------------------------------------
148 # <menueName>, <HeaderString>
149 #------------------------------------------------------------------------------
150 0 ▶sub delAutoHeader($){
Subroutine delAutoHeader: not called CC=3 SCAR=24.8
Pod undocumented
151 0 my ($self,$name) = @_;
152  
153 0 ▶ if( defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 0 0
154 0 _delAutoHead( $self->{'def'}{$name} );
155 0 return;
156 }
157 0 foreach my $n (keys %{$self->{'def'}} ){
158 0 _delAutoHead( $self->{'def'}{$n} );
159 }
160 }
161  
162 #------------------------------------------------------------------------------
163 # <menueName>, <HeaderString>
164 #------------------------------------------------------------------------------
165 0 ▶sub getHeader($){
Subroutine getHeader: not called CC=4 SCAR=30.0
Pod undocumented
166 0 my ($self,$name) = @_;
167  
168 0 my $autoHead = $self->{'def'}{$name}{'autohead'};
169 0 my $H;
170 0 my $h = $self->{'def'}{$name}{'head'};
171 0 ▶ $h = "Menu: $name" if(!defined $h && defined $autoHead);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $h and defined $autoHead 0 0 0
Condition0%0/3
not defined $h and defined $autoHead
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $h and defined $autoHead
not defined $h defined $autoHead
Truth table0%0/3
not(A) and B
A= not defined $hB= defined $autoHead
ABresult
0X0
100
111
172 0 ▶ $H = {'header' => $h} if( defined $h );
Branch: 1 branch
BranchTrueFalseTotal
if defined $h 0 0 0
173  
174 0 return $H;
175 }
176  
177 #------------------------------------------------------------------------------
178 # <menueName>, <FooterString>
179 #------------------------------------------------------------------------------
180 0 ▶sub setFooter($$){
Subroutine setFooter: not called CC=1 SCAR=6.9
Pod undocumented
181 0 my ($self,$name,$foot) = @_;
182  
183 0 $self->{'def'}{$name}{'foot'} = $foot;
184 0 return;
185 }
186  
187 #------------------------------------------------------------------------------
188 # <menueName>, <FooterString>
189 #------------------------------------------------------------------------------
190 0 ▶sub getFooter($){
Subroutine getFooter: not called CC=2 SCAR=17.9
Pod undocumented
191 0 my ($self,$name) = @_;
192  
193 0 my $foot = $self->{'def'}{$name}{'foot'} ;
194 0 ▶ return {'footer'=> $foot} if(defined $foot);
Branch: 1 branch
BranchTrueFalseTotal
if defined $foot 0 0 0
195 0 return undef;
196 }
197  
198 #------------------------------------------------------------------------------
199 # <menueName>, {label=>,value=>,jump=>,argv=>}
200 #------------------------------------------------------------------------------
201 0 ▶sub addOption($$){
Subroutine addOption: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my ($self,$name,$opt) = @_;
203  
204 0 ▶ $self->{'def'}{$name}{'opts'} = [] if( ! defined $self->{'def'}{$name}{'opts'} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"def"}{$name}{"opts"} 0 0 0
205  
206 0 $self->_resolveSubmenue($opt);
207 0 push @{$self->{'def'}{$name}{'opts'}}, $opt;
208 0 return;
209 }
210  
211 #------------------------------------------------------------------------------
212 #------------------------------------------------------------------------------
213 0 ▶sub _getParams($){
Subroutine _getParams: not called CC=3 SCAR=24.8
214 0 my ($self,$name) = @_;
215  
216 0 my @p;
217 0 ▶ my $s = $self->getHeader($name); push @p, $s if( defined $s );
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
218 0 ▶ $s = $self->getFooter($name); push @p, $s if( defined $s );
Branch: 1 branch
BranchTrueFalseTotal
if defined $s 0 0 0
219 0 push @p, {'label'=>'RETURN'};
220 map {
221 0 push @p, $_;
222 0 } @{$self->{'def'}{$name}{'opts'}};
223  
224 0 return \@p;
225 }
226  
227 #------------------------------------------------------------------------------
228 # Validate parameters and rearrange parameters in case of internal menue call
229 # ( submenue call by name).
230 # Return 0 if parameters invalid.
231 #------------------------------------------------------------------------------
232 0 ▶sub validateParams($$){
Subroutine validateParams: not called CC=5 SCAR=34.0
Pod undocumented
233 0 my ($self,$name) = @_;
234 0 ▶ return 0 if( ! defined $$self );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$self 0 0 0
235 0 ▶ if( ref $$self eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$self eq "ARRAY") 0 0 0
236 0 ▶ return 0 if( ref $$self->[0] ne 'Script::Toolbox::Util::Menus' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $$self->[0] ne "Script::Toolbox::Util::Menus" 0 0 0
237 0 $$name = $$self->[1];
238 0 $$self = $$self->[0];
239 }
240 0 ▶ return 1 if( defined $$self->{'def'}{$$name} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $$self->{"def"}{$$name} 0 0 0
241 0 Script::Toolbox::Util::Log("\nWARNING: Submenue $$name is not defined!");
242 0 sleep 5;
243 0 return 0;
244 }
245  
246 #------------------------------------------------------------------------------
247 # 0 HASH(0x7f98e5350ed0)
248 # 'label' => 'test10'
249 # 'readOnly' => 1
250 # 'value' => 'x'
251 #------------------------------------------------------------------------------
252 0 ▶sub _toggleRO($){
Subroutine _toggleRO: not called CC=6 SCAR=37.4
253 0 my ($opt) = @_;
254 0 ▶ return if( ! $opt->{'readOnly'});
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"readOnly"} 0 0 0
255  
256 0 my $v = $opt->{'value'};
257 0 my $d = $opt->{'default'};
258  
259 0 ▶ if( $d && $v ) { $opt->{'value'} = $d; $opt->{'default'} = $v }
Branch: 3 branches
BranchTrueFalseTotal
if ($d and $v) { } 0 0 0
elsif ($d) { } 0 0 0
elsif ($v) { } 0 0 0
Condition0%0/3
$d and $v
!ll&&!rl&&r
000
MC/DC0%0/2
$d and $v
$d $v
Truth table0%0/3
A and B
A= $dB= $v
ABresult
0X0
100
111
260 0 elsif( $d ) { $opt->{'value'} = $d; $opt->{'default'} = '' }
261 0 elsif( $v ) { $opt->{'value'} = ''; $opt->{'default'} = $v }
262 0 else { $opt->{'value'} = 'x';$opt->{'default'} = '' }
263 }
264  
265 #------------------------------------------------------------------------------
266 # Run the named menue as long as $cnt is true. $cnt will be decremented by each
267 # loop. That means if $cnt starts with 0 we have an endless loop.
268 # Return the number of the last selected option.
269 # The option 'RETURN' will be created automaticly and has option number 0 by
270 # default.
271 #------------------------------------------------------------------------------
272 0 ▶sub run($$){
Subroutine run: not called CC=8 SCAR=42.8
Pod undocumented
273 0 my ($self,$name,$cnt) = @_;
274  
275 0 ▶ return if( ! validateParams(\$self,\$name) );
Branch: 1 branch
BranchTrueFalseTotal
unless &validateParams(\$self, \$name) 0 0 0
276 0 ▶ $cnt = 1 if( ! defined $cnt);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cnt 0 0 0
277 0 ▶ $cnt = 1 if( $cnt !~ /^[-]?\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $cnt =~ /^[-]?\d+$/ 0 0 0
278 0 ▶ $cnt = -1 if( $cnt == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $cnt == 0 0 0 0
279 0 $self->{'_cnt'} = $cnt;
280 0 my $o; my $m;
281 0 ▶ while($self->{'_cnt'}--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_cnt"}--) 0 0 0
282 0 my $p = $self->_getParams($name);
283 0 ($o,$m) = Script::Toolbox::Util::Menu($p);
284 0 $self->{'def'}{$name}{'selected'}{'num'} = $o;
285 0 $self->{'def'}{$name}{'selected'}{'opt'} = $m->[$o];
286 0 ▶ _toggleRO($m->[$o]) if($self->{'_cnt'} < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_cnt"} < 0 0 0 0
287 0 ▶ return $o if( $o == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $o == 0 0 0 0
288 }
289 0 return $o;
290 }
291  
292 #------------------------------------------------------------------------------
293 # Return the current value of internal menu running counter.
294 #------------------------------------------------------------------------------
295 0 ▶sub getRunCnt($$){
Subroutine getRunCnt: not called CC=1 SCAR=6.9
Pod undocumented
296 0 my ($self,$menName) = @_;
297  
298 0 return $self->{$menName}{'_cnt'};
299 }
300  
301 #------------------------------------------------------------------------------
302 # Return current number of selected option.
303 #------------------------------------------------------------------------------
304 0 ▶sub currNumber($){
Subroutine currNumber: not called CC=2 SCAR=17.9
Pod undocumented
305 0 my ($self,$name) = @_;
306  
307 Script::Toolbox::Util::Exit(1,"Undefined menu: $name",
308 0 ▶ __FILE__ , __LINE__) if( ! defined $self->{'def'}{$name} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"def"}{$name} 0 0 0
309  
310 0 return $self->{'def'}{$name}{'selected'}{'num'};
311 }
312  
313 #------------------------------------------------------------------------------
314 # Return current label of selected option.
315 #------------------------------------------------------------------------------
316 0 ▶sub currLabel($){
Subroutine currLabel: not called CC=1 SCAR=6.9
Pod undocumented
317 0 my ($self,$name) = @_;
318 0 return $self->{'def'}{$name}{'selected'}{'opt'}{'label'};
319 }
320  
321 #------------------------------------------------------------------------------
322 # Return current value of selected option.
323 #------------------------------------------------------------------------------
324 0 ▶sub currValue($){
Subroutine currValue: not called CC=1 SCAR=6.9
Pod undocumented
325 0 my ($self,$name) = @_;
326 0 return $self->{'def'}{$name}{'selected'}{'opt'}{'value'};
327 }
328  
329 #------------------------------------------------------------------------------
330 # Return the callback address and argv address of selected option.
331 #------------------------------------------------------------------------------
332 0 ▶sub currJump($){
Subroutine currJump: not called CC=1 SCAR=6.9
Pod undocumented
333 0 my ($self,$name) = @_;
334  
335 0 my $call = $self->{'def'}{$name}{'selected'}{'opt'}{'jump'};
336 0 my $args = $self->{'def'}{$name}{'selected'}{'opt'}{'argv'};
337
338 0 return $call,$args;
339 }
340  
341 #------------------------------------------------------------------------------
342 # Set a new default for current selected option. Return old default.
343 #------------------------------------------------------------------------------
344 0 ▶sub setCurrDefault($$){
Subroutine setCurrDefault: not called CC=1 SCAR=6.9
Pod undocumented
345 0 my ($self,$name,$newDefault) = @_;
346  
347 0 my $cn = $self->currNumber($name) -1;
348 0 my $ol = $self->{'def'}{$name}{'opts'}[$cn]{'default'};
349 0 $self->{'def'}{$name}{'opts'}[$cn]{'default'} = $newDefault;
350 0 return $ol;
351 }
352  
353 #------------------------------------------------------------------------------
354 # Set a new default for current selected option. Return old default.
355 #------------------------------------------------------------------------------
356 0 ▶sub setCurrReadOnly($$){
Subroutine setCurrReadOnly: not called CC=3 SCAR=24.8
Pod undocumented
357 0 my ($self,$name,$newRo) = @_;
358
359 0 ▶ if( ! defined $newRo ) { $newRo = 0 }
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $newRo) { } 0 0 0
elsif ($newRo =~ /(0|false)/i) { } 0 0 0
360 0 elsif( $newRo =~ /(0|false)/i ){ $newRo = 0 }
361 0 else { $newRo = 1 }
362 0 my $cn = $self->currNumber($name) -1;
363 0 my $ol = $self->{'def'}{$name}{'opts'}[$cn]{'readOnly'};
364 0 $self->{'def'}{$name}{'opts'}[$cn]{'readOnly'} = $newRo;
365 0 return $ol;
366 }
367  
368 #------------------------------------------------------------------------------
369 # Set a new label for current selected option. Return old label.
370 #------------------------------------------------------------------------------
371 0 ▶sub setCurrLabel($$){
Subroutine setCurrLabel: not called CC=1 SCAR=6.9
Pod undocumented
372 0 my ($self,$name,$newLabel) = @_;
373  
374 0 my $cn = $self->currNumber($name) -1;
375 0 my $ol = $self->{'def'}{$name}{'opts'}[$cn]{'label'};
376 0 $self->{'def'}{$name}{'opts'}[$cn]{'label'} = $newLabel;
377 0 return $ol;
378 }
379  
380 #------------------------------------------------------------------------------
381 # Set a new value for current selected option. Return old value.
382 #------------------------------------------------------------------------------
383 0 ▶sub setCurrValue($$){
Subroutine setCurrValue: not called CC=1 SCAR=6.9
Pod undocumented
384 0 my ($self,$name,$newValue) = @_;
385  
386 0 my $cn = $self->currNumber($name) -1;
387 0 my $ov = $self->{'def'}{$name}{'opts'}[$cn]{'value'};
388 0 $self->{'def'}{$name}{'opts'}[$cn]{'value'} = $newValue;
389 0 return $ov;
390 }
391  
392 #------------------------------------------------------------------------------
393 # Set new callback address und argv for the current selected option.
394 #------------------------------------------------------------------------------
395 0 ▶sub setCurrJump($$$){
Subroutine setCurrJump: not called CC=1 SCAR=6.9
Pod undocumented
396 0 my ($self,$name,$callBack,$argv) = @_;
397  
398 0 my $cn = $self->currNumber($name) -1;
399 0 $self->{'def'}{$name}{'opts'}[$cn]{'jump'} = $callBack;
400 0 $self->{'def'}{$name}{'opts'}[$cn]{'argv'} = $argv;
401 0 return $callBack,$argv;
402 }
403  
404 #------------------------------------------------------------------------------
405 #------------------------------------------------------------------------------
406 0 ▶sub _invalidParam($$$$$){
Subroutine _invalidParam: not called CC=7 SCAR=40.3
407 0 my ($self,$name,$pattern,$search,$return) = @_;
408 0 ▶ return 1 if( !defined $pattern );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pattern 0 0 0
409 0 ▶ return 1 if( !defined $search );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $search 0 0 0
410 0 ▶ return 1 if( !defined $return );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return 0 0 0
411 0 ▶ return 1 if( !defined $self->{'def'}{$name}{'opts'});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"def"}{$name}{"opts"} 0 0 0
412 0 ▶ return 1 if( $search !~ /(number|value|label)/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $search =~ /(number|value|label)/ 0 0 0
413 0 ▶ return 1 if( $return !~ /(number|value|label)/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $return =~ /(number|value|label)/ 0 0 0
414 0 return 0;
415 }
416  
417 #------------------------------------------------------------------------------
418 # Search the labels array for $pattern matching in $search. If matching return
419 # value of type return.
420 # $pattern='[Mm]ax' $search='value' $return='label'
421 # => returns all labels where value column matching Max or max.
422 # search: /(label,number,value)/
423 # return: /(label,number,value)/
424 #------------------------------------------------------------------------------
425 0 ▶sub getMatching($$$$){
Subroutine getMatching: not called CC=7 SCAR=40.3
Pod undocumented
426 0 my ($self,$name,$pattern,$search,$return) = @_;
427 0 ▶ return '' if( _invalidParam($self,$name,$pattern,$search,$return));
Branch: 1 branch
BranchTrueFalseTotal
if &_invalidParam($self, $name, $pattern, $search, $return) 0 0 0
428  
429 0 my $L = $self->{'def'}{$name}{'opts'};
430 0 my @R;
431 0 my $i=1;
432 0 foreach my $l ( @{$L} ){
433 0 ▶ if( $search eq 'number' ){
Branch: 1 branch
BranchTrueFalseTotal
if ($search eq 'number') { } 0 0 0
434 0 ▶ push @R, $l->{$return} if( $i =~ /$pattern/);
Branch: 1 branch
BranchTrueFalseTotal
if $i =~ /$pattern/ 0 0 0
435 0 $i++;
436 }else{
437 0 ▶ next if( !defined $l->{$search} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $l->{$search} 0 0 0
438 0 ▶ next if( $l->{$search} !~ /$pattern/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $l->{$search} =~ /$pattern/ 0 0 0
439 0 push @R, $l->{$return};
440 }
441 }
442 0 return \@R;
443 }
444  
445 #------------------------------------------------------------------------------
446 # Useful for DataMenus.
447 # Return all Label-Value pairs in a hash structure.
448 #------------------------------------------------------------------------------
449 0 ▶sub getLabelValueHash($$){
Subroutine getLabelValueHash: not called CC=3 SCAR=24.8
Pod undocumented
450 0 my ($self,$name) = @_;
451  
452 0 my $L = $self->{'def'}{$name}{'opts'};
453 0 my $lvh;
454 0 foreach my $x (@{$L}) {
455 0 my $l = $x->{'label'};
456 0 my $v = $x->{'value'};
457 0 ▶ next if( ! defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
458 0 $lvh->{$l} = $v;
459 }
460 0 return $lvh;
461 }
462  
463 #------------------------------------------------------------------------------
464 # Take a value hash {<label> => <value>} as input.
465 # Copy the value of the value hash to the value of the menu option
466 # if they have the same label.
467 #------------------------------------------------------------------------------
468 0 ▶sub setValues($$$){
Subroutine setValues: not called CC=3 SCAR=24.8
Pod undocumented
469 0 my ($self,$name,$values) = @_;
470  
471 0 my $L = $self->{'def'}{$name}{'opts'};
472 0 my $lvh;
473 0 foreach my $x (@{$L}) {
474 0 my $l = $x->{'label'};
475 0 my $v = $values->{$l};
476 0 ▶ next if( ! defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
477 0 $x->{'value'} = $v;
478 }
479 }
480  
481 #------------------------------------------------------------------------------
482 # Take a value hash {<label> => <value>} as input.
483 # Copy the value of the value hash to the default field of the menu option
484 # if they have the same label.
485 #------------------------------------------------------------------------------
486 0 ▶sub setDefaults($$$){
Subroutine setDefaults: not called CC=3 SCAR=24.8
Pod undocumented
487 0 my ($self,$name,$defaults) = @_;
488  
489 0 my $L = $self->{'def'}{$name}{'opts'};
490 0 my $lvh;
491 0 foreach my $x (@{$L}) {
492 0 my $l = $x->{'label'};
493 0 my $v = $defaults->{$l};
494 0 ▶ next if( ! defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
495 0 $x->{'default'} = $v;
496 }
497 }
498  
499 #------------------------------------------------------------------------------
500 # Take a hash {<label> => <jumpTarget>} as input.
501 # Copy the jumpTarget to the jump field of the menu option
502 # if they have the same label.
503 #------------------------------------------------------------------------------
504 0 ▶sub setJumps($$$){
Subroutine setJumps: not called CC=3 SCAR=24.8
Pod undocumented
505 0 my ($self,$name,$jumps) = @_;
506  
507 0 my $L = $self->{'def'}{$name}{'opts'};
508 0 my $lvh;
509 0 foreach my $x (@{$L}) {
510 0 my $l = $x->{'label'};
511 0 my $v = $jumps->{$l};
512 0 ▶ next if( ! defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
513 0 $x->{'jump'} = $v;
514 }
515 }
516  
517 #------------------------------------------------------------------------------
518 # Take a hash {<label> => <readOnly>} as input.
519 # Copy the readOnly to the readOnly field of the menu option
520 # if they have the same label.
521 #------------------------------------------------------------------------------
522 0 ▶sub setReadOnlys($$$){
Subroutine setReadOnlys: not called CC=3 SCAR=24.8
Pod undocumented
523 0 my ($self,$name,$readOnly) = @_;
524  
525 0 my $L = $self->{'def'}{$name}{'opts'};
526 0 my $lvh;
527 0 foreach my $x (@{$L}) {
528 0 my $l = $x->{'label'};
529 0 my $v = $readOnly->{$l};
530 0 ▶ next if( ! defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 0 0
531 0 $x->{'readOnly'} = $v;
532 }
533 }
534  
535 21 1;
536 __END__
↑ Summary blib/lib/Script/Toolbox/Util/Menues.pm »