Commit | Line | Data |
867a26a0 |
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 | { |
16 | my $obj = bless { |
17 | foo => 5, |
18 | }, 'Foo'; |
19 | |
20 | cmp_ok( $obj->{foo}, '==', 5 ); |
21 | ok( !exists $obj->{bar} ); |
22 | |
23 | $db->begin_work; |
24 | |
25 | $db->{foo} = $obj; |
26 | $db->{foo}{bar} = 1; |
27 | |
28 | cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" ); |
29 | cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" ); |
30 | |
31 | $db->rollback; |
32 | |
33 | cmp_ok( $obj->{foo}, '==', 5 ); |
34 | ok( !exists $obj->{bar}, "bar doesn't exist" ); |
35 | ok( !tied(%$obj), "And it's not tied" ); |
36 | |
37 | ok( !exists $db->{foo}, "The transaction inside the DB works" ); |
38 | } |
39 | |
40 | __END__ |
41 | { |
42 | my $obj = bless { |
43 | foo => 5, |
44 | }, 'Foo'; |
45 | |
46 | cmp_ok( $obj->{foo}, '==', 5 ); |
47 | ok( !exists $obj->{bar} ); |
48 | |
49 | $db->begin_work; |
50 | |
51 | $db->{foo} = $obj; |
52 | $db->{foo}{bar} = 1; |
53 | |
54 | cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" ); |
55 | cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" ); |
56 | |
57 | $db->commit; |
58 | |
59 | cmp_ok( $obj->{foo}, '==', 5 ); |
60 | ok( !exists $obj->{bar} ); |
61 | } |