11 use Variable::Magic qw<wizard cast dispell VMG_UVAR>;
14 load_or_skip_all('Hash::Util::FieldHash', undef, [ ]);
15 plan tests => 2 * 5 + 7 + 1;
17 skip_all 'No nice uvar magic for this perl';
20 use Variable::Magic::TestWatcher;
22 my $wiz = init_watcher [ qw<fetch store> ], 'huf';
23 ok defined($wiz), 'huf: wizard with uvar is defined';
24 is ref($wiz), 'SCALAR', 'huf: wizard with uvar is a scalar ref';
26 Hash::Util::FieldHash::fieldhash(\my %h);
29 bless $obj, 'Variable::Magic::Test::Mock';
32 my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash';
33 ok $res, 'huf: cast uvar magic on fieldhash succeeded';
35 my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash';
36 is $s, 5, 'huf: fetch on magical fieldhash succeeded';
38 watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash';
39 is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded';
41 ($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash';
42 ok $res, 'huf: dispell uvar magic on fieldhash succeeded';
46 is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok';
48 $Variable::Magic::TestWatcher::mg_end = { fetch => 1 };