C<clear>
-This magic is invoked when a container variable is reset, i.e. when an array or a hash is emptied.
+This magic is invoked when the variable is reset, such as when an array is emptied.
Please note that this is different from undefining the variable, even though the magic is called when the clearing is a result of the undefine (e.g. for an array, but actually a bug prevent it to work before perl 5.9.5 - see the L<history|/PERL MAGIC HISTORY>).
=item *
use strict;
use warnings;
-use Test::More tests => (2 * 14 + 2) + 2 * (2 * 8 + 4) + 1;
+use Config qw/%Config/;
-use Variable::Magic qw/cast dispell/;
+use Test::More tests => (2 * 14 + 2) + 2 * (2 * 8 + 4) + 3 + 1;
+
+use Variable::Magic qw/wizard cast dispell MGf_COPY/;
use lib 't/lib';
use Variable::Magic::TestWatcher;
check { $h{b} = 4 } { }, 'hash element: set after delete';
+SKIP: {
+ my $SKIP;
+
+ unless (MGf_COPY) {
+ $SKIP = 'No copy magic for this perl';
+ } elsif ($Config{useithreads} and $] le 5.008003) {
+ $SKIP = 'Causes havoc during global destruction for old threaded perls';
+ } else {
+ eval "use Tie::Array";
+ $SKIP = 'Tie::Array required to test clear magic on tied array values' if $@;
+ }
+
+ skip $SKIP => 3 if $SKIP;
+ diag "Using Tie::Array $Tie::Array::VERSION" if defined $Tie::Array::VERSION;
+
+ tie my @a, 'Tie::StdArray';
+ $a[0] = $$;
+
+ eval {
+ cast @a, wizard copy => sub { cast $_[3], $wiz; () };
+ };
+ is $@, '', 'cast copy magic on tied array';
+
+ check { delete $a[0] } [ qw/get clear free/ ], 'delete from tied array';
+}