| Next | Tricks of the Wizards | 107 |
If there's a lot of autoloaded code, it makes more sense to keep it in a file
sub AUTOLOAD {
my $file = $AUTOLOAD;
$file =~ s{::}{/}g;
$file = "/src/app/autoloaded/$file.al";
open my $fh, "< $file"
or croak "Couldn't load code from $file: $!; aborting";
my $code;
{ local $/; $code = <$fh> }
*$AUTOLOAD = eval $code;
goto &$AUTOLOAD;
}
The first time the function is called, the code is loaded from the file
Code for Some::Module::foo is in .../Some/Module/foo.al
Code compiled and installed in symbol table as before
Second time, the function is called directly - no overhead
Now you know what AutoLoader does - invented for POSIX
| Next | ![]() |
Copyright © 2003 M. J. Dominus |