8 use Variable::Magic qw<wizard cast dispell VMG_UVAR>;
11 use VPIT::TestHelpers;
14 load_or_skip('Hash::Util::FieldHash', undef, [ ],
15 'required for testing uvar interaction');
16 plan tests => 2 * 5 + 7 + 1;
18 skip_all 'No nice uvar magic for this perl';
21 use Variable::Magic::TestWatcher;
23 my $wiz = init_watcher [ qw<fetch store> ], 'huf';
24 ok defined($wiz), 'huf: wizard with uvar is defined';
25 is ref($wiz), 'SCALAR', 'huf: wizard with uvar is a scalar ref';
27 Hash::Util::FieldHash::fieldhash(\my %h);
30 bless $obj, 'Variable::Magic::Test::Mock';
33 my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash';
34 ok $res, 'huf: cast uvar magic on fieldhash succeeded';
36 my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash';
37 is $s, 5, 'huf: fetch on magical fieldhash succeeded';
39 watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash';
40 is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded';
42 ($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash';
43 ok $res, 'huf: dispell uvar magic on fieldhash succeeded';
47 is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok';
49 $Variable::Magic::TestWatcher::mg_end = { fetch => 1 };