Commit | Line | Data |
ffed8b01 |
1 | ## |
2 | # DBM::Deep Test |
3 | ## |
4 | use strict; |
5 | use Test::More tests => 5; |
98ac82af |
6 | use File::Temp qw( tempfile tempdir ); |
58910373 |
7 | use Fcntl qw( :flock ); |
ffed8b01 |
8 | |
9 | use_ok( 'DBM::Deep' ); |
10 | |
98ac82af |
11 | my $dir = tempdir( CLEANUP => 1 ); |
12 | my ($fh2, $filename2) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
58910373 |
13 | flock $fh2, LOCK_UN; |
98ac82af |
14 | my $db2 = DBM::Deep->new( $filename2 ); |
15 | |
16 | { |
17 | my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir ); |
58910373 |
18 | flock $fh, LOCK_UN; |
98ac82af |
19 | my $db = DBM::Deep->new( $filename ); |
20 | |
21 | ## |
22 | # Create structure in $db |
23 | ## |
24 | $db->import( |
25 | hash1 => { |
26 | subkey1 => "subvalue1", |
c9cec40e |
27 | subkey2 => "subvalue2", |
98ac82af |
28 | } |
29 | ); |
98ac82af |
30 | is( $db->{hash1}{subkey1}, 'subvalue1', "Value imported correctly" ); |
31 | is( $db->{hash1}{subkey2}, 'subvalue2', "Value imported correctly" ); |
32 | |
33 | ## |
34 | # Cross-ref nested hash accross DB objects |
35 | ## |
36 | $db2->{copy} = $db->{hash1}; |
37 | } |
ffed8b01 |
38 | |
39 | ## |
40 | # Make sure $db2 has copy of $db's hash structure |
41 | ## |
42 | is( $db2->{copy}{subkey1}, 'subvalue1', "Value copied correctly" ); |
43 | is( $db2->{copy}{subkey2}, 'subvalue2', "Value copied correctly" ); |