]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blobdiff - t/80-leaks.t
Stop leaking objects stored in the data slot
[perl/modules/Variable-Magic.git] / t / 80-leaks.t
diff --git a/t/80-leaks.t b/t/80-leaks.t
new file mode 100644 (file)
index 0000000..dcaf66a
--- /dev/null
@@ -0,0 +1,40 @@
+#!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;
+}