Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Wise Monks,

I have to do both module and application development in Perl. Once modules are done, they are placed in a shared repository.

The repository is in a non-standard location and so I use the following in my applications to get at the functionality:

use lib '/foo/bar/shared_modules';

However, sometimes I want to make a small modification to a local copy the module and then use that with my program.

Ideally, I don't want to change the 'use lib' line of the program - the fewer lines that have to change, the better.

I tried to run the application as follows to compile against my local (modified) module:

perl -I/home/user/local_modules MyApplication.pl

But, what I find is that the directory of 'use lib' has precedence. Is there a way from the command line to have my custom module directory searched first?

Replies are listed 'Best First'.
Re: Percedence of -I, use Lib, @INC
by Burak (Chaplain) on Aug 20, 2007 at 17:15 UTC
    You can set the PERL5LIB environment variable and change it anytime you want...
Re: Percedence of -I, use Lib, @INC
by matsi (Novice) on Aug 20, 2007 at 17:49 UTC
    There is a way for your custom module directory to be searched first.
    For this purpose you may manipulate @INC in the following way:
    BEGIN { unshift @INC, 'your_lib_dir_here'; }

      That's just a bad way of doing use lib 'your_lib_dir_here';.

      I am enlightened Thanks to both the above replies.
Re: Percedence of -I, use Lib, @INC
by sgt (Deacon) on Aug 21, 2007 at 16:28 UTC

    seems like you need a code hook in @INC. See 'perldoc perlvar' or 'perldoc -f require'

    another idea is somehow to add a CHECK block to list @INC and exit and generate this way a shell alias for 'perl -M mod1 -M mod2 .... -M modn -M my_last'. seems that chromatic's module Devel::TraceUse could be used. I remember also a module that could preload all the used modules to accelerate the startup (I think Perl hacks mentions it, but I don't have my copy here...)

    cheers --stephan