| 1 |
#!perl -T |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More; |
| 7 |
|
| 8 |
use lib 't/lib'; |
| 9 |
use VPIT::TestHelpers; |
| 10 |
|
| 11 |
use Variable::Magic qw<wizard cast dispell VMG_UVAR>; |
| 12 |
|
| 13 |
if (VMG_UVAR) { |
| 14 |
load_or_skip_all('Hash::Util::FieldHash', undef, [ ]); |
| 15 |
plan tests => 2 * 5 + 7 + 1; |
| 16 |
} else { |
| 17 |
skip_all 'No nice uvar magic for this perl'; |
| 18 |
} |
| 19 |
|
| 20 |
use Variable::Magic::TestWatcher; |
| 21 |
|
| 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'; |
| 25 |
|
| 26 |
Hash::Util::FieldHash::fieldhash(\my %h); |
| 27 |
|
| 28 |
my $obj = { }; |
| 29 |
bless $obj, 'Variable::Magic::Test::Mock'; |
| 30 |
$h{$obj} = 5; |
| 31 |
|
| 32 |
my ($res) = watch { cast %h, $wiz } { }, 'cast uvar magic on fieldhash'; |
| 33 |
ok $res, 'huf: cast uvar magic on fieldhash succeeded'; |
| 34 |
|
| 35 |
my ($s) = watch { $h{$obj} } { fetch => 1 }, 'fetch on magical fieldhash'; |
| 36 |
is $s, 5, 'huf: fetch on magical fieldhash succeeded'; |
| 37 |
|
| 38 |
watch { $h{$obj} = 7 } { store => 1 }, 'store on magical fieldhash'; |
| 39 |
is $h{$obj}, 7, 'huf: store on magical fieldhash succeeded'; |
| 40 |
|
| 41 |
($res) = watch { dispell %h, $wiz } { }, 'dispell uvar magic on fieldhash'; |
| 42 |
ok $res, 'huf: dispell uvar magic on fieldhash succeeded'; |
| 43 |
|
| 44 |
$h{$obj} = 11; |
| 45 |
$s = $h{$obj}; |
| 46 |
is $s, 11, 'huf: store/fetch on fieldhash after dispell still ok'; |
| 47 |
|
| 48 |
$Variable::Magic::TestWatcher::mg_end = { fetch => 1 }; |