sub AUTOLOAD { my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); my $code_ref = DBI::db->can($method); if (!$code_ref) { require Carp; Carp::croak("Undefined subroutine $method called"); } # This only works with methods, # and only if they are non-static # (just like your code). local $_[0] = $_[0]->{DBH}; goto($code_ref); } #### sub AUTOLOAD { my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::')+2); my $code_ref = DBI::db->can($method); if (!$code_ref) { require Carp; Carp::croak("Undefined subroutine $method called"); } my $stub = sub { # This only works with methods, # and only if they are non-static # (just like your code). local $_[0] = $_[0]->{DBH}; &$code_ref; }; { no strict 'refs'; *$method = $stub; } goto($stub); }