[% setvar title New pragma 'autoload' to load functions and modules on-demand %]
To see what is currently happening visit http://www.perl6.org/
New pragma 'autoload' to load functions and modules on-demand
Maintainer: Nathan Wiger <firstname.lastname@example.org> Date: 24 Aug 2000 Last Modified: 19 Sep 2000 Mailing List: email@example.com Number: 153 Version: 2 Status: Frozen
Some goals for Perl 6 include making it more compact and lighter weight.
While much stuff will remain available, many things are potentially
being moved out of core and into modules, like
gmtime, and so on.
While good from a computer standpoint, having to start a script with:
#!perl -w use User::pwent; use Time::Local; use Format; use String::Util;
Just to parse the
/etc/passwd file and print the date is "bad".
This RFC proposes a new pragma,
autoload, that could autoload the
functions from the appropriate modules on-demand. Unlike the existing
autouse, which loads modules on demand that you specifically tell it
autoload looks at a configuration file and loads the appropriate
modules for you.
autoload pragma would rely on an
autoload.conf file that
was located in
@INC and looked something like this:
# proposed autoload.conf format # function module getpwnam User::pwent date Date::Time time Date::Time open IO::File chomp String::Util
This file could be auto-appended to by module installations, similar to
.packlist. However, it could also be manually modified by the system
administrator. A custom one could also be included in
@INC ahead of
the system one so that a user could include their own definitions. The
user can also specify the path to a custom configuration file via the
use autoload pragma directly:
The script would then start with:
#!perl -w use autoload '/home/nwiger/perl/autoload.conf'; $uid = getpwnam($>);
Which would autoload
User::pwent per the
/home/nwiger/perl/autoload.conf file. Like
use lib, this should
just add an additional config file to read onto the start of the search
autoload should be able to handle simple
#!perl -w use autoload; my $r = new CGI; # these are both loaded from tie %session, Apache::Session; # @INC just like via 'use'
This makes easy things easier. The person still gets the same
functionality as if they had manually
import'ed) each module, since
@INC is still
On installation, some part of the Perl module install driven by
MakeMaker would have to read the exported function list from a given
module and append it to the
autoload pragma could be extended in several ways:
1. If duplicate modules or methods are found, <autoload> should issue messages like: Duplicate CGI modules found - autoloading /path/to/CGI.pm Duplicate getpwnam functions registered - using User::pwent::getpwnam C<autoload> should always use the last one in the list, since this will be the most recent one if the person is not actively maintaining the file (i.e., just letting it be appended to automatically). 2. The C<autoload.conf> file could list version numbers and the such to take advantage of advanced module versioning as mentioned in RFC 78.
Mostly harmless. Right before raising the famous "Can't locate method
..." error, Perl should check to see if
autoload is in effect. If so,
it should read the
autoload.conf config file and try to load the
appropriate function and module. If not possible, then the error should
None. This introduces new functionality.
RFC 78: Improved Module Versioning And Searching
use autouse pragma/module