6 sub export { 'export' };
10 use Test::More tests => 54;
12 use_ok( 'DBM::Deep' );
16 my $db = DBM::Deep->new(
21 die "ERROR: " . $db->error();
29 $db->{blessed} = $obj;
35 $db->{blessed2} = $obj2;
37 $db->{unblessed} = {};
38 $db->{unblessed}{a} = 1;
39 $db->{unblessed}{b} = [];
40 $db->{unblessed}{b}[0] = 1;
41 $db->{unblessed}{b}[1] = 2;
42 $db->{unblessed}{b}[2] = 3;
46 my $db = DBM::Deep->new(
51 die "ERROR: " . $db->error();
54 my $obj = $db->{blessed};
55 isa_ok( $obj, 'Foo' );
56 can_ok( $obj, 'export', 'foo' );
57 ok( !$obj->can( 'STORE' ), "... but it cannot 'STORE'" );
60 is( $obj->{b}[0], 1 );
61 is( $obj->{b}[1], 2 );
62 is( $obj->{b}[2], 3 );
64 my $obj2 = $db->{blessed2};
65 isa_ok( $obj, 'Foo' );
66 can_ok( $obj, 'export', 'foo' );
67 ok( !$obj->can( 'STORE' ), "... but it cannot 'STORE'" );
69 is( $obj2->[0]{a}, 'foo' );
70 is( $obj2->[1], '2' );
72 is( $db->{unblessed}{a}, 1 );
73 is( $db->{unblessed}{b}[0], 1 );
74 is( $db->{unblessed}{b}[1], 2 );
75 is( $db->{unblessed}{b}[2], 3 );
78 is( $db->{blessed}{c}, 'new' );
82 my $db = DBM::Deep->new(
86 is( $db->{blessed}{c}, 'new' );
88 my $structure = $db->export();
90 my $obj = $structure->{blessed};
91 isa_ok( $obj, 'Foo' );
92 can_ok( $obj, 'export', 'foo' );
93 ok( !$obj->can( 'STORE' ), "... but it cannot 'STORE'" );
96 is( $obj->{b}[0], 1 );
97 is( $obj->{b}[1], 2 );
98 is( $obj->{b}[2], 3 );
100 my $obj2 = $structure->{blessed2};
101 isa_ok( $obj, 'Foo' );
102 can_ok( $obj, 'export', 'foo' );
103 ok( !$obj->can( 'STORE' ), "... but it cannot 'STORE'" );
105 is( $obj2->[0]{a}, 'foo' );
106 is( $obj2->[1], '2' );
108 is( $structure->{unblessed}{a}, 1 );
109 is( $structure->{unblessed}{b}[0], 1 );
110 is( $structure->{unblessed}{b}[1], 2 );
111 is( $structure->{unblessed}{b}[2], 3 );
115 my $db = DBM::Deep->new(
119 die "ERROR: " . $db->error();
122 my $obj = $db->{blessed};
123 isa_ok( $obj, 'DBM::Deep' );
124 can_ok( $obj, 'export', 'STORE' );
125 ok( !$obj->can( 'foo' ), "... but it cannot 'foo'" );
128 is( $obj->{b}[0], 1 );
129 is( $obj->{b}[1], 2 );
130 is( $obj->{b}[2], 3 );
132 my $obj2 = $db->{blessed2};
133 isa_ok( $obj2, 'DBM::Deep' );
134 can_ok( $obj2, 'export', 'STORE' );
135 ok( !$obj2->can( 'foo' ), "... but it cannot 'foo'" );
137 is( $obj2->[0]{a}, 'foo' );
138 is( $obj2->[1], '2' );
140 is( $db->{unblessed}{a}, 1 );
141 is( $db->{unblessed}{b}[0], 1 );
142 is( $db->{unblessed}{b}[1], 2 );
143 is( $db->{unblessed}{b}[2], 3 );
148 my $db = DBM::Deep->new(
149 file => "t/test2.db",
153 die "ERROR: " . $db->error();
160 $db->import( { blessed => $obj } );
164 $db = DBM::Deep->new(
165 file => "t/test2.db",
169 die "ERROR: " . $db->error();
172 my $blessed = $db->{blessed};
173 isa_ok( $blessed, 'Foo' );
174 is( $blessed->{a}, 1 );
179 # test blessing hash into short named class (Foo), then re-blessing into
180 # longer named class (FooFoo) and replacing key in db file, then validating
181 # content after that point in file to check for corruption.
184 my $db = DBM::Deep->new(
185 file => "t/test3.db",
189 die "ERROR: " . $db->error();
192 my $obj = bless {}, 'Foo';
194 $db->{blessed} = $obj;
195 $db->{after} = "hello";
197 my $obj2 = bless {}, 'FooFoo';
199 $db->{blessed} = $obj2;
201 is( $db->{after}, "hello" );