This and other RFCs are available on the web at
http://dev.perl.org/rfc/
=head1 TITLE
New pragma 'autoloader' to load modules on-demand
=head1 VERSION
Maintainer: Nathan Wiger <[EMAIL PROTECTED]>
Date: 24 Aug 2000
Version: 1
Mailing List: [EMAIL PROTECTED]
Number: 153
Status: Developing
=head1 ABSTRACT
A main goal for Perl 6 is to make it faster, more compact, and lighter
weight. This means moving lots of former core functions into modules.
While good from a computer standpoint, having to start a script with:
#!perl -w
use Unix::User;
use Date::Time;
use IO::File;
use String::Parse;
Just to parse the /etc/passwd file and print the date is "bad".
This RFC proposes a new pragma, C<autoloader>, that could autoload the
functions from the appropriate modules on-demand.
=head1 DESCRIPTION
=head2 The Basics
The new C<autoloader> pragma would rely on a C<registry> file that was
located in C<@INC> and looked something like this:
# proposed registry format
# function module
getpwnam Unix::User
date Date::Time
time Date::Time
open IO::File
chomp String::Chomp
This file could be auto-appended to by module installations, similar to
C<.packlist>. However, it could also be manually modified by the system
administrator. A custom one could also be included in C<@INC> ahead of
the system one so that a user could include their own definitions.
The script would then start with:
#!perl -w
use autoloader;
$uid = getpwnam($>);
Which would autoload C<getpwnam> from C<Unix::User> per the C<registry>
file.
In addition, the C<autoloader> should be able to handle simple C<use>
operations:
#!perl -w
use autoloader;
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 C<use>'d (actually,
required/imported) each module, since C<@INC> is still searched.
=head2 Extensions
The C<autoloader> pragma could be extended in several ways:
1. If duplicate modules or methods are found, we might want
the <autoloader> to issue messages like:
Duplicate CGI.pm modules found - autoloading
/path/to/perl6/lib/CGI.pm
Duplicate getpwnam functions registered - using
Unix::User::getpwnam
2. The C<registry> file could list version numbers and the
such to take advantage of advanced module versioning
as mentioned in RFC 78.
3. If it works really well, we could enable it by default and
then use 'no autoloader' if we wanted fine-grained control.
Pretty sure I don't like the last one, but it's worth considering.
=head1 IMPLEMENTATION
Mostly harmless. Could probably be implemented in Perl 5 as a
require/import based on the C<registry> file.
=head1 MIGRATION
None. This introduces new functionality.
=head1 NOTES
Alternatives to the Microsquish-centric C<registry> file name are
greatly welcomed. If used by other Perl routines, a generic name (like
"registry") is probably appropriate. However, if only the C<autoloader>
pragma uses this information then perhaps C<autoloader.conf> is more
appropriate.
=head1 REFERENCES
http://www.mail-archive.com/perl6-language@perl.org/msg02576.html
RFC 78: Improved Module Versioning And Searching