X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=samples%2Fuvar.pl;h=d1e52abdc5559950b82e27bbc2a1430ff1c3fd9a;hb=HEAD;hp=6620aec4f8952bb9213980796a768c25ba7aa6ea;hpb=6f35a291f0c453d34b617ee9eb03d2a68c410614;p=perl%2Fmodules%2FVariable-Magic.git diff --git a/samples/uvar.pl b/samples/uvar.pl index 6620aec..d1e52ab 100755 --- a/samples/uvar.pl +++ b/samples/uvar.pl @@ -1,18 +1,27 @@ #!/usr/bin/env perl -use lib qw{blib/arch blib/lib}; - use strict; use warnings; -use Variable::Magic qw/wizard cast/; - -my $w = wizard map { - my $s = $_; $s => sub { print STDERR "$s $_[2]!\n" } -} qw/fetch store exists delete/; -my %h; -cast %h, $w; -$h{'foo'} = 1; -print STDERR "#", $h{'foo'}, "#\n"; -my $y = exists $h{'foo'}; -delete $h{'foo'}; +use lib qw; +use Variable::Magic qw; + +my $wiz = wizard + fetch => sub { print STDERR "$_[0] FETCH KEY $_[2]\n" }, + store => sub { print STDERR "$_[0] STORE KEY $_[2]\n" }, + 'exists' => sub { print STDERR "$_[0] EXISTS KEY $_[2]\n" }, + 'delete' => sub { print STDERR "$_[0] DELETE KEY $_[2]\n" }; + +my %h = (foo => 1, bar => 2); +cast %h, $wiz; + +print STDERR "foo was $h{foo}\n"; +$h{foo} = 3; +print STDERR "now foo is $h{foo}\n"; + +print STDERR "foo exists!\n" if exists $h{foo}; + +my $d = delete $h{foo}; +print STDERR "foo deleted, got $d\n"; + +dispell %h, $wiz;