Next Tricks of the Wizards 108

Generating Functions Dynamically

        sub AUTOLOAD {
          # ... as before; set up $method ...
          my $code = sub {
              my ($self) = @_;
              my $val = $self->{$method};
              $self->{$method} = shift if @_;
              $val;
            };

          *$AUTOLOAD = $code;    
          goto &$AUTOLOAD;
        }


Next Copyright © 2003 M. J. Dominus