Search code examples
perlperl-module

Exporting subroutines from a module 'used' via a 'require'


I'm working with a set of perl scripts which our build system is written with. Unfortunately they were not written as a set of modules, but instead a bunch of .pl files which 'require' each other.

After making some changes to a 'LogOutput.pl' which was used by almost every other file, I started to suffer from some issues caused by the file being 'require'd multiple times.

In an effort to fix this, while not changing every file (some of which are not under my direct control), I did the following:

-Move everything in LogOutput.pl to a new file LogOutput.pm, this one having everything needed to make it a module (based on reading http://www.perlmonks.org/?node_id=102347 ).

-Replace the existing LogOutput.pl with the following

BEGIN
{
    use File::Spec;

    push @INC, File::Spec->catfile($BuildScriptsRoot, 'Modules');
}

use COMPANY::LogOutput qw(:DEFAULT);

1;

This works, except that I need to change calling code to prefix the sub names with the new package (i.e. COMPANY::LogOutput::OpenLog instead of just OpenLog)

Is there any way for me to export the new module's subroutine's from within LogOutput.pl?


Solution

  • This turned out to just be a stupid mistake on my part, I didn't put the subs into the @EXPORT list, only into @EXPORT_OK.