6 use Test::More tests => 12;
8 use Variable::Magic qw/wizard cast/;
10 my $wiz = eval { wizard get => sub { undef } };
11 is($@, '', 'wizard creation doesn\'t croak');
12 ok(defined $wiz, 'wizard is defined');
13 is(ref $wiz, 'SCALAR', 'wizard is a scalar ref');
15 my $n = int rand 1000;
18 my $res = eval { cast $a, $wiz };
19 is($@, '', 'cast doesn\'t croak');
20 ok($res, 'cast is valid');
24 local $SIG{__WARN__} = sub { die };
27 is($@, '', 'callback returning undef doesn\'t warn/croak');
28 is($x, $n, 'callback returning undef fails');
31 $wiz = wizard get => sub {
34 while (@c = caller $i++) {
35 push @callers, [ @c[0, 1, 2] ];
43 is_deeply(\@callers, [
44 [ 'main', $0, __LINE__-2 ],
45 ], 'caller into callback returns the right thing');
49 is_deeply(\@callers, [
50 [ 'main', $0, __LINE__-2 ],
51 ], 'caller into callback returns the right thing (second time)');
56 is_deeply(\@callers, [
57 [ 'main', $0, __LINE__-2 ],
58 ], 'caller into callback into block returns the right thing');
63 is($@, '', 'caller into callback doesn\'t croak');
64 is_deeply(\@callers, [
65 ([ 'main', $0, __LINE__-3 ]) x 2,
66 ], 'caller into callback into eval returns the right thing');