data = (w->cb_data) ? vmg_data_new(w->cb_data, sv, args, items) : NULL;
mg = sv_magicext(sv, data, PERL_MAGIC_ext, w->vtbl, (const char *) wiz, HEf_SVKEY);
+ SvREFCNT_dec(data);
mg->mg_private = SIG_WIZ;
#if MGf_COPY
if (w->cb_copy)
--- /dev/null
+#!perl -T
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+use Variable::Magic qw/wizard cast/;
+
+our $destroyed;
+
+{
+ package Variable::Magic::TestDestructor;
+
+ sub new { bless { }, shift }
+
+ sub DESTROY { ++$::destroyed }
+}
+
+sub D () { 'Variable::Magic::TestDestructor' }
+
+{
+ local $destroyed = 0;
+
+ my $w = wizard data => sub { $_[1] };
+
+ {
+ my $obj = D->new;
+
+ {
+ my $x = 1;
+ cast $x, $w, $obj;
+ is $destroyed, 0;
+ }
+
+ is $destroyed, 0;
+ }
+
+ is $destroyed, 1;
+}