in reply to How many ways are there to use AUTOLOAD?

One thing to watch out for with this, and with autoload in general is when you have parent / child classes, if your AUTOLOADs actually handle any method calls. You need to be careful that a child AUTOLOAD doesnt die before a parent AUTOLOAD gets a chance to handle the method properly. For example:
package parent; ... sub AUTOLOAD { our $AUTOLOAD; return if ( $AUTOLOAD =~ /DESTROY$/ ); if ( $AUTOLOAD eq 'handled_func' ) { # do something return; } $logger->warn("Tried to call $AUTOLOAD."); } ... package child { ... sub AUTOLOAD { our $AUTOLOAD; return if ( $AUTOLOAD =~ /DESTROY$/ ); $logger->warn("Tried to call $AUTOLOAD."); }
Now if you call handled_func() on a child object, child::AUTOLOAD will *handle* it by logging the warning, when you probably wanted parent::AUTOLOAD to actually deal with the method call

Replies are listed 'Best First'.
Re^2: How many ways are there to use AUTOLOAD?
by talexb (Chancellor) on Jul 20, 2004 at 20:26 UTC

    Interesting point -- as it happens, I'm not using inheritance, so I don't anticipate encountering this problem.

    Alex / talexb / Toronto

    Life is short: get busy!