The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


AnyLoader - Automagically loads modules for fully qualified functions


  use AnyLoader;

  Carp::croak("This is going to hurt the Perl community more than it ".
              "is going to hurt you!");


AnyLoader will automagically load the module and import the function for any fully qualified function call. Essentially, this means you can just call functions without worrying about loading the module first.

In the example above, AnyLoader does the equivalent of "require Carp" before the call to Carp::carp(). This should be useful for the many cases where one does:

    if($error) {
        require Carp;

to avoid loading Carp at startup.

AnyLoader is package scoped.

Restricting what gets loaded.

You might not want to let *every* package be AnyLoaded, so ways of qualifying what gets loaded are provided. A list of modules can be given to use AnyLoader and only those modules will be AnyLoaded.

    use AnyLoader qw(Data::Dumper Carp);

    Data::Dumper::Dumper($foo);         # This works.
    LWP::Simple::get($url);             # This doesn't.

If you wish to shut off AnyLoader, no AnyLoader will do so for the current package. no AnyLoader also takes a list of modules. These modules are those which are specifically not to be loaded.

    # AnyLoad anything but LWP and URI::URL.
    no AnyLoader qw(LWP URI::URL);

The lists and effects are cumulative and package scoped (not lexical).


The effects should really be lexically scoped, but I don't think I can pull that off.

This module requires on the "Use of inherited AUTOLOAD for non-method" deprecated feature.

$SIG{__WARN__} had to be used to suppress a warning about the deprecated feature.

Defines UNIVERSAL::AUTOLOAD which may interfere with other modules.

Despite what you'd think, AnyLoader *will* work with modules which employ an autoloader.


Arnar M. Hrafnkelsson <> and Michael G Schwern <>


Copyright (c) 2000 Arnar M. Hrafnkelsson and Michael G Schwern. All Rights Reserved.

You may distribute under the same license as Perl itself.