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]);
39 use Lexical::Types as => 'Lexical::Types::Test';
42 my $got = Variable::Magic::getdata(%{$_[1]}, $Lexical::Types::Test::Ref::wiz);
43 my ($test, $exp, $desc) = @_[0, 2, 3];
47 local @{$got}{qw/fetch store/}; delete @{$got}{qw/fetch store/};
49 @ret = eval { $test->() };
50 } elsif (defined $want) {
51 $ret[0] = eval { $test->() };
55 is_deeply $got, $exp, $desc;
57 return $want ? @ret : $ret[0];
61 my Ref $x; my $lx = __LINE__;
63 my $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch';
64 is $y, $lx, 'fetch correctly';
66 check { $x->{wat} = __LINE__ } $x, { store => 1 }, 'store'; my $l0 = __LINE__;
67 is $x->{wat}, $l0, 'store correctly';
69 my Ref $z = $x; my $lz = __LINE__;
71 $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch after being assigned';
72 is $y, $lx, 'fetch after being assigned correctly';
74 $y = check { $z->{_ref} } $z, { fetch => 1 }, 'fetch after being assigned to';
75 is $y, $lx, 'fetch after being assigned to correctly';
77 check { $z->{wat} = $x->{wat} + __LINE__ - $l0 } $z, { fetch => 1, store => 1 }, 'fetch/store';
78 is $z->{wat}, __LINE__-1, 'fetch/store correctly';
79 is $x->{wat}, __LINE__-2, 'fetch/store correctly';