package Tie::BUKHash; sub TIEHASH { bless {}, ref $_[0] or $_[0]; } sub FETCH { my ($this, $key) = @_; return new Tie::BUKHash::Elem( $this, $key ); } sub STORE { my ($this, $key, $value) = @_; $this->{$key} = $value; } package Tie::BUKHash::Elem; use WeakRef 'weaken'; use Carp 'croak'; use constant HASH => 0; use constant KEY => 1; sub new { my ($proto, $hash, $key) = @_; my $self = bless [weaken($hash), $key], ref $proto or $proto; } sub get { my $self = shift; my $hash = $self->gethash; return $hash->{$self->[KEY]}; } sub set { my ($self, $val) = @_; my $hash = $self->gethash; $hash->{$self->[KEY]} = $val; } sub delete { my $self = shift; my $hash = $self->gethash; delete $hash->{$self->[KEY]}; } sub gethash { my $self = shift; return $self->[HASH] or croak "You shouldn't keep hash entries around after their respe +ctive hashes are gone!" ; }
In reply to Re^4: Pronoun Programming
by plobsing
in thread Pronoun Programming
by rje
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |