File: 21_tie_access.t

package info (click to toggle)
libdbm-deep-perl 2.0008-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 884 kB
  • sloc: perl: 7,383; sql: 36
file content (55 lines) | stat: -rw-r--r-- 1,427 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use strict;
use warnings FATAL => 'all';

use Test::More;
use Test::Exception;
use t::common qw( new_fh );

use_ok( 'DBM::Deep' );

my ($fh, $filename) = new_fh();

{
    my %hash;
    tie %hash, 'DBM::Deep', $filename;

    $hash{key1} = 'value';
    is( $hash{key1}, 'value', 'Set and retrieved key1' );
    tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
}

{
    my %hash;
    tie %hash, 'DBM::Deep', $filename;

    is( $hash{key1}, 'value', 'Set and retrieved key1' );

    is( keys %hash, 1, "There's one key so far" );
    ok( exists $hash{key1}, "... and it's key1" );
    tied( %hash )->_get_self->_engine->storage->close( tied( %hash )->_get_self );
}

{
    throws_ok {
        tie my @array, 'DBM::Deep', {
            file => $filename,
            type => DBM::Deep->TYPE_ARRAY,
        };
        tied( @array )->_get_self->_engine->storage->close( tied( @array )->_get_self );
    } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
}

{
    my ($fh, $filename) = new_fh();
    my $db = DBM::Deep->new( file => $filename, type => DBM::Deep->TYPE_ARRAY );

    throws_ok {
        tie my %hash, 'DBM::Deep', {
            file => $filename,
            type => DBM::Deep->TYPE_HASH,
        };
    } qr/DBM::Deep: File type mismatch/, "\$SIG_TYPE doesn't match file's type";
    $db->_get_self->_engine->storage->close( $db->_get_self );
}

done_testing;