]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - samples/magic.pl
Importing Variable-Magic-0.03.tar.gz
[perl/modules/Variable-Magic.git] / samples / magic.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib qw{blib/arch blib/lib};
7 use Variable::Magic qw/wizard getsig cast dispell/;
8
9 sub foo { print STDERR "got ${$_[0]}!\n" }
10 my $bar = sub { ++${$_[0]}; print STDERR "now set to ${$_[0]}!\n"; };
11
12 my $a = 1;
13 my $sig;
14 {
15  my $wiz = wizard get  => \&foo,
16                   set  => $bar,
17                   free => sub {  print STDERR "deleted!\n"; };
18  $sig = getsig $wiz;
19  print "my sig is $sig\n";
20  cast $a, $wiz, qw/a b c/;
21  ++$a;              # "got 1!", "now set to 3!"
22  dispell $a, $wiz;
23  cast $a, $wiz;
24  my $b = 123;
25  cast $b, $wiz;
26 }                   # "deleted!"
27 my $b = $a;         # "got 3!"
28 $a = 3;             # "now set to 4!"
29 $b = 3;             # (nothing)
30 dispell $a, $sig;
31 $a = 4;             # (nothing)