June 2001 Making a Module Back Slide 61 Forward

Run the new Function

# my $self = shift;
  no strict 'refs';
  if ($AUTOLOADABLE{$name} eq 'h') {
    my $code = q{
                 sub {
                      my $self = shift;
                      my $val = $self->{METHODNAME};
                      return (($val) ? %{$val} : undef);
                     }
                };
    $code =~ s/METHODNAME/$name/g;

    *$name = eval $code;    
    goto &$name;
  }

  • Eval the new code into a function with the correct name
  • GOTO that function as if it was called directly
  • It also takes @_ as it exists
  • The best of both worlds, quicker startup and minimizes use of AUTOLOAD


Copyright © 2001 R. Geoffrey Avery Back Contents Forward