{ package SaneFoo; use Carp; my %Foo = (); sub new { my $self = bless {}, shift; $Foo{$self} = Foo->new; return($self); }; sub allows { my ($self, $method) = @_; return( $method eq "sane" ); }; sub AUTOLOAD { my $self = shift; our $AUTOLOAD; my ($method) = ($AUTOLOAD =~ m/([^:]+)$/); croak "$self cannot $method" unless $self->allows($method); $Foo{$self}->$method; }; sub DESTROY { my $self = shift; delete $Foo{$self}; }; };