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