Fixed how classname is stored
[dbsrgits/DBM-Deep.git] / t / 21_tie_access.t
CommitLineData
ffed8b01 1use strict;
0e3e3555 2use warnings FATAL => 'all';
3
4use Test::More;
ffed8b01 5use Test::Exception;
fde3db1a 6use t::common qw( new_fh );
ffed8b01 7
8use_ok( 'DBM::Deep' );
9
fde3db1a 10my ($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
55done_testing;