6 use Test::More tests => 7;
8 use Variable::Magic qw/wizard cast/;
13 $wiz = wizard data => sub { $_[1]->() };
15 cast $x, $wiz, sub { die "carrot" };
18 like $@, qr/carrot/, 'die in data callback';
21 $wiz = wizard data => sub { $_[1] },
22 set => sub { $_[1]->(); () };
24 cast $x, $wiz, sub { die "lettuce" };
28 like $@, qr/lettuce/, 'die in set callback';
31 $wiz = wizard data => sub { $_[1] },
32 len => sub { $_[1]->(); () };
34 cast @a, $wiz, sub { die "potato" };
38 like $@, qr/potato/, 'die in len callback';
41 $wiz = wizard data => sub { $_[1] },
42 free => sub { $_[1]->(); () };
44 cast $x, $wiz, sub { die "spinach" };
47 like $@, qr/spinach/, 'die in free callback';
49 # Inspired by B::Hooks::EndOfScope
52 $wiz = wizard data => sub { $_[1]->() };
54 cast $x, $wiz, sub { die "pumpkin" };
57 like $@, qr/pumpkin/, 'die in data callback in BEGIN';
60 $wiz = wizard data => sub { $_[1] },
61 free => sub { $_[1]->(); () };
63 cast %^H, $wiz, sub { die "macaroni" };
66 like $@, qr/macaroni/, 'die in free callback in BEGIN';
69 $wiz = wizard data => sub { $_[1] },
70 len => sub { $_[1]->(); $_[2] },
71 free => sub { my $x = @{$_[0]}; () };
73 cast @a, $wiz, sub { die "pepperoni" };
76 like $@, qr/pepperoni/, 'die in len callback in BEGIN';