6 use Variable::Magic qw<wizard cast dispell getdata>;
8 use Test::More tests => 3 * 11;
12 my $destructor = wizard free => sub { ++$destroyed; return };
17 my $increment_aux = wizard(
18 data => sub { $_[1] },
21 my $target_data = &getdata($target, $increment);
22 local $target_data->{guard} = 1;
30 return +{ guard => 0 };
33 return if $_[1]->{guard};
35 cast $token, $increment_aux, $_[0];
58 my @y = ($x = -13, $x);
63 dispell $x, $increment;
77 my $locker_aux = wizard(
78 data => sub { $_[1] },
81 my $target_data = &getdata($target, $locker);
82 local $target_data->{guard} = 1;
83 $$target = $target_data->{value};
90 return +{ guard => 0, value => $_[1] };
93 return if $_[1]->{guard};
95 cast $token, $locker_aux, $_[0];
100 local $destroyed = 0;
105 cast $x, $destructor;
108 cast $x, $locker, 999;
118 my @y = ($x = -13, $x);
137 my $delayed_aux = wizard(
138 data => sub { $_[1] },
140 my ($target) = $_[1];
141 my $target_data = &getdata($target, $delayed);
142 local $target_data->{guard} = 1;
143 if (ref $target eq 'SCALAR') {
145 $$target = $target_data->{mangler}->($orig);
153 return +{ guard => 0, mangler => $_[1] };
156 return if $_[1]->{guard};
158 cast $token, $delayed_aux, $_[0];
163 local $destroyed = 0;
168 cast $x, $destructor;
171 cast $x, $delayed => sub { $_[0] * 2 };
181 my @y = ($x = -13, $x);
186 dispell $x, $delayed;