Commit | Line | Data |
867a26a0 |
1 | use strict; |
c57b19c6 |
2 | use Test::More tests => 11; |
867a26a0 |
3 | use Test::Deep; |
4 | use t::common qw( new_fh ); |
5 | |
6 | use_ok( 'DBM::Deep' ); |
7 | |
c57b19c6 |
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 | |
c57b19c6 |
16 | $db->{a} = 1; |
17 | $db->{foo} = { a => 'b' }; |
18 | my $x = $db->{foo}; |
19 | my $y = $db->{foo}; |
867a26a0 |
20 | |
888453b9 |
21 | is( $x, $y, "The references are the same" ); |
22 | |
23 | delete $db->{foo}; |
24 | is( $x, undef ); |
25 | is( $y, undef ); |
c57b19c6 |
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 | |
41 | SKIP: { |
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 | } |