);
if ( $bytes_read ) {
- my ($signature, $version, @values) = unpack( 'A4 N S A S A S', $buffer );
+ my ($signature, $version, @values) = unpack( 'A4 S S A S A S', $buffer );
unless ($signature eq SIG_FILE) {
$self->close_fh( $obj );
$obj->_throw_error("Signature not found -- file is not a Deep DB");
}
- if ( if @values < 5 || grep { !defined } @values ) {
+ if ( @values < 5 || grep { !defined } @values ) {
die "DBM::Deep: Corrupted file - bad header\n";
}
+
+ #XXX Add warnings if values weren't set right
@{$self}{qw( long_size long_pack data_size data_pack max_buckets )} = @values;
}
# DBM::Deep Test
##
use strict;
-use Test::More tests => 2;
+use Test::More tests => 4;
use t::common qw( new_fh );
use_ok( 'DBM::Deep' );
{
my ($fh, $filename) = new_fh();
- my $db = DBM::Deep->new(
- file => $filename,
- autoflush => 1,
- pack_size => 'small',
- );
+ {
+ my $db = DBM::Deep->new(
+ file => $filename,
+ autoflush => 1,
+ pack_size => 'small',
+ );
- $db->{key1} = "value1";
- $db->{key2} = "value2";
- $after = (stat($db->_fh()))[7];
+ $db->{key1} = "value1";
+ $db->{key2} = "value2";
+ $after = (stat($db->_fh()))[7];
+ }
+
+ # This tests the header to verify that the pack_size is really there
+ {
+ my $db = DBM::Deep->new(
+ file => $filename,
+ );
+
+ is( $db->{key1}, 'value1', 'Can read key1' );
+ is( $db->{key2}, 'value2', 'Can read key2' );
+ }
}
-ok( $after < $before, "The new packsize reduced the size of the file" );
+cmp_ok( $after, '<', $before, "The new packsize reduced the size of the file" );