Commit | Line | Data |
76a2eb58 |
1 | use strict; |
2 | $|++; |
3 | |
4 | { |
5 | package Foo; |
6 | |
7 | sub export { 'export' }; |
8 | sub foo { 'foo' }; |
9 | } |
10 | |
11 | use Test::More no_plan => 1; |
12 | |
13 | use_ok( 'DBM::Deep' ); |
14 | |
15 | unlink 't/test.db'; |
16 | my $db = DBM::Deep->new( |
17 | file => "t/test.db", |
18 | autobless => 0, |
19 | ); |
20 | if ($db->error()) { |
21 | die "ERROR: " . $db->error(); |
22 | } |
23 | |
24 | $db->{unblessed} = {}; |
25 | $db->{unblessed}{a} = 1; |
26 | $db->{unblessed}{b} = []; |
27 | $db->{unblessed}{b}[0] = 1; |
28 | $db->{unblessed}{b}[1] = 2; |
29 | $db->{unblessed}{b}[2] = 3; |
30 | |
31 | undef $db; |
32 | |
33 | my $db2 = DBM::Deep->new( |
34 | file => 't/test.db', |
35 | autobless => 1, |
36 | ); |
37 | if ($db2->error()) { |
38 | die "ERROR: " . $db2->error(); |
39 | } |
40 | |
41 | is( $db2->{unblessed}{a}, 1 ); |
42 | is( $db2->{unblessed}{b}[0], 1 ); |
43 | is( $db2->{unblessed}{b}[1], 2 ); |
44 | is( $db2->{unblessed}{b}[2], 3 ); |
45 | |
46 | $db2->{unblessed}{a} = 2; |
47 | |
48 | is( $db2->{unblessed}{a}, 2 ); |
49 | is( $db2->{unblessed}{b}[0], 1 ); |
50 | is( $db2->{unblessed}{b}[1], 2 ); |
51 | is( $db2->{unblessed}{b}[2], 3 ); |
52 | |
53 | undef $db2; |
54 | |
55 | my $db3 = DBM::Deep->new( |
56 | file => "t/test.db", |
57 | autobless => 0, |
58 | ); |
59 | if ($db3->error()) { |
60 | die "ERROR: " . $db->error(); |
61 | } |
62 | |
63 | is( $db3->{unblessed}{a}, 2 ); |
64 | is( $db3->{unblessed}{b}[0], 1 ); |
65 | __END__ |
66 | is( $db3->{unblessed}{b}[1], 2 ); |
67 | is( $db3->{unblessed}{b}[2], 3 ); |