Commit | Line | Data |
ffed8b01 |
1 | use strict; |
0e3e3555 |
2 | use warnings FATAL => 'all'; |
3 | |
4 | use Test::More; |
ffed8b01 |
5 | use Test::Exception; |
fde3db1a |
6 | use t::common qw( new_fh ); |
ffed8b01 |
7 | |
8 | use_ok( 'DBM::Deep' ); |
9 | |
fde3db1a |
10 | my ($fh, $filename) = new_fh(); |
ffed8b01 |
11 | |
12 | { |
13 | my %hash; |
2a81bf9e |
14 | tie %hash, 'DBM::Deep', $filename; |
ffed8b01 |
15 | |
16 | $hash{key1} = 'value'; |
17 | is( $hash{key1}, 'value', 'Set and retrieved key1' ); |
f1879fdc |
18 | tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self ); |
ffed8b01 |
19 | } |
20 | |
21 | { |
22 | my %hash; |
2a81bf9e |
23 | tie %hash, 'DBM::Deep', $filename; |
ffed8b01 |
24 | |
25 | is( $hash{key1}, 'value', 'Set and retrieved key1' ); |
26 | |
27 | is( keys %hash, 1, "There's one key so far" ); |
28 | ok( exists $hash{key1}, "... and it's key1" ); |
f1879fdc |
29 | tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self ); |
ffed8b01 |
30 | } |
31 | |
2a8ac017 |
32 | { |
33 | throws_ok { |
34 | tie my @array, 'DBM::Deep', { |
35 | file => $filename, |
36 | type => DBM::Deep->TYPE_ARRAY, |
37 | }; |
f1879fdc |
38 | tied( @array )->_get_self->_engine->storage->close( tied( @array )->_get_self ); |
2a8ac017 |
39 | } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; |
40 | } |
ffed8b01 |
41 | |
2a81bf9e |
42 | { |
fde3db1a |
43 | my ($fh, $filename) = new_fh(); |
45f047f8 |
44 | my $db = DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY ); |
2a81bf9e |
45 | |
46 | throws_ok { |
47 | tie my %hash, 'DBM::Deep', { |
48 | file => $filename, |
49 | type => DBM::Deep->TYPE_HASH, |
50 | }; |
51 | } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type"; |
f1879fdc |
52 | $db->_get_self->_engine->storage->close( $db->_get_self ); |
2a81bf9e |
53 | } |
0e3e3555 |
54 | |
55 | done_testing; |