5 use Test::More tests => 11;
7 use t::common qw( new_fh );
12 my ($fh, $filename) = new_fh();
13 my $db = DBM::Deep->new({
19 # Create structure in memory
24 array1 => [ "elem0", "elem1", "elem2" ],
26 subkey1 => "subvalue1",
27 subkey2 => "subvalue2",
28 subkey3 => bless( {}, 'Foo' ),
32 $db->import( $struct );
39 array1 => [ 'elem0', 'elem1', 'elem2', ],
41 subkey1 => "subvalue1",
42 subkey2 => "subvalue2",
43 subkey3 => useclass( bless {}, 'Foo' ),
49 $struct->{foo} = 'bar';
50 is( $struct->{foo}, 'bar', "\$struct has foo and it's 'bar'" );
51 ok( !exists $db->{foo}, "\$db doesn't have the 'foo' key, so \$struct is not tied" );
53 $struct->{hash1}->{foo} = 'bar';
54 is( $struct->{hash1}->{foo}, 'bar', "\$struct->{hash1} has foo and it's 'bar'" );
55 ok( !exists $db->{hash1}->{foo}, "\$db->{hash1} doesn't have the 'foo' key, so \$struct->{hash1} is not tied" );
59 my ($fh, $filename) = new_fh();
60 my $db = DBM::Deep->new({
62 type => DBM::Deep->TYPE_ARRAY,
69 { foo => [ 2 .. 4 ] },
72 $db->import( $struct );
79 useclass( bless( [], 'Bar' ) ),
80 { foo => [ 2 .. 4 ] },
86 is( $struct->[-1], 'bar', "\$struct has 'bar' at the end" );
87 ok( $db->[-1], "\$db doesn't have the 'bar' value at the end, so \$struct is not tied" );
90 # Failure case to verify that rollback occurs
92 my ($fh, $filename) = new_fh();
93 my $db = DBM::Deep->new({
107 $db->import( $struct );
109 like( $@, qr/Storage of references of type 'CODE' is not supported/, 'Error message correct' );
116 "Everything matches",
122 Need to add tests for:
123 - Failure case (have something tied or a glob or something like that)
124 - Where we already have $db->{hash1} to make sure that it's not overwritten