8 use Variable::Magic qw<wizard cast getdata MGf_LOCAL>;
11 plan tests => 2 * 3 + 1 + (2 + 2 * 7) + 1;
13 plan skip_all => 'No local magic for this perl';
17 use Variable::Magic::TestWatcher;
19 my $wiz = init_watcher 'local', 'local';
21 our $a = int rand 1000;
23 my $res = watch { cast $a, $wiz } { }, 'cast';
24 ok $res, 'local: cast succeeded';
26 watch { local $a } { local => 1 }, 'localized';
31 my $w1 = eval { wizard local => \undef, data => sub { 'w1' } };
32 is $@, '', 'local: noop wizard creation does not croak';
33 my $w2 = eval { wizard data => sub { 'w2' } };
34 is $@, '', 'local: dummy wizard creation does not croak';
38 eval { cast $u, $w1 };
39 is $@, '', 'local: noop magic (first) cast does not croak';
40 is getdata($u, $w1), 'w1', 'local: noop magic (first) cast succeeded';
41 eval { cast $u, $w2 };
42 is $@, '', 'local: dummy magic (second) cast does not croak';
43 is getdata($u, $w2), 'w2', 'local: dummy magic (second) cast succeeded';
47 $z1 = getdata $u, $w1;
48 $z2 = getdata $u, $w2;
50 is $@, '', 'local: noop/dummy magic invocation does not croak';
51 is $z1, undef, 'local: noop magic (first) prevented magic copy';
52 is $z2, 'w2', 'local: dummy magic (second) was copied';
57 eval { cast $v, $w2 };
58 is $@, '', 'local: dummy magic (first) cast does not croak';
59 is getdata($v, $w2), 'w2', 'local: dummy magic (first) cast succeeded';
60 eval { cast $v, $w1 };
61 is $@, '', 'local: noop magic (second) cast does not croak';
62 is getdata($v, $w1), 'w1', 'local: noop magic (second) cast succeeded';
66 $z1 = getdata $v, $w1;
67 $z2 = getdata $v, $w2;
69 is $@, '', 'local: dummy/noop magic invocation does not croak';
70 is $z2, 'w2', 'local: dummy magic (first) was copied';
71 is $z1, undef, 'local: noop magic (second) prevented magic copy';