summaryrefslogtreecommitdiff
path: root/t/retain.t
blob: 9e74ac54b9e829cee397e5f4a492767c1d9cb76d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use strict;
use warnings;

use Test::More;
use Test::Refcount;
use Variable::Disposition qw(retain dispose);

my $copy;
{
	my $x = [];
	Scalar::Util::weaken($copy = $x);
	ok($x, 'have a variable');
	is_refcount($x, 1, 'refcount is now 1');
	Scalar::Util::weaken($copy = $x);
	is_refcount($x, 1, 'refcount is still 1');
	retain($x);
	is_refcount($x, 2, 'refcount is now 2');
}
is_refcount($copy, 1, 'refcount is still 1');
ok($copy, 'copy still exists');
dispose($copy);
is($copy, undef, 'copy went away');

done_testing;