1#!perl -T 2 3use strict; 4use warnings; 5 6use Test::More tests => (2 * 5 + 2) + (2 * 2 + 1) + 1; 7 8use Variable::Magic qw/cast dispell/; 9 10use lib 't/lib'; 11use Variable::Magic::TestWatcher; 12use Variable::Magic::TestValue; 13 14my $wiz = init_watcher 'clear', 'clear'; 15 16my @a = qw/a b c/; 17 18watch { cast @a, $wiz } { }, 'cast array'; 19 20watch { @a = () } { clear => 1 }, 'clear array'; 21is_deeply \@a, [ ], 'clear: clear array correctly'; 22 23my %h = (foo => 1, bar => 2); 24 25watch { cast %h, $wiz } { }, 'cast hash'; 26 27watch { %h = () } { clear => 1 }, 'clear hash'; 28is_deeply \%h, { }, 'clear: clear hash correctly'; 29 30{ 31 my @val = (4 .. 6); 32 33 my $wv = init_value @val, 'clear', 'clear'; 34 35 value { @val = () } [ 4 .. 6 ]; 36 37 dispell @val, $wv; 38 is_deeply \@val, [ ], 'clear: value after'; 39} 40