6 use Test::More tests => 17;
8 use Variable::Magic qw/wizard cast dispell getdata/;
14 wizard data => sub { $_[0] },
18 is($@, '', 'wizard creation error doesn\'t croak');
19 ok(defined $wiz, 'wizard is defined');
20 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
22 my $res = eval { cast $wiz, $wiz };
23 is($@, '', 'cast on self doesn\'t croak');
24 ok($res, 'cast on self is valid');
27 is($c, 1, 'magic works correctly on self');
29 $res = eval { dispell $wiz, $wiz };
30 is($@, '', 'dispell on self doesn\'t croak');
31 ok($res, 'dispell on self is valid');
34 is($c, 1, 'magic is no longer invoked on self when dispelled');
36 $res = eval { cast $wiz, $wiz, $wiz };
37 is($@, '', 're-cast on self doesn\'t croak');
38 ok($res, 're-cast on self is valid');
40 $w = getdata $wiz, $wiz;
41 is($c, 1, 'getdata on magical self doesn\'t trigger callbacks');
43 $res = eval { dispell $wiz, $wiz };
44 is($@, '', 're-dispell on self doesn\'t croak');
45 ok($res, 're-dispell on self is valid');
47 $res = eval { cast $wiz, $wiz };
48 is($@, '', 're-re-cast on self doesn\'t croak');
49 ok($res, 're-re-cast on self is valid');
54 BEGIN { require Variable::Magic::TestDestroyRequired; }
56 is $@, '', 'wizard destruction at the end of BEGIN-time require doesn\'t panic';
58 if ((defined $ENV{PERL_DESTRUCT_LEVEL} and $ENV{PERL_DESTRUCT_LEVEL} >= 3)
59 or eval "use Perl::Destruct::Level level => 3; 1") {
60 diag 'Test global destruction';