File: watchvar.pl

package info (click to toggle)
libgtk-perl 0.7009-12
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,956 kB
  • ctags: 2,260
  • sloc: perl: 13,998; xml: 9,919; ansic: 2,894; makefile: 64; cpp: 45
file content (33 lines) | stat: -rw-r--r-- 728 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl -w
use Gtk '-init';

$data = "Initial val";

Gtk->watch_add($data, 0, sub {
	print "\$data changed to '$_[0]'\n";
	Gtk->main_quit if $data eq 'quit';
	# get some noise
	$data = 'jumpy' unless $data eq 'jumpy';
	1;
});
# has a highter priority and gets called first
Gtk->watch_add($data, -100, sub {
	print "Another change handler for \$data\n";
});
{	
	@data2 = (1);
	my $id;
	$id = Gtk->watch_add($data2[0], 0, sub {
		print "\$data2 changed to $data2[0]\n";
		Gtk->watch_remove($id);
		1;
	});
	# try to be evil
	# undef @data2;
}
Gtk->timeout_add(250, sub {$data = "Yadda yadda";$data2[0]++;1});
Gtk->timeout_add(400, sub {$data = "Yappa yappa";0});
Gtk->timeout_add(600, sub {$data = "quit";0});

main Gtk;