8 use Variable::Magic qw/wizard cast dispell VMG_UVAR/;
13 plan skip_all => 'No nice uvar magic for this perl';
20 is join(':', map { (defined) ? $_ : 'u' } @c[0 .. 3]),
21 join(':', map { (defined) ? $_ : 'u' } @x[0 .. 3]),
25 my $wiz = wizard 'fetch' => sub { ++$c[0] },
26 'store' => sub { ++$c[1] },
27 'exists' => sub { ++$c[2] },
28 'delete' => sub { ++$c[3] };
29 check('uvar : create wizard');
31 my %h = (a => 1, b => 2, c => 3);
32 my $res = cast %h, $wiz;
33 ok($res, 'uvar : cast succeeded');
34 check( 'uvar : cast didn\'t triggered the callback');
38 check( 'uvar : fetch directly');
39 ok($x, 'uvar : fetch directly correctly');
43 check( 'uvar : fetch by interpolation');
44 is($x, 2, 'uvar : fetch by interpolation correctly');
48 check('uvar : store directly');
52 check( 'uvar : fetch and store');
53 is($x, 5, 'uvar : fetch and store correctly');
57 check( 'uvar : exists');
58 ok($x, 'uvar : exists correctly');
62 check( 'uvar : delete existing key');
63 is($x, 5, 'uvar : delete existing key correctly');
67 check( 'uvar : delete non-existing key');
68 ok(!defined $x, 'uvar : delete non-existing key correctly');
70 my $wiz2 = wizard 'fetch' => sub { 0 };
71 my %h2 = (a => 37, b => 2, c => 3);
75 local $SIG{__WARN__} = sub { die };
78 is($@, '', 'uvar : fetch with incomplete magic');
79 is($x, 37, 'uvar : fetch with incomplete magic correctly');
82 local $SIG{__WARN__} = sub { die };
85 is($@, '', 'uvar : store with incomplete magic');
86 is($h2{a}, 73, 'uvar : store with incomplete magic correctly');