Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Do Pure Perl CPAN packages really need to use ExtUtils::Command::MM?

by Eliya (Vicar)
on Feb 17, 2011 at 21:55 UTC ( #888807=note: print w/ replies, xml ) Need Help??


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.


Comment on Re^3: Do Pure Perl CPAN packages really need to use ExtUtils::Command::MM?
Select or Download Code
Re^4: Do Pure Perl CPAN packages really need to use ExtUtils::Command::MM?
by ELISHEVA (Prior) on Feb 18, 2011 at 00:27 UTC

    I want to ++ this a thousand times tonight. This worked! I totally missed the "MY::post_initialize" when I was reading the docs and studying the source code yesterday.

    I had to modify it slightly so I didn't clobber the user's settings. Some people install CPAN software into their home dir and may be using PERL5LIB to add those to their module search path.

    use File::Spec; use Config; sub MY::post_initialize { my $sInc = File::Spec->rel2abs('inc', $ENV{PWD}); my $sSep = $Config{path_sep}; my $PERL5LIB=$ENV{PERL5LIB}; return "PERL5LIB := $PERL5LIB$sSep$sInc"; }

    Update: After grepping through the code one more time I found where this is documented:ExtUtils::MM::Unix. I do remember reading it yesterday, but when I read the documentation I didn't connect the dots:

    Returns an empty string per default. Used in Makefile.PLs to add some chunk of text to the Makefile after the object is initialized.

    The object, what object? Thanks once again.

    Update: added comment about portable way to append paths to PERL5LIB

    Update: updated with resolution portability issue

        Can you name a specific platform where setting PERL5LIB in the makefile will be invisible to perl called from within the makefile?

        blib/ExtUtils::testlib simply adds cwd()/blib/arch and cwd()/blib/lib to @INC. "make test" already puts those in @INC. To eliminate the tension between MakeMaker and ModuleBuild without placing all sorts of stuff in the project root, I would need a portable way to get ExtUtils::MakeMaker to put "projectroot/inc", a directory used by [mod://Module::Build], into @INC.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://888807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-12-20 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (95 votes), past polls