http://www.perlmonks.org?node_id=888807


in reply to Re^2: Do Pure Perl CPAN packages really need to use ExtUtils::Command::MM?
in thread Do Pure Perl CPAN packages really need to use ExtUtils::Command::MM?

...I am referring to the contents of @INC before any script calls use lib or any command line sets and exports PERL5LIB.

I'm not saying this is the recommended way to do it, but technically, the following should work:

Set PERL5LIB in the Makefile

export PERL5LIB = ...path/to/lib

As any command being run for the "test" target (or any other target) is a subprocess of make, it will inherit the environment variable, so the lib dir is being added to @INC for all tests.

What remains to be solved is how to get MakeMaker to put the above line in the generated Makefile. A quick test shows that this can be achieved by overriding the routine post_initialize, which is responsible for creating a (normally empty) section at the beginning of the Makefile.  I.e., add a MY::post_initialize routine to your Makefile.PL:

use ExtUtils::MakeMaker; sub MY::post_initialize { return "export PERL5LIB = ...path/to/lib"; } WriteMakefile( ... );

This generates a section in the Makefile

# --- MakeMaker post_initialize section: export PERL5LIB = ...path/to/lib

which causes make to set PERL5LIB in its environment.