6 use Test::More tests => 2 * 12 + 11 + 1;
8 use Variable::Magic qw/cast dispell/;
11 use Variable::Magic::TestWatcher;
13 my $wiz = init_watcher
14 [ qw/get set len clear free copy dup local fetch store exists delete/ ],
20 watch { cast &hlagh, $wiz } { }, 'cast';
21 is $x, 0, 'code: cast didn\'t called code';
23 watch { hlagh() } { }, 'call without arguments';
24 is $x, 1, 'code: call without arguments succeeded';
26 watch { hlagh(1, 2, 3) } { }, 'call with arguments';
27 is $x, 2, 'code: call with arguments succeeded';
29 watch { undef *hlagh } { free => 1 }, 'undef symbol table entry';
30 is $x, 2, 'code: undef symbol table entry didn\'t call code';
33 watch { *hlagh = sub { ++$y } } { }, 'redefining sub';
35 watch { cast &hlagh, $wiz } { }, 're-cast';
36 is $y, 0, 'code: re-cast didn\'t called code';
38 my ($r) = watch { \&hlagh } { }, 'reference';
39 is $y, 0, 'code: reference didn\'t called code';
41 watch { $r->() } { }, 'call reference';
42 is $y, 1, 'code: call reference succeeded';
43 is $x, 2, 'code: call reference didn\'t called the previous code';
47 no warnings 'redefine';
49 } { }, 'redefining sub 2';
51 watch { hlagh() } { }, 'call without arguments 2';
52 is $z, 1, 'code: call without arguments 2 succeeded';
53 is $y, 1, 'code: call without arguments 2 didn\'t called the previous code';
55 watch { dispell &hlagh, $wiz } { }, 'dispell';
56 is $z, 1, 'code: dispell didn\'t called code';
58 $Variable::Magic::TestWatcher::mg_end = { free => 1 };