]> git.vpit.fr Git - perl/modules/Variable-Magic.git/blob - t/80-leaks.t
Stop leaking objects stored in the data slot
[perl/modules/Variable-Magic.git] / t / 80-leaks.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 3;
7
8 use Variable::Magic qw/wizard cast/;
9
10 our $destroyed;
11
12 {
13  package Variable::Magic::TestDestructor;
14
15  sub new { bless { }, shift }
16
17  sub DESTROY { ++$::destroyed }
18 }
19
20 sub D () { 'Variable::Magic::TestDestructor' }
21
22 {
23  local $destroyed = 0;
24
25  my $w = wizard data => sub { $_[1] };
26
27  {
28   my $obj = D->new;
29
30   {
31    my $x = 1;
32    cast $x, $w, $obj;
33    is $destroyed, 0;
34   }
35
36   is $destroyed, 0;
37  }
38
39  is $destroyed, 1;
40 }