I was noticing in some module libraries, the caller was required to use Library::This and use Library::That separately. Other libraries had a "meta" module which would have the effect of importing all of the others for you in one simple use Library statement.

Normally, if a package uses some other module, the symbols are only imported for the package's use. With the caller function, a crafty meta-package can emulate the use statements on behalf of the main script. This can make the Library more friendly to use and document.

package Library; ... sub import { my $calling = (caller())[0]; eval qq{ # Load these on behalf of the calling package. package $calling; use Library::This; use Library::That; use Library::TheOther::Thing; }; die $@ if $@; }

Replies are listed 'Best First'.
Re: Meta Module imports several packages
by Aristotle (Chancellor) on May 04, 2003 at 13:54 UTC
    See also Dominus' ModuleBundle which presents a more generalized solution.

    Makeshifts last the longest.

      Thanks, that's a great little module. I hope it gets elevated to the core distribution. As a module author, I try not to create dependencies on Yet Another Obscure Module From CPAN. There's a balance between reinventing the wheel and requiring a fifth wheel.

      --
      [ e d @ h a l l e y . c c ]