Next Tricks of the Wizards 121

The Self-Replacing Stub

        ...
        require Carp;        
        Carp::croak(...);
        ...

as a way to defer loading of a module until it's needed.

        sub AUTOLOAD {
          if ($AUTOLOAD =~ /::croak$/) {
            require Carp;
            goto &Carp::croak;
          }
        }


Next Copyright © 2003 M. J. Dominus