1
$Tk::waitVariableX::VERSION = '1.0';
3
package Tk::waitVariableX;
9
@EXPORT = qw/waitVariableX/;
16
my ($parent, $millis) = (shift, shift); # @_ has list of var refs
18
croak "waitVariableX: no milliseconds." unless defined $millis;
19
my ($callback, $st, $tid, @watch, $why);
21
if (ref $millis eq 'ARRAY') {
22
$callback = Tk::Callback->new($millis->[1]);
23
$millis = $millis->[0];
26
$st = sub {my $argv = $_[0]->Args('-store'); $why = $argv->[0]};
27
foreach my $vref (@_) {
29
Tie::Watch->new(-variable => $vref, -store => [$st, $vref]);
31
$tid = $parent->after($millis => sub {$why = 0}) unless $millis == 0;
33
$parent->waitVariable(\$why); # wait for timer or watchpoint(s)
35
$_->Unwatch foreach @watch;
36
$parent->afterCancel($tid);
37
$callback->Call($why) if defined $callback;
39
return $why; # why we stopped waiting: 0 or $vref
48
Tk::waitVariableX - a waitVariable with extensions.
52
use Tk::waitVariableX;
54
$splash->waitVariableX( [$millis, $destroy_splashscreen], \$v1, \$v2} );
58
This subroutine waits for a list of variables, with a timeout - the
59
subroutine returns when one of the variables changes value or the timeout
60
expires, whichever occurs first.
62
Although the millisecond parameter is required, it may be zero, which
63
effects no timeout. The milliscond paramter may also be an array of
64
two elements, the first the millisecond value, and the second a
65
normal Per/Tk callback. The callback is invoked just before
66
waitVariableX returns.
68
Callback format is patterned after the Perl/Tk scheme: supply either a
69
code reference, or, supply an array reference and pass the callback
70
code reference in the first element of the array, followed by callback
75
Copyright (C) 2000 - 2002 Stephen O. Lidie. All rights reserved.
77
This program is free software; you can redistribute it and/or modify it under
78
the same terms as Perl itself.