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 | |
fb451ba6 |
33 | TODO: { |
34 | local $TODO = "Adding items in transactions will be fixed soon"; |
35 | local $^W; |
867a26a0 |
36 | cmp_ok( $obj->{foo}, '==', 5 ); |
fb451ba6 |
37 | } |
867a26a0 |
38 | ok( !exists $obj->{bar}, "bar doesn't exist" ); |
fb451ba6 |
39 | TODO: { |
40 | local $TODO = "Adding items in transactions will be fixed soon"; |
867a26a0 |
41 | ok( !tied(%$obj), "And it's not tied" ); |
fb451ba6 |
42 | } |
867a26a0 |
43 | |
44 | ok( !exists $db->{foo}, "The transaction inside the DB works" ); |
45 | } |
46 | |
47 | __END__ |
48 | { |
49 | my $obj = bless { |
50 | foo => 5, |
51 | }, 'Foo'; |
52 | |
53 | cmp_ok( $obj->{foo}, '==', 5 ); |
54 | ok( !exists $obj->{bar} ); |
55 | |
56 | $db->begin_work; |
57 | |
58 | $db->{foo} = $obj; |
59 | $db->{foo}{bar} = 1; |
60 | |
61 | cmp_ok( $db->{foo}{bar}, '==', 1, "The value is visible within the transaction" ); |
62 | cmp_ok( $obj->{bar}, '==', 1, "The value is visible within the object" ); |
63 | |
64 | $db->commit; |
65 | |
66 | cmp_ok( $obj->{foo}, '==', 5 ); |
67 | ok( !exists $obj->{bar} ); |
68 | } |