File: magic.pl

package info (click to toggle)
libvariable-magic-perl 0.64-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: perl: 4,256; ansic: 633; makefile: 8
file content (26 lines) | stat: -rwxr-xr-x 654 bytes parent folder | download | duplicates (6)
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
#!/usr/bin/env perl

use strict;
use warnings;

use lib qw<blib/arch blib/lib>;
use Variable::Magic qw<wizard cast dispell>;

sub foo { print STDERR "got ${$_[0]}!\n" }
my $bar = sub { ++${$_[0]}; print STDERR "now set to ${$_[0]}!\n"; };

my $a = 1;
{
 my $wiz = wizard get  => \&foo,
                  set  => $bar,
                  free => sub { print STDERR "deleted!\n"; };
 cast $a, $wiz, qw<a b c>;
 ++$a;              # "got 1!", "now set to 3!"
 dispell $a, $wiz;
 cast $a, $wiz;
 my $b = 123;
 cast $b, $wiz;
}                   # "deleted!"
my $b = $a;         # "got 3!"
$a = 3;             # "now set to 4!"
$b = 3;             # (nothing)