12 load_or_skip_all('Variable::Magic', '0.35', [ ]);
13 plan skip_all => 'perl 5.10 required to test uvar magic'
14 unless Variable::Magic::VMG_UVAR();
18 package Lexical::Types::Test::Ref;
20 use Variable::Magic qw<wizard cast>;
24 $wiz = wizard data => sub { +{ } },
25 fetch => sub { ++$_[1]->{fetch}; () },
26 store => sub { ++$_[1]->{store}; () };
30 my %h = ("_\L$_[2]" => (caller(0))[2]);
43 use Lexical::Types as => 'Lexical::Types::Test';
46 my $got = Variable::Magic::getdata(%{$_[1]}, $Lexical::Types::Test::Ref::wiz);
47 my ($test, $exp, $desc) = @_[0, 2, 3];
51 local @{$got}{qw<fetch store>};
52 delete @{$got}{qw<fetch store>};
54 @ret = eval { $test->() };
55 } elsif (defined $want) {
56 $ret[0] = eval { $test->() };
60 local $Test::Builder::Level = $Test::Builder::Level + 1;
61 is_deeply $got, $exp, $desc;
63 return $want ? @ret : $ret[0];
67 my Ref $x; my $lx = __LINE__;
69 my $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch';
70 is $y, $lx, 'fetch correctly';
72 check { $x->{wat} = __LINE__ } $x, { store => 1 }, 'store'; my $l0 = __LINE__;
73 is $x->{wat}, $l0, 'store correctly';
75 my Ref $z = $x; my $lz = __LINE__;
77 $y = check { $x->{_ref} } $x, { fetch => 1 }, 'fetch after being assigned';
78 is $y, $lx, 'fetch after being assigned correctly';
80 $y = check { $z->{_ref} } $z, { fetch => 1 }, 'fetch after being assigned to';
81 is $y, $lx, 'fetch after being assigned to correctly';
83 check { $z->{wat} = $x->{wat} + __LINE__ - $l0 } $z, { fetch => 1, store => 1 }, 'fetch/store';
84 is $z->{wat}, __LINE__-1, 'fetch/store correctly';
85 is $x->{wat}, __LINE__-2, 'fetch/store correctly';