6 use Variable::Temp 'temp';
8 use Test::More tests => 16;
11 package Variable::Temp::TestDestructor;
14 my ($class, $code) = @_;
15 bless { code => $code }, $class;
23 my $x_is_destroyed = 0;
24 my $x_temp1_is_destroyed = 0;
25 my $x_temp2_is_destroyed = 0;
28 my $x = Variable::Temp::TestDestructor->new(sub {
29 is $x_temp1_is_destroyed, 1;
30 is $x_temp2_is_destroyed, 1;
33 is $x_is_destroyed, 0;
35 temp $x = Variable::Temp::TestDestructor->new(sub {
36 is $x_is_destroyed, 0;
37 is $x_temp2_is_destroyed, 1;
38 ++$x_temp1_is_destroyed;
40 is $x_is_destroyed, 0;
41 is $x_temp1_is_destroyed, 0;
42 is $x_temp2_is_destroyed, 0;
44 temp $x = Variable::Temp::TestDestructor->new(sub {
45 is $x_is_destroyed, 0;
46 is $x_temp1_is_destroyed, 0;
47 ++$x_temp2_is_destroyed;
49 is $x_is_destroyed, 0;
50 is $x_temp1_is_destroyed, 0;
51 is $x_temp2_is_destroyed, 0;
54 is $x_is_destroyed, 1;
55 is $x_temp1_is_destroyed, 1;
56 is $x_temp2_is_destroyed, 1;