I have many standalone scripts. The only thing they share, is that they use() a large set of CPAN modules (that each export several functions). I would like to centralize th
The problem with all three of your proposed solutions is that the module may be use
d from another module, in which case the symbols should be exported into the use
ing module's package, not into main
.
bvr's solution of using caller
to import things directly into that package is a major step in the right direction, but prevents the 'real' package from using use ShareableModules qw( foo bar baz);
to selectively import only what it actually needs.
Unfortunately, preserving the ability to import selectively will require you to import all relevant symbols from the underlying modules and then re-export them from ShareableModules. You can't just delegate the import to each underlying module's import
method (as Modern::Perl
does) because import
dies if it's asked for a symbol that isn't exported by that module. If that's not an issue, though, then Modern::Perl
's way of doing it is probably the cleanest and simplest option.