3 use Test::More tests => 14;
5 use Variable::Magic qw/wizard getdata cast dispell/;
10 wizard data => sub { return { foo => 12, bar => 27 } },
11 get => sub { $c += $_[1]->{foo}; $_[1]->{foo} = $c },
12 set => sub { $c += $_[1]->{bar}; $_[1]->{bar} = $c }
14 ok(!$@, "wizard creation error ($@)");
15 ok(defined $wiz, 'wizard is defined');
16 ok(ref $wiz eq 'SCALAR', 'wizard is a scalar ref');
19 my $res = eval { cast $a, $wiz };
20 ok(!$@, "cast error 1 ($@)");
21 ok($res, 'cast error 2');
23 my $data = eval { getdata $a, $wiz };
24 ok(!$@, "getdata error 1 ($@)");
25 ok($res, 'getdata error 2');
26 ok($data && ref($data) eq 'HASH'
27 && exists $data->{foo} && $data->{foo} eq 12
28 && exists $data->{bar} && $data->{bar} eq 27,
29 'private data creation ok');
32 ok($c == 13, 'get magic : pass data');
33 ok($data->{foo} == 13, 'get magic : data updated');
36 ok($c == 40, 'set magic : pass data');
37 ok($data->{bar} == 40, 'set magic : pass data');
39 $res = eval { dispell $a, $wiz };
40 ok(!$@, "dispell error 1 ($@)");
41 ok($res, 'dispell error 2');