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 qw/fieldhash/";
16 plan skip_all => 'Hash::Util::FieldHash required for testing uvar interaction';
23 bless \(my $obj = {}), 'Variable::Magic::Test::Mock';
26 my ($w, $c) = (undef, 0);
28 eval { $w = wizard fetch => sub { ++$c }, store => sub { --$c } };
29 ok(!$@, "wizard with uvar creation error ($@)");
30 ok(defined $w, 'wizard with uvar is defined');
31 ok(ref($w) eq 'SCALAR', 'wizard with uvar is a scalar ref');
33 my $res = eval { cast %h, $w };
34 ok(!$@, "cast uvar magic on fieldhash croaks ($@)");
35 ok($res, 'cast uvar magic on fieldhash invalid');
38 ok($s == 5, 'fetch magic on fieldhash doesn\'t clobber');
39 ok($c == 1, 'fetch magic on fieldhash');
42 ok($c == 0, 'store magic on fieldhash');
43 ok($h{$obj} == 7, 'store magic on fieldhash doesn\'t clobber'); # $c == 1
45 $res = eval { dispell %h, $w };
46 ok(!$@, "dispell uvar magic on fieldhash croaks ($@)");
47 ok($res, 'dispell uvar magic on fieldhash invalid');
51 ok($s == 11, 'store/fetch on fieldhash after dispell still ok');