Next Tricks of the Wizards 204

Import.pm Module

        sub AUTOLOAD {
          my $code = get_code($AUTOLOAD);
          goto &$code if $code;
          die "Undefined subroutine $AUTOLOAD called";
        }
        sub get_code {
          my ($fullname) = @_;
          return \&$fullname if defined &$fullname;
          my($pkg, $sub) = ($fullname =~ /(.*)::(.*)/);
          for my $parent (@{$pkg . '::ISA'}) {
            my $code = get_code(join '::', $parent, $sub);
            return $code if defined $code;
          }
          return;
        }


Next Copyright © 2003 M. J. Dominus