3 use Test::More tests => 33;
5 use Variable::Magic qw/wizard cast dispell/;
12 my ($cb, $tests) = @_;
13 for (local $i = 0; $i < $n; ++$i) {
14 my $res = eval { $cb->() };
19 eval { $w[0] = wizard get => sub { ++$c[0] }, set => sub { --$c[0] } };
20 ok(!$@, "wizard 0 creation error ($@)");
21 eval { $w[1] = wizard get => sub { ++$c[1] }, set => sub { --$c[1] } };
22 ok(!$@, "wizard 1 creation error ($@)");
23 eval { $w[2] = wizard get => sub { ++$c[2] }, set => sub { --$c[2] } };
24 ok(!$@, "wizard 2 creation error ($@)");
30 ok(defined $res, "wizard $i is defined");
31 ok(ref($w[$i]) eq 'SCALAR', "wizard $i is a scalar ref");
40 ok(!$err, "cast magic $i croaks ($err)");
41 ok($res, "cast magic $i invalid");
45 for (0 .. $n - 1) { ok($c[$_] == 1, "get magic $_"); }
48 for (0 .. $n - 1) { ok($c[$_] == 0, "set magic $_"); }
50 my $res = eval { dispell $a, $w[1] };
51 ok(!$@, "dispell magic 1 croaks ($@)");
52 ok($res, 'dispell magic 1 invalid');
55 for (0, 2) { ok($c[$_] == 1, "get magic $_ after dispelled 1"); }
58 for (0, 2) { ok($c[$_] == 0, "set magic $_ after dispelled 1"); }
60 $res = eval { dispell $a, $w[0] };
61 ok(!$@, "dispell magic 0 croaks ($@)");
62 ok($res, 'dispell magic 0 invalid');
65 ok($c[2] == 1, 'get magic 2 after dispelled 1 & 0');
68 ok($c[2] == 0, 'set magic 2 after dispelled 1 & 0');
70 $res = eval { dispell $a, $w[2] };
71 ok(!$@, "dispell magic 2 croaks ($@)");
72 ok($res, 'dispell magic 2 invalid');