use warnings; use strict; package MyThing; sub new { my $class = shift; bless [], $class; } sub set_foo { my ($self, $newfoo) = @_; $self->[0] = $newfoo; } sub get_foo { $_[0]->[0]; } package HashAPI; sub TIEHASH { my $class = shift; bless [], $class; } sub STORE { my ($self, $key, $val) = @_; unless ($key eq 'foo') { die "No $key member\n"; } $self->[0] = $val; } sub FETCH { my ($self, $key, $val) = @_; unless ($key eq 'foo') { die "No $key member\n"; } $self->[0]; } sub new { my $class = shift; tie my(%obj), $class; bless \%obj, $class; } package main; my $clunker = MyThing->new(); my $slick = HashAPI->new(); $clunker->set_foo('Some value'); print $clunker->get_foo, "\n"; $slick->{foo} = 'Some value'; print $slick->{foo}, "\n";