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';
18 plan tests => 2 * 5 + 7 + 1;
19 my $v = $Hash::Util::FieldHash::VERSION;
20 diag "Using Hash::Util::FieldHash $v" if defined $v;
24 use Variable::Magic::TestWatcher;
26 my $wiz = init_watcher [ qw/fetch store/ ], 'huf';
27 ok defined($wiz), 'huf: wizard with uvar is defined';
28 is ref($wiz), 'SCALAR', 'huf: wizard with uvar is a scalar ref';
30 Hash::Util::FieldHash::fieldhash(\my %h);
33 bless $obj, 'Variable::Magic::Test::Mock';
36 my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash';
37 ok $res, 'huf: cast uvar magic on fieldhash succeeded';
39 my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash';
40 is $s, 5, 'huf: fetch on magical fieldhash succeeded';
42 watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash';
43 is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded';
45 ($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash';
46 ok $res, 'huf: dispell uvar magic on fieldhash succeeded';
50 is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok';
52 $Variable::Magic::TestWatcher::mg_end = { fetch => 1 };