]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - samples/uvar.pl
This is 0.64
[perl/modules/Variable-Magic.git] / samples / uvar.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use lib qw<blib/arch blib/lib>;
7 use Variable::Magic qw<wizard cast dispell>;
8
9 my $wiz = wizard
10  fetch  => sub { print STDERR "$_[0] FETCH KEY $_[2]\n" },
11  store  => sub { print STDERR "$_[0] STORE KEY $_[2]\n" },
12  'exists' => sub { print STDERR "$_[0] EXISTS KEY $_[2]\n" },
13  'delete' => sub { print STDERR "$_[0] DELETE KEY $_[2]\n" };
14
15 my %h = (foo => 1, bar => 2);
16 cast %h, $wiz;
17
18 print STDERR "foo was $h{foo}\n";
19 $h{foo} = 3;
20 print STDERR "now foo is $h{foo}\n";
21
22 print STDERR "foo exists!\n" if exists $h{foo};
23
24 my $d = delete $h{foo};
25 print STDERR "foo deleted, got $d\n";
26
27 dispell %h, $wiz;