9 plan skip_all => 'Variable::Magic 0.35 on 5.10 required to test uvar magic'
10 unless eval "use Variable::Magic 0.35; 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 local $Test::Builder::Level = $Test::Builder::Level + 1;
57 is_deeply $got, $exp, $desc;
59 return $want ? @ret : $ret[0];
63 my Ref $x; my $lx = __LINE__;
65 my $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch';
66 is $y, $lx, 'fetch correctly';
68 check { $x->{wat} = __LINE__ } $x, { store => 1 }, 'store'; my $l0 = __LINE__;
69 is $x->{wat}, $l0, 'store correctly';
71 my Ref $z = $x; my $lz = __LINE__;
73 $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch after being assigned';
74 is $y, $lx, 'fetch after being assigned correctly';
76 $y = check { $z->{_ref} } $z, { fetch => 1 }, 'fetch after being assigned to';
77 is $y, $lx, 'fetch after being assigned to correctly';
79 check { $z->{wat} = $x->{wat} + __LINE__ - $l0 } $z, { fetch => 1, store => 1 }, 'fetch/store';
80 is $z->{wat}, __LINE__-1, 'fetch/store correctly';
81 is $x->{wat}, __LINE__-2, 'fetch/store correctly';