8 use Variable::Magic qw/wizard cast dispell VMG_UVAR/;
11 plan skip_all => 'No nice uvar magic for this perl';
14 eval "use Hash::Util::FieldHash";
16 plan skip_all => 'Hash::Util::FieldHash required for testing uvar interaction';
19 my $v = $Hash::Util::FieldHash::VERSION;
20 diag "Using Hash::Util::FieldHash $v" if defined $v;
23 Hash::Util::FieldHash::fieldhash(\my %h);
26 bless $obj, 'Variable::Magic::Test::Mock';
29 my ($w, $c) = (undef, 0);
31 eval { $w = wizard fetch => sub { ++$c }, store => sub { --$c } };
32 is($@, '', 'wizard with uvar doesn\'t croak');
33 ok(defined $w, 'wizard with uvar is defined');
34 is(ref $w, 'SCALAR', 'wizard with uvar is a scalar ref');
36 my $res = eval { cast %h, $w };
37 is($@, '', 'cast uvar magic on fieldhash doesn\'t croak');
38 ok($res, 'cast uvar magic on fieldhash is valid');
41 is($s, 5, 'fetch magic on fieldhash doesn\'t clobber');
42 is($c, 1, 'fetch magic on fieldhash');
45 is($c, 0, 'store magic on fieldhash');
46 is($h{$obj}, 7, 'store magic on fieldhash doesn\'t clobber'); # $c == 1
48 $res = eval { dispell %h, $w };
49 is($@, '', 'dispell uvar magic on fieldhash doesn\'t croak');
50 ok($res, 'dispell uvar magic on fieldhash is valid');
54 is($s, 11, 'store/fetch on fieldhash after dispell still ok');