line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Script::Toolbox::Util::Menues; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# THIS IS DEPRECATED CODE. |
4
|
|
|
|
|
|
|
# DON'T USE IT. |
5
|
|
|
|
|
|
|
# USE Script::Toolbox::Util::Menus |
6
|
|
|
|
|
|
|
|
7
|
10
|
|
|
10
|
|
73
|
use strict; |
|
10
|
|
|
|
|
26
|
|
|
10
|
|
|
|
|
367
|
|
8
|
10
|
|
|
10
|
|
57
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
10
|
|
|
|
|
29
|
|
|
10
|
|
|
|
|
24941
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
@EXPORT = qw( |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Preloaded methods go here. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
# {'menueName>' =>[{label=>,value=>,jump=>,argv=>},...]} |
25
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
sub new |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
|
|
0
|
0
|
|
my $classname = shift; |
29
|
0
|
|
|
|
|
|
my $self = {}; |
30
|
0
|
|
|
|
|
|
bless( $self, $classname ); |
31
|
0
|
|
|
|
|
|
$self->_init( @_ ); |
32
|
0
|
|
|
|
|
|
return $self; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
36
|
|
|
|
|
|
|
# {'' =>[{label=>,value=>,jump=>,argv=>},...]} |
37
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
38
|
|
|
|
|
|
|
sub _init |
39
|
|
|
|
|
|
|
{ |
40
|
0
|
|
|
0
|
|
|
my ($self, $newDef) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->{'def'} = {}; |
43
|
0
|
0
|
|
|
|
|
return if( ref $newDef ne 'HASH' ); |
44
|
0
|
|
|
|
|
|
$self->addMenue($newDef); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
48
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
49
|
|
|
|
|
|
|
sub _getHead($){ |
50
|
0
|
|
|
0
|
|
|
my ($self,$def) = @_; |
51
|
0
|
|
|
|
|
|
my $s = ''; |
52
|
0
|
|
|
|
|
|
foreach my $k ( @{$def} ) { |
|
0
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
next if( ! defined $k->{'header'} ); |
54
|
0
|
|
|
|
|
|
$s .= sprintf "%s", $k->{'header'}; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
|
return $s ne '' ? $s : undef; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
59
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
60
|
|
|
|
|
|
|
sub _getFoot($){ |
61
|
0
|
|
|
0
|
|
|
my ($self,$def) = @_; |
62
|
0
|
|
|
|
|
|
my $s = ''; |
63
|
0
|
|
|
|
|
|
foreach my $k ( @{$def} ) { |
|
0
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
next if( ! defined $k->{'footer'} ); |
65
|
0
|
|
|
|
|
|
$s .= sprintf "%s", $k->{'footer'}; |
66
|
|
|
|
|
|
|
} |
67
|
0
|
0
|
|
|
|
|
return $s ne '' ? $s : undef; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
71
|
|
|
|
|
|
|
# ... |
72
|
|
|
|
|
|
|
# {'label'=>'Call the submenue 1','jump'=>'SubMenue1'} |
73
|
|
|
|
|
|
|
# SubMenue1: is the name of a previous defined menue in the same menues container |
74
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
75
|
|
|
|
|
|
|
sub _resolveSubmenue($){ |
76
|
0
|
|
|
0
|
|
|
my ($self,$opt) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
return if( !defined $opt->{'jump'} ); |
79
|
0
|
0
|
|
|
|
|
return if( ref \$opt->{'jump'} ne 'SCALAR' ); |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
my $subName = $opt->{'jump'}; |
82
|
0
|
|
|
|
|
|
$opt->{'jump'} = \&Script::Toolbox::Util::Menues::run; |
83
|
0
|
|
|
|
|
|
$opt->{'argv'} = [$self,$subName]; |
84
|
0
|
|
|
|
|
|
return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
88
|
|
|
|
|
|
|
# [{label=>,value=>,jump=>,argv=>},...]} |
89
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
90
|
|
|
|
|
|
|
sub _getOpts($){ |
91
|
0
|
|
|
0
|
|
|
my ($self,$def) = @_; |
92
|
0
|
|
|
|
|
|
my @s; |
93
|
0
|
|
|
|
|
|
foreach my $k ( @{$def} ) { |
|
0
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
next if( ! defined $k->{'label'} ); |
95
|
0
|
|
|
|
|
|
$self->_resolveSubmenue($k); |
96
|
0
|
|
|
|
|
|
push @s, $k; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
return \@s; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
102
|
|
|
|
|
|
|
# , [{label=>,value=>,jump=>,argv=>},...]} |
103
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
104
|
|
|
|
|
|
|
sub addMenue($){ |
105
|
0
|
|
|
0
|
0
|
|
my ($self,$newDef) = @_; |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
return if( ref $newDef ne 'HASH' ); |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
foreach my $name ( keys %{$newDef} ){ |
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $def = $newDef->{$name}; |
111
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'head'} = $self->_getHead($def); |
112
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'foot'} = $self->_getFoot($def); |
113
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'opts'} = $self->_getOpts($def); |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
119
|
|
|
|
|
|
|
# , |
120
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
121
|
|
|
|
|
|
|
sub setHeader($$){ |
122
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$head) = @_; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'head'} = $head; |
125
|
0
|
|
|
|
|
|
return; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
130
|
|
|
|
|
|
|
# , |
131
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
132
|
|
|
|
|
|
|
sub setAutoHeader($){ |
133
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
134
|
|
|
|
|
|
|
|
135
|
0
|
0
|
|
|
|
|
if( defined $name) { |
136
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'autohead'} = 1; |
137
|
0
|
|
|
|
|
|
return; |
138
|
|
|
|
|
|
|
} |
139
|
0
|
|
|
|
|
|
foreach my $n (keys %{$self->{'def'}} ){ |
|
0
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$self->{'def'}{$n}{'autohead'} = 1; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
145
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
146
|
|
|
|
|
|
|
sub _delAutoHead($){ |
147
|
0
|
|
|
0
|
|
|
my ($ah) = @_; |
148
|
0
|
0
|
|
|
|
|
delete $ah->{'autohead'} if( defined $ah->{'autohead'} ); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
152
|
|
|
|
|
|
|
# , |
153
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
154
|
|
|
|
|
|
|
sub delAutoHeader($){ |
155
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
156
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
if( defined $name) { |
158
|
0
|
|
|
|
|
|
_delAutoHead( $self->{'def'}{$name} ); |
159
|
0
|
|
|
|
|
|
return; |
160
|
|
|
|
|
|
|
} |
161
|
0
|
|
|
|
|
|
foreach my $n (keys %{$self->{'def'}} ){ |
|
0
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
_delAutoHead( $self->{'def'}{$n} ); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
167
|
|
|
|
|
|
|
# , |
168
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
169
|
|
|
|
|
|
|
sub getHeader($){ |
170
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $autoHead = $self->{'def'}{$name}{'autohead'}; |
173
|
0
|
|
|
|
|
|
my $H; |
174
|
0
|
|
|
|
|
|
my $h = $self->{'def'}{$name}{'head'}; |
175
|
0
|
0
|
0
|
|
|
|
$h = "Menue: $name" if(!defined $h && defined $autoHead); |
176
|
0
|
0
|
|
|
|
|
$H = {'header' => $h} if( defined $h ); |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return $H; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
182
|
|
|
|
|
|
|
# , |
183
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
184
|
|
|
|
|
|
|
sub setFooter($$){ |
185
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$foot) = @_; |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'foot'} = $foot; |
188
|
0
|
|
|
|
|
|
return; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
192
|
|
|
|
|
|
|
# , |
193
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
194
|
|
|
|
|
|
|
sub getFooter($){ |
195
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
my $foot = $self->{'def'}{$name}{'foot'} ; |
198
|
0
|
0
|
|
|
|
|
return {'footer'=> $foot} if(defined $foot); |
199
|
0
|
|
|
|
|
|
return undef; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
203
|
|
|
|
|
|
|
# , {label=>,value=>,jump=>,argv=>} |
204
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
205
|
|
|
|
|
|
|
sub addOption($$){ |
206
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$opt) = @_; |
207
|
|
|
|
|
|
|
|
208
|
0
|
0
|
|
|
|
|
$self->{'def'}{$name}{'opts'} = [] if( ! defined $self->{'def'}{$name}{'opts'} ); |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
|
|
|
|
$self->_resolveSubmenue($opt); |
211
|
0
|
|
|
|
|
|
push @{$self->{'def'}{$name}{'opts'}}, $opt; |
|
0
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
return; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
216
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
217
|
|
|
|
|
|
|
sub _getParams($){ |
218
|
0
|
|
|
0
|
|
|
my ($self,$name) = @_; |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
my @p; |
221
|
0
|
0
|
|
|
|
|
my $s = $self->getHeader($name); push @p, $s if( defined $s ); |
|
0
|
|
|
|
|
|
|
222
|
0
|
0
|
|
|
|
|
$s = $self->getFooter($name); push @p, $s if( defined $s ); |
|
0
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
push @p, {'label'=>'RETURN'}; |
224
|
|
|
|
|
|
|
map { |
225
|
0
|
|
|
|
|
|
push @p, $_; |
226
|
0
|
|
|
|
|
|
} @{$self->{'def'}{$name}{'opts'}}; |
|
0
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
|
return \@p; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
232
|
|
|
|
|
|
|
# Validate parameters and rearrange parameters in case of internal menue call |
233
|
|
|
|
|
|
|
# ( submenue call by name). |
234
|
|
|
|
|
|
|
# Return 0 if parameters invalid. |
235
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
236
|
|
|
|
|
|
|
sub validateParams($$){ |
237
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
238
|
0
|
0
|
|
|
|
|
return 0 if( ! defined $$self ); |
239
|
0
|
0
|
|
|
|
|
if( ref $$self eq 'ARRAY' ) { |
240
|
0
|
0
|
|
|
|
|
return 0 if( ref $$self->[0] ne 'Script::Toolbox::Util::Menues' ); |
241
|
0
|
|
|
|
|
|
$$name = $$self->[1]; |
242
|
0
|
|
|
|
|
|
$$self = $$self->[0]; |
243
|
|
|
|
|
|
|
} |
244
|
0
|
0
|
|
|
|
|
return 1 if( defined $$self->{'def'}{$$name} ); |
245
|
0
|
|
|
|
|
|
Script::Toolbox::Util::Log("\nWARNING: Submenue $$name is not defined!"); |
246
|
0
|
|
|
|
|
|
sleep 5; |
247
|
0
|
|
|
|
|
|
return 0; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
251
|
|
|
|
|
|
|
# Run the named menue as long as $cnt is true. $cnt will be decremented by each |
252
|
|
|
|
|
|
|
# loop. That means if $cnt starts with 0 we have an endless loop. |
253
|
|
|
|
|
|
|
# Return the number of the last selected option. |
254
|
|
|
|
|
|
|
# The option 'RETURN' will be created automaticly and has option number 0 by |
255
|
|
|
|
|
|
|
# default. |
256
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
257
|
|
|
|
|
|
|
sub run($$){ |
258
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$cnt) = @_; |
259
|
|
|
|
|
|
|
|
260
|
0
|
0
|
|
|
|
|
return if( ! validateParams(\$self,\$name) ); |
261
|
0
|
0
|
|
|
|
|
$cnt = 1 if( ! defined $cnt); |
262
|
0
|
0
|
|
|
|
|
$cnt = 1 if( $cnt !~ /^[-]?\d+$/ ); |
263
|
0
|
0
|
|
|
|
|
$cnt =-1 if( $cnt == 0 ); |
264
|
0
|
|
|
|
|
|
my $o; my $m; |
265
|
0
|
|
|
|
|
|
while($cnt--) { |
266
|
0
|
|
|
|
|
|
my $p = $self->_getParams($name); |
267
|
0
|
|
|
|
|
|
($o,$m) = Script::Toolbox::Util::Menue($p); |
268
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'selected'}{'num'} = $o; |
269
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'selected'}{'opt'} = $m->[$o]; |
270
|
0
|
0
|
|
|
|
|
return $o if( $o == 0 ); |
271
|
|
|
|
|
|
|
} |
272
|
0
|
|
|
|
|
|
return $o; |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
276
|
|
|
|
|
|
|
# Return current nmber of selected option. |
277
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
278
|
|
|
|
|
|
|
sub currNumber($){ |
279
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
280
|
0
|
|
|
|
|
|
return $self->{'def'}{$name}{'selected'}{'num'}; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
284
|
|
|
|
|
|
|
# Return current label of selected option. |
285
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
286
|
|
|
|
|
|
|
sub currLabel($){ |
287
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
288
|
0
|
|
|
|
|
|
return $self->{'def'}{$name}{'selected'}{'opt'}{'label'}; |
289
|
|
|
|
|
|
|
} |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
292
|
|
|
|
|
|
|
# Return current value of selected option. |
293
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
294
|
|
|
|
|
|
|
sub currValue($){ |
295
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
296
|
0
|
|
|
|
|
|
return $self->{'def'}{$name}{'selected'}{'opt'}{'value'}; |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
300
|
|
|
|
|
|
|
# Return the callback address and argv address of selected option. |
301
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
302
|
|
|
|
|
|
|
sub currJump($){ |
303
|
0
|
|
|
0
|
0
|
|
my ($self,$name) = @_; |
304
|
|
|
|
|
|
|
|
305
|
0
|
|
|
|
|
|
my $call = $self->{'def'}{$name}{'selected'}{'opt'}{'jump'}; |
306
|
0
|
|
|
|
|
|
my $args = $self->{'def'}{$name}{'selected'}{'opt'}{'argv'}; |
307
|
|
|
|
|
|
|
|
308
|
0
|
|
|
|
|
|
return $call,$args; |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
312
|
|
|
|
|
|
|
# Set a new label for current selected option. Return old label. |
313
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
314
|
|
|
|
|
|
|
sub setCurrLabel($$){ |
315
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$newLabel) = @_; |
316
|
|
|
|
|
|
|
|
317
|
0
|
|
|
|
|
|
my $cn = $self->currNumber($name) -1; |
318
|
0
|
|
|
|
|
|
my $ol = $self->{'def'}{$name}{'opts'}[$cn]{'label'}; |
319
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'opts'}[$cn]{'label'} = $newLabel; |
320
|
0
|
|
|
|
|
|
return $ol; |
321
|
|
|
|
|
|
|
} |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
324
|
|
|
|
|
|
|
# Set a new value for current selected option. Return old value. |
325
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
326
|
|
|
|
|
|
|
sub setCurrValue($$){ |
327
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$newValue) = @_; |
328
|
|
|
|
|
|
|
|
329
|
0
|
|
|
|
|
|
my $cn = $self->currNumber($name) -1; |
330
|
0
|
|
|
|
|
|
my $ov = $self->{'def'}{$name}{'opts'}[$cn]{'value'}; |
331
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'opts'}[$cn]{'value'} = $newValue; |
332
|
0
|
|
|
|
|
|
return $ov; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
336
|
|
|
|
|
|
|
# Set new callback address und argv for the current selected option. |
337
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
338
|
|
|
|
|
|
|
sub setCurrJump($$$){ |
339
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$callBack,$argv) = @_; |
340
|
|
|
|
|
|
|
|
341
|
0
|
|
|
|
|
|
my $cn = $self->currNumber($name) -1; |
342
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'opts'}[$cn]{'jump'} = $callBack; |
343
|
0
|
|
|
|
|
|
$self->{'def'}{$name}{'opts'}[$cn]{'argv'} = $argv; |
344
|
0
|
|
|
|
|
|
return $callBack,$argv; |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
348
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
349
|
|
|
|
|
|
|
sub _invalidParam($$$$$){ |
350
|
0
|
|
|
0
|
|
|
my ($self,$name,$pattern,$search,$return) = @_; |
351
|
0
|
0
|
|
|
|
|
return 1 if( !defined $pattern ); |
352
|
0
|
0
|
|
|
|
|
return 1 if( !defined $search ); |
353
|
0
|
0
|
|
|
|
|
return 1 if( !defined $return ); |
354
|
0
|
0
|
|
|
|
|
return 1 if( !defined $self->{'def'}{$name}{'opts'}); |
355
|
0
|
0
|
|
|
|
|
return 1 if( $search !~ /(number|value|label)/ ); |
356
|
0
|
0
|
|
|
|
|
return 1 if( $return !~ /(number|value|label)/ ); |
357
|
0
|
|
|
|
|
|
return 0; |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
361
|
|
|
|
|
|
|
# Search the labels array for $pattern matching in $search. If matching return |
362
|
|
|
|
|
|
|
# value of type return. |
363
|
|
|
|
|
|
|
# $pattern='[Mm]ax' $search='value' $return='label' |
364
|
|
|
|
|
|
|
# => returns all labels where value column matching Max or max. |
365
|
|
|
|
|
|
|
# search: /(label,number,value)/ |
366
|
|
|
|
|
|
|
# return: /(label,number,value)/ |
367
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
368
|
|
|
|
|
|
|
sub getMatching($$$$){ |
369
|
0
|
|
|
0
|
0
|
|
my ($self,$name,$pattern,$search,$return) = @_; |
370
|
0
|
0
|
|
|
|
|
return '' if( _invalidParam($self,$name,$pattern,$search,$return)); |
371
|
|
|
|
|
|
|
|
372
|
0
|
|
|
|
|
|
my $L = $self->{'def'}{$name}{'opts'}; |
373
|
0
|
|
|
|
|
|
my @R; |
374
|
0
|
|
|
|
|
|
my $i=1; |
375
|
0
|
|
|
|
|
|
foreach my $l ( @{$L} ){ |
|
0
|
|
|
|
|
|
|
376
|
0
|
0
|
|
|
|
|
if( $search eq 'number' ){ |
377
|
0
|
0
|
|
|
|
|
push @R, $l->{$return} if( $i =~ /$pattern/); |
378
|
0
|
|
|
|
|
|
$i++; |
379
|
|
|
|
|
|
|
}else{ |
380
|
0
|
0
|
|
|
|
|
next if( !defined $l->{$search} ); |
381
|
0
|
0
|
|
|
|
|
next if( $l->{$search} !~ /$pattern/ ); |
382
|
0
|
|
|
|
|
|
push @R, $l->{$return}; |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
} |
385
|
0
|
|
|
|
|
|
return \@R; |
386
|
|
|
|
|
|
|
} |
387
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
|
389
|
|
|
|
|
|
|
1; |
390
|
|
|
|
|
|
|
__END__ |