I'm trying to write a Perl Module for learning purposes and I have a few doubts regarding the usage of several .pm files within a module.

While writing the module, I realised I was trying to cram a bit too much in it, and therefore I decided to split it into 3 sub-modules: there's a core .pm file and then 2 "optional" .pm files. The idea is that a "user" would surely include the 1st .pm in his script, while the two supplementary "submodules" contain routines the user will optionally want to look at only AFTER having done a run of the core module.

For instance, let's say the first module outputs a TSV data file (eg use computeTSV). Then, the second data file might compute and add a further column of data to such tsv (eg use computeTSV::addScores). Same story for the third (eg computerTSV::getNetworkRepresentation).

Now my problem is: there are some constants and a couple of subroutines that I would happily keep, unchanged, in all of the three "submodules". E.g. I have the TSV header field names, but also some db connection subroutines,etc, that appear identical in the 3 .pm files.

In order not to have 3 copies of said constants/subroutines, I was considering adding a 4th file to the mix, (something like a .h file in the C programming language) where I'll dump all the these global constants, subroutines, and nothing else. Let's call this file globals.pm. Does this make sense or is there a better way to do this?

Now my question: it's clear I would like to export ALL of the content of global.pm in my three modules files. Is there a way to do this? Or, do I have to manually add ALL of the constants and subroutines in global.pm using the

Now my question: it's clear I would like to export ALL of the content of global.pm in my three modules files. Is there a way to do this? Or, do I have to manually add ALL of the constants and subroutines in global.pm using the

@EXPORT = qw(...);

paradigm?

If your constants are declared with

use constant ....

Export::NoWork (available on CPAN) could do what you want. If your constants are declared using the CPAN module

Readonly ....

you would have to write your own logic. Since you have access to the symbol table, you can write a import function which walks through all those constants and have it injected into the name space of the importing module.