June 2001 Making a Module Back Slide 57 Forward

Do $self later

# 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;
  }

  • Don't set $self because this function will not actually do any work on it
  • Do set $self inside the new function where the work is done


Copyright © 2001 R. Geoffrey Avery Back Contents Forward