in reply to Re^3: Using a module more than once
in thread Using a module more than once

However, as I understand it, you can delay use calls if you are using SelfLoader and then execute the use call inside of a subroutine.

Example:
use SelfLoader; sub __PACKAGE__::myfunc; 1; __DATA__ sub myfunc { use ThisOtherModule; }

Replies are listed 'Best First'.
Re^5: Using a module more than once
by bart (Canon) on Aug 02, 2005 at 17:11 UTC
    Interesting. And it comes with perl 5.8.7, no less. But so does autouse. Its purpose looks similar.
    SelfLoader
    load functions only on demand
    autouse
    postpone load of modules until a function is used

    So... what's the difference between SelfLoader and autouse? And which is "best"?

      I don't know much about autouse, as I haven't tried it out. It looks like autouse's purpose is more context-oriented while SelfLoader is useful in a broader context. The benefit of delaying a 'use Module' command is a side-effect of SelfLoader, while it seems to be the main purpose of autouse.

      SelfLoader delays the compilation of methods/subroutines until they are called, while autouse delays the execution of 'using' a module until it is explicitly called.