5 use Test::More tests => 11;
7 use File::Temp qw( tempfile tempdir );
11 my $dir = tempdir( CLEANUP => 1 );
14 # testing the various modes of opening a file
17 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
19 my $db = tie %hash, 'DBM::Deep', $filename;
21 ok(1, "Tied an hash with an array for params" );
25 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
27 my $db = tie %hash, 'DBM::Deep', {
31 ok(1, "Tied a hash with a hashref for params" );
35 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
37 my $db = tie @array, 'DBM::Deep', $filename;
39 ok(1, "Tied an array with an array for params" );
41 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
45 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
47 my $db = tie @array, 'DBM::Deep', {
51 ok(1, "Tied an array with a hashref for params" );
53 is( $db->{type}, DBM::Deep->TYPE_ARRAY, "TIE_ARRAY sets the correct type" );
56 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
58 tie my %hash, 'DBM::Deep', [ file => $filename ];
59 } qr/Not a hashref/, "Passing an arrayref to TIEHASH fails";
63 tie my @array, 'DBM::Deep', [ file => $filename ];
64 } qr/Not a hashref/, "Passing an arrayref to TIEARRAY fails";
68 tie my %hash, 'DBM::Deep', undef, file => $filename;
69 } qr/Odd number of parameters/, "Odd number of params to TIEHASH fails";
73 tie my @array, 'DBM::Deep', undef, file => $filename;
74 } qr/Odd number of parameters/, "Odd number of params to TIEARRAY fails";