6 use Scope::Upper qw/localize_delete/;
8 use Test::More tests => 5;
13 package Scope::Upper::Test::TiedArray;
15 sub TIEARRAY { bless [], $_[0] }
16 sub STORE { $_[0]->[$_[1]] = $_[2] }
17 sub FETCH { $_[0]->[$_[1]] }
18 sub CLEAR { @{$_[0]} = (); }
19 sub FETCHSIZE { scalar @{$_[0]} }
20 sub DELETE { ++$main::deleted; delete $_[0]->[$_[1]] }
26 tie @a, 'Scope::Upper::Test::TiedArray';
30 is $deleted, undef, 'localize_delete @tied_array, $existent => 0 [not deleted]';
32 localize_delete '@a', 4 => 0;
33 is $deleted, 1, 'localize_delete @tied_array, $existent => 0 [deleted]';
34 is_deeply \@a, [ 5 .. 7 ], 'localize_delete @tied_array, $existent => 0 [ok]';
36 is_deeply \@a, [ 5 .. 7, undef, 9 ], 'localize_elem @incomplete_tied_array, $nonexistent, 12 => 0 [end]';
37 is $deleted, 1, 'localize_delete @tied_array, $existent => 0 [not more deleted]';