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;
32 ok($res, 'uvar : cast succeeded');
33 ok(check(), 'uvar : cast didn\'t triggered the callback');
37 ok(check(), 'uvar : fetch directly');
38 ok($x, 'uvar : fetch directly correctly');
42 ok(check(), 'uvar : fetch by interpolation');
43 ok($x == 2, 'uvar : fetch by interpolation correctly');
47 ok(check(), 'uvar : store directly');
51 ok(check(), 'uvar : fetch and store');
52 ok($x == 5, 'uvar : fetch and store correctly');
56 ok(check(), 'uvar : exists');
57 ok($x, 'uvar : exists correctly');
61 ok(check(), 'uvar : delete existing key');
62 ok($x == 5, 'uvar : delete existing key correctly');
66 ok(check(), 'uvar : delete non-existing key');
67 ok(!defined $x, 'uvar : delete non-existing key correctly');
69 my $wiz2 = wizard 'fetch' => sub { 0 };
70 my %h2 = (a => 37, b => 2, c => 3);
74 local $SIG{__WARN__} = sub { die };
77 ok(!$@, 'uvar : fetch with incomplete magic');
78 ok($x == 37, 'uvar : fetch with incomplete magic correctly');
81 local $SIG{__WARN__} = sub { die };
84 ok(!$@, 'uvar : store with incomplete magic');
85 ok($h2{a} == 73, 'uvar : store with incomplete magic correctly');