Fixed the hypothetical TIESCALAR
[dbsrgits/DBM-Deep.git] / lib / DBM / Deep / Hash.pm
index e315a5d..4dc0b22 100644 (file)
@@ -5,7 +5,7 @@ use strict;
 use base 'DBM::Deep';
 
 sub _get_self {
-    eval { tied( %{$_[0]} ) } || $_[0]
+    eval { local $SIG{'__DIE__'}; tied( %{$_[0]} ) } || $_[0]
 }
 
 sub TIEHASH {
@@ -13,22 +13,22 @@ sub TIEHASH {
     # Tied hash constructor method, called by Perl's tie() function.
     ##
     my $class = shift;
-    my $args;
-    if (scalar(@_) > 1) {
-        if ( @_ % 2 ) {
-            $class->_throw_error( "Odd number of parameters to TIEHASH" );
-        }
-        $args = {@_};
-    }
-    #XXX This use of ref() is bad and is a bug
-    elsif (ref($_[0])) { $args = $_[0]; }
-    else { $args = { file => shift }; }
+    my $args = $class->_get_args( @_ );
     
     $args->{type} = $class->TYPE_HASH;
 
     return $class->_init($args);
 }
 
+sub FETCH {
+    my $self = shift->_get_self;
+    my $key = ($self->root->{filter_store_key})
+        ? $self->root->{filter_store_key}->($_[0])
+        : $_[0];
+
+    return $self->SUPER::FETCH( $key );
+}
+
 sub STORE {
     my $self = shift->_get_self;
        my $key = ($self->root->{filter_store_key})
@@ -39,6 +39,24 @@ sub STORE {
     return $self->SUPER::STORE( $key, $value );
 }
 
+sub EXISTS {
+    my $self = shift->_get_self;
+       my $key = ($self->root->{filter_store_key})
+        ? $self->root->{filter_store_key}->($_[0])
+        : $_[0];
+
+    return $self->SUPER::EXISTS( $key );
+}
+
+sub DELETE {
+    my $self = shift->_get_self;
+       my $key = ($self->root->{filter_store_key})
+        ? $self->root->{filter_store_key}->($_[0])
+        : $_[0];
+
+    return $self->SUPER::DELETE( $key );
+}
+
 sub FIRSTKEY {
        ##
        # Locate and return first key (in no particular order)