This is not at all obvious. The Exporter module provides an export_to_level function that can help solve this problem. Typically, using an Exporter (i.e., creating a package of a subclass of Exporter ) exports the characters to the calling package. The export_to_level method allows export_to_level to export characters to a package above the stack trace, which you want to do here. Here's a proof of concept:
First, some modules with exported functions:
# Module1.pm package Module1; use base 'Exporter'; our @EXPORT = ('foo'); sub foo { "FOO" } 1;
And instead of talking
use Module1; use Module2 'bar'; use Module3 ':all'; use Module4;
in each of the dozens of scripts, you just say
use Module1234;
So here is what Module1234.pm might look Module1234.pm :
package Module1234; # optional use Module1; use Module2; use Module3; use Module4; # these commands could go inside an import method, too. Module1->export_to_level(1, __PACKAGE__); Module2->export_to_level(1, __PACKAGE__, 'bar'); Module3->export_to_level(1, __PACKAGE__, ':all'); 1;
Call now
package MyPackage; use Module1234;
in your script it will load the remaining four modules and process the export of all the desired functions to the MyPackage package and
use Module1234; print foo(), bar(), baz();
enough to output the output of "FOOBARBAZ" .
source share