June 2001 Making a Module Back Slide 56 Forward

Do the function

use vars qw ($AUTOLOAD);
sub AUTOLOAD
{
	my $name = $AUTOLOAD;
	$name =~ s/^.*:://;
	goto &Exporter::AUTOLOAD unless (exists $AUTOLOADABLE{$name});

	my $self = shift;
	if ($AUTOLOADABLE{$name} eq 'h') {
		return %{($self->{$name}	|| undef)};
	} elsif ($AUTOLOADABLE{$name} eq 's') {
		return $self->{$name}		|| undef;
	} else {
		return undef;
	}
}

  • Set $self and write the code that would have been in the method if it really existed
  • Have saved startup time, but AUTOLOAD will be called everytime even if we call the same method many times
  • So we want to replace what is in bold on this slide


Copyright © 2001 R. Geoffrey Avery Back Contents Forward