]> git.vpit.fr Git - perl/modules/Variable-Temp.git/blob - t/12-destroy.t
This is 0.01
[perl/modules/Variable-Temp.git] / t / 12-destroy.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Variable::Temp 'temp';
7
8 use Test::More tests => 16;
9
10 {
11  package Variable::Temp::TestDestructor;
12
13  sub new {
14   my ($class, $code) = @_;
15   bless { code => $code }, $class;
16  }
17
18  sub DESTROY {
19   $_[0]->{code}->();
20  }
21 }
22
23 my $x_is_destroyed       = 0;
24 my $x_temp1_is_destroyed = 0;
25 my $x_temp2_is_destroyed = 0;
26
27 {
28  my $x = Variable::Temp::TestDestructor->new(sub {
29   is $x_temp1_is_destroyed, 1;
30   is $x_temp2_is_destroyed, 1;
31   ++$x_is_destroyed;
32  });
33  is $x_is_destroyed, 0;
34
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;
39  });
40  is $x_is_destroyed,       0;
41  is $x_temp1_is_destroyed, 0;
42  is $x_temp2_is_destroyed, 0;
43
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;
48  });
49  is $x_is_destroyed,       0;
50  is $x_temp1_is_destroyed, 0;
51  is $x_temp2_is_destroyed, 0;
52 }
53
54 is $x_is_destroyed,       1;
55 is $x_temp1_is_destroyed, 1;
56 is $x_temp2_is_destroyed, 1;