r6209@rob-kinyons-computer-2 (orig r9991): rkinyon | 2007-09-24 21:18:27 -0400
[dbsrgits/DBM-Deep.git] / t / 39_singletons.t
CommitLineData
867a26a0 1use strict;
4c76b4dd 2use Test::More tests => 11;
867a26a0 3use Test::Deep;
4use t::common qw( new_fh );
5
6use_ok( 'DBM::Deep' );
7
4c76b4dd 8{
9 my ($fh, $filename) = new_fh();
10 my $db = DBM::Deep->new(
11 file => $filename,
12 locking => 1,
13 autoflush => 1,
14 );
867a26a0 15
4c76b4dd 16 $db->{a} = 1;
17 $db->{foo} = { a => 'b' };
18 my $x = $db->{foo};
19 my $y = $db->{foo};
867a26a0 20
4c76b4dd 21 is( $x, $y, "The references are the same" );
867a26a0 22
4c76b4dd 23 delete $db->{foo};
24 is( $x, undef );
25 is( $y, undef );
26 is( $x + 0, undef );
27 is( $y + 0, undef );
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 );
39}
40
41SKIP: {
42 skip "What do we do with external references and txns?", 2;
43 my ($fh, $filename) = new_fh();
44 my $db = DBM::Deep->new(
45 file => $filename,
46 locking => 1,
47 autoflush => 1,
48 num_txns => 2,
49 );
50
51 $db->{foo} = { a => 'b' };
52 my $x = $db->{foo};
53
54 $db->begin_work;
55
56 $db->{foo} = { c => 'd' };
57 my $y = $db->{foo};
58
59 # XXX What should happen here with $x and $y?
60 is( $x, $y );
61 is( $x->{c}, 'd' );
62
63 $db->rollback;
fb451ba6 64}