8 use Variable::Magic qw<wizard cast dispell VMG_UVAR>;
11 plan skip_all => 'No nice uvar magic for this perl';
16 if (eval { require Hash::Util::FieldHash; 1 }) {
17 plan tests => 2 * 5 + 7 + 1;
18 defined and diag "Using Hash::Util::FieldHash $_"
19 for $Hash::Util::FieldHash::VERSION;
21 plan skip_all => 'Hash::Util::FieldHash required for testing uvar interaction'
26 use Variable::Magic::TestWatcher;
28 my $wiz = init_watcher [ qw<fetch store> ], 'huf';
29 ok defined($wiz), 'huf: wizard with uvar is defined';
30 is ref($wiz), 'SCALAR', 'huf: wizard with uvar is a scalar ref';
32 Hash::Util::FieldHash::fieldhash(\my %h);
35 bless $obj, 'Variable::Magic::Test::Mock';
38 my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash';
39 ok $res, 'huf: cast uvar magic on fieldhash succeeded';
41 my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash';
42 is $s, 5, 'huf: fetch on magical fieldhash succeeded';
44 watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash';
45 is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded';
47 ($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash';
48 ok $res, 'huf: dispell uvar magic on fieldhash succeeded';
52 is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok';
54 $Variable::Magic::TestWatcher::mg_end = { fetch => 1 };