
package Text::Wigwam::Stash::Base::Metachar::Hash;

use strict;
use warnings;
no warnings q/uninitialized/;

use base 'Text::Wigwam::Stash::Base::Metachar';

our $VERSION = '0.01';

sub get {
    my ($self, $mgc, $href, $key, undef, $level) = @_;
    $key =~ s/\\(.)/$1/g;
     # Only return $href if the key is null and we're on level 0
     # otherwise force a lookup.
    return (length $key || $level)
           ? ($href->{$key}, \$href->{$key})
           : ($href, \$href)
    ;
    return ( $href->{$key}, \$href->{$key} );
#    return exists $href->{$key} ? ( $href->{$key}, \$href->{$key} )
#    return( $href->{$key}, \($href->{$key}) );
}

sub set {
    my ($self, $mgc, $href, $key, $type, $def, $level) = @_;
    my $v;
    $key =~ s/\\(.)/$1/g;
    return ( $type, $href ) unless $level || length $key;
    return ( $type, $v )
      if defined($v = $href->{$key});
    return ( $type, $href->{$key} = $def );
}

sub def {
    my ($self, $mgc, $href, $key, $level) = @_;
    $key =~ s/\\(.)/$1/g;
    return $self->_ref_rref ( exists $href->{$key} ? $href->{$key} : undef )
      if $level || length $key;
    return $self->_ref_rref ( $href );
#    return ($href, \$href ) unless length $key;
#    return unless exists $href->{$key} && defined $href->{$key};
#    return ($href->{$key}, \$href->{$key});
}


1;
