8 use Variable::Magic qw/wizard cast dispell VMG_UVAR/;
13 plan skip_all => 'No nice uvar magic for this perl';
20 for (0 .. 3) { return 0 unless $c[$_] == $x[$_]; }
24 my $wiz = wizard 'fetch' => sub { ++$c[0] },
25 'store' => sub { ++$c[1] },
26 'exists' => sub { ++$c[2] },
27 'delete' => sub { ++$c[3] };
28 ok(check(), 'uvar : create wizard');
30 my %h = (a => 1, b => 2, c => 3);
31 my $res = cast %h, $wiz;
33 ok($res, 'uvar : cast succeeded');
34 ok(check(), 'uvar : cast didn\'t triggered the callback');
38 ok(check(), 'uvar : fetch directly');
39 ok($x, 'uvar : fetch directly correctly');
43 ok(check(), 'uvar : fetch by interpolation');
44 ok($x == 2, 'uvar : fetch by interpolation correctly');
48 ok(check(), 'uvar : store directly');
52 ok(check(), 'uvar : fetch and store');
53 ok($x == 5, 'uvar : fetch and store correctly');
57 ok(check(), 'uvar : exists');
58 ok($x, 'uvar : exists correctly');
62 ok(check(), 'uvar : delete existing key');
63 ok($x == 5, 'uvar : delete existing key correctly');
67 ok(check(), 'uvar : delete non-existing key');
68 ok(!defined $x, 'uvar : delete non-existing key correctly');