perl5ever has asked for the wisdom of the Perl Monks concerning the following question:

Is there a CPAN module which implements lazy compilation of modules via the following idea:

1. unshifts a sub ref/object to @INC which when use X is encountered will install an AUTOLOAD stub for package X.

2. The AUTOLOAD stub will 1) remove itself from package X and 2) perform a do on the real path of the module and 3) goto &$AUTOLOAD.

The main purpose would be to avoid loading/compiling a module until when one of its subroutines was actually called. It wouldn't work for all modules (such as meta-programming modules or ones that exported symbols), but it could work for fairly "conventional" modules.

Does anything like that currently exist?

Replies are listed 'Best First'.
Re: lazy loading of modules
by Corion (Patriarch) on Jan 31, 2010 at 21:37 UTC
Re: lazy loading of modules
by shmem (Chancellor) on Jan 31, 2010 at 23:04 UTC
    The main purpose would be to avoid loading/compiling a module until when one of its subroutines was actually called.

    Not quite in the way you've outlined, but the (core) module autouse does that:

    NAME
    autouse - postpone load of modules until a function is used
Re: lazy loading of modules
by Khen1950fx (Canon) on Jan 31, 2010 at 22:11 UTC