Have a 98% solution to making references work.
[dbsrgits/DBM-Deep.git] / t / 39_singletons.t
1 use strict;
2 use Test::More tests => 9;
3 use Test::Deep;
4 use t::common qw( new_fh );
5
6 use_ok( 'DBM::Deep' );
7
8 my ($fh, $filename) = new_fh();
9 my $db = DBM::Deep->new(
10     file => $filename,
11     locking => 1,
12     autoflush => 1,
13 );
14
15 $db->{a} = 1;
16 $db->{foo} = { a => 'b' };
17 my $x = $db->{foo};
18 my $y = $db->{foo};
19
20 is( $x, $y, "The references are the same" );
21
22 delete $db->{foo};
23 is( $x, undef );
24 is( $y, undef );
25 warn "$x\n";
26 is( $x + 0, 0 );
27 is( $y + 0, 0 );
28 is( $db->{foo}, undef );
29
30 # These shenanigans work to get another hashref
31 # into the same data location as $db->{foo} was.
32 $db->{foo} = {};
33 delete $db->{foo};
34 $db->{foo} = {};
35 $db->{bar} = {};
36
37 is( $x, undef );
38 is( $y, undef );