- New caveat in the docs explaining stale references (RT#42129)
- All included modules now have the same version in META.yml, so
the CPAN shell will no longer try to downgrade.
+ - Fixed bug in clear() for hashes (RT#50541)
1.0015 Jan 25 22:05:00 2010 PST
- (This version is compatible with 1.0014)
$self->lock_exclusive;
- #XXX Rewrite this dreck to do it in the engine as a tight loop vs.
- # iterating over keys - such a WASTE - is this required for transactional
- # clearning?! Surely that can be detected in the engine ...
- if ( $self->_type eq TYPE_HASH ) {
- my $key = $self->first_key;
- while ( $key ) {
- # Retrieve the key before deleting because we depend on next_key
- my $next_key = $self->next_key( $key );
- $self->_engine->delete_key( $self, $key, $key );
- $key = $next_key;
- }
- }
- else {
- my $size = $self->FETCHSIZE;
- for my $key ( 0 .. $size - 1 ) {
- $self->_engine->delete_key( $self, $key, $key );
- }
- $self->STORESIZE( 0 );
- }
+ # Dispatch to the specific clearing functionality.
+ $self->_clear;
$self->unlock;
return 1;
}
+sub _clear {
+ my $self = shift;
+
+ my $size = $self->FETCHSIZE;
+ for my $key ( 0 .. $size - 1 ) {
+ $self->_engine->delete_key( $self, $key, $key );
+ }
+ $self->STORESIZE( 0 );
+
+ return;
+}
+
##
# Public method aliases
##
$sector->find_md5( $args->{key_md5} );
# See whether or not we need to reindex the bucketlist
- # Yes, the double-braces are there for a reason. if() doesn't create a redo-able block,
- # so we have to create a bare block within the if() for redo-purposes. Patch and idea
- # submitted by sprout@cpan.org. -RobK, 2008-01-09
+ # Yes, the double-braces are there for a reason. if() doesn't create a
+ # redo-able block, so we have to create a bare block within the if() for
+ # redo-purposes.
+ # Patch and idea submitted by sprout@cpan.org. -RobK, 2008-01-09
if ( !$sector->has_md5 && $args->{create} && $sector->{idx} == -1 ) {{
my $redo;
sub first_key { (shift)->FIRSTKEY(@_) }
sub next_key { (shift)->NEXTKEY(@_) }
+sub _clear {
+ my $self = shift;
+
+ while ( my $key = $self->first_key ) {
+ $self->_engine->delete_key( $self, $key, $key );
+ }
+
+ return;
+}
+
sub _copy_node {
my $self = shift;
my ($db_temp) = @_;
# DBM::Deep Test
##
use strict;
-use Test::More tests => 51;
+use Test::More tests => 53;
use Test::Exception;
use t::common qw( new_fh );
$db->exists(undef);
} qr/Cannot use an undefined hash key/, "EXISTS fails on an undefined key";
+{
+ # RT# 50541 (reported by Peter Scott)
+ # clear() leaves one key unless there's only one
+ my ($fh, $filename) = new_fh();
+ my $db = DBM::Deep->new(
+ file => $filename,
+ fh => $fh,
+ );
+
+ $db->{block} = { };
+ $db->{critical} = { };
+ $db->{minor} = { };
+
+ cmp_ok( scalar(keys( %$db )), '==', 3, "Have 3 keys" );
+
+ $db->clear;
+
+ cmp_ok( scalar(keys( %$db )), '==', 0, "clear clears everything" );
+}