9 plan skip_all => 'Variable::Magic 0.08 on 5.10 required to test uvar magic'
10 unless eval "use Variable::Magic 0.08; Variable::Magic::VMG_UVAR";
14 package Lexical::Types::Test::Ref;
16 use Variable::Magic qw/wizard cast/;
20 $wiz = wizard data => sub { +{ } },
21 fetch => sub { ++$_[1]->{fetch}; () },
22 store => sub { ++$_[1]->{store}; () };
26 my %h = ("_\L$_[2]" => (caller(0))[2]);
37 defined and diag "Using Variable::Magic $_" for $Variable::Magic::VERSION;
40 use Lexical::Types as => 'Lexical::Types::Test';
43 my $got = Variable::Magic::getdata(%{$_[1]}, $Lexical::Types::Test::Ref::wiz);
44 my ($test, $exp, $desc) = @_[0, 2, 3];
48 local @{$got}{qw/fetch store/}; delete @{$got}{qw/fetch store/};
50 @ret = eval { $test->() };
51 } elsif (defined $want) {
52 $ret[0] = eval { $test->() };
56 is_deeply $got, $exp, $desc;
58 return $want ? @ret : $ret[0];
62 my Ref $x; my $lx = __LINE__;
64 my $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch';
65 is $y, $lx, 'fetch correctly';
67 check { $x->{wat} = __LINE__ } $x, { store => 1 }, 'store'; my $l0 = __LINE__;
68 is $x->{wat}, $l0, 'store correctly';
70 my Ref $z = $x; my $lz = __LINE__;
72 $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch after being assigned';
73 is $y, $lx, 'fetch after being assigned correctly';
75 $y = check { $z->{_ref} } $z, { fetch => 1 }, 'fetch after being assigned to';
76 is $y, $lx, 'fetch after being assigned to correctly';
78 check { $z->{wat} = $x->{wat} + __LINE__ - $l0 } $z, { fetch => 1, store => 1 }, 'fetch/store';
79 is $z->{wat}, __LINE__-1, 'fetch/store correctly';
80 is $x->{wat}, __LINE__-2, 'fetch/store correctly';