6 sub export { 'export' };
10 use Test::More tests => 29;
12 use_ok( 'DBM::Deep' );
15 my $db = DBM::Deep->new(
20 die "ERROR: " . $db->error();
28 $db->{blessed} = $obj;
30 $db->{unblessed} = {};
31 $db->{unblessed}{a} = 1;
32 $db->{unblessed}{b} = [];
33 $db->{unblessed}{b}[0] = 1;
34 $db->{unblessed}{b}[1] = 2;
35 $db->{unblessed}{b}[2] = 3;
39 my $db2 = DBM::Deep->new(
44 die "ERROR: " . $db2->error();
47 my $obj2 = $db2->{blessed};
48 isa_ok( $obj2, 'Foo' );
49 can_ok( $obj2, 'export', 'foo' );
50 ok( !$obj2->can( 'STORE' ), "... but it cannot 'STORE'" );
53 is( $obj2->{b}[0], 1 );
54 is( $obj2->{b}[1], 2 );
55 is( $obj2->{b}[2], 3 );
57 is( $db2->{unblessed}{a}, 1 );
58 is( $db2->{unblessed}{b}[0], 1 );
59 is( $db2->{unblessed}{b}[1], 2 );
60 is( $db2->{unblessed}{b}[2], 3 );
63 is( $db2->{blessed}{c}, 'new' );
67 $db2 = DBM::Deep->new(
71 is( $db2->{blessed}{c}, 'new' );
74 todo_skip "_copy_node() doesn't work with autobless", 1;
75 my $structure = $db2->export();
79 my $db3 = DBM::Deep->new(
83 die "ERROR: " . $db3->error();
86 my $obj3 = $db3->{blessed};
87 isa_ok( $obj3, 'DBM::Deep' );
88 can_ok( $obj3, 'export', 'STORE' );
89 ok( !$obj3->can( 'foo' ), "... but it cannot 'foo'" );
92 is( $obj3->{b}[0], 1 );
93 is( $obj3->{b}[1], 2 );
94 is( $obj3->{b}[2], 3 );
96 is( $db3->{unblessed}{a}, 1 );
97 is( $db3->{unblessed}{b}[0], 1 );
98 is( $db3->{unblessed}{b}[1], 2 );
99 is( $db3->{unblessed}{b}[2], 3 );
107 my $db = DBM::Deep->new(
112 die "ERROR: " . $db->error();
120 $db->import( { blessed => $obj } );
124 $db = DBM::Deep->new(
129 die "ERROR: " . $db->error();
132 my $blessed = $db->{blessed};
133 isa_ok( $blessed, 'Foo' );
134 is( $blessed->{a}, 1 );
139 # test blessing hash into short named class (Foo), then re-blessing into
140 # longer named class (FooFoo) and replacing key in db file, then validating
141 # content after that point in file to check for corruption.
144 my $db = DBM::Deep->new(
149 die "ERROR: " . $db->error();
152 my $obj = bless {}, 'Foo';
154 $db->{blessed} = $obj;
155 $db->{after} = "hello";
157 my $obj2 = bless {}, 'FooFoo';
159 $db->{blessed} = $obj2;
161 is( $db->{after}, "hello" );