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

Esteemed Monks,

In this node, I was helped to find an issue with the version of a module my hosting company provides. I have installed the latest and greatest version of the problem module (CGI::Session) in my local lib, and set use lib to the correct path.

The issue now is that the hosting company has a problematic install of the module, but their module directory has precedence in @INC. Their module is discovered and called first each time. Is it possible to change this, or am I over a barrel until the issue is fixed on the server side? I assume not, after all, perl makes the impossible things possible, (or something like that)

As always, thanks for your wisdom
digger

Replies are listed 'Best First'.
Re: Precedence in @INC
by Abigail-II (Bishop) on May 19, 2003 at 22:15 UTC
    If you use use lib "foo", "foo" will be unshifted on @INC, and hence be tried before other directories. If that won't do it, you could always use no lib "problem_directory" to remove the offending directory from @INC.

    Abigail

Re: Precedence in @INC
by arthas (Hermit) on May 19, 2003 at 22:15 UTC
    If you say:
    use lib '/mypath';
    this should be *prepended* to @INC array, so it should have precedence on your provider's default path.

    However, you cans till delete all @INC contents with:
    no lib;
    and the rebuild it as you wish.

    Michele.
      A fix to myself ;-) The no lib pragma should be followed by the name of the path you want to remove from @INC.
Re: Precedence in @INC
by perrin (Chancellor) on May 19, 2003 at 22:18 UTC
    The use lib pragma puts your added path first in @INC, ahead of anything that was there before. Double-check your assumptions about their directory having precedence in @INC.
Re: Precedence in @INC
by PodMaster (Abbot) on May 19, 2003 at 22:17 UTC
    Are you sure? Try this out
    { local $\="\n"; print for @INC; eval q{ use lib '/digger/'; }; print for @INC; } __END__ C:/Perl/lib C:/Perl/site/lib . /digger/ C:/Perl/lib C:/Perl/site/lib .
    Do you see what "use lib" does? `perldoc lib' reveals its "*almost* the same as saying BEGIN { unshift(@INC, LIST) }"


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Re: Precedence in @INC
by omnibus (Scribe) on May 19, 2003 at 22:15 UTC
    call perl with the -I flag, followed by the path to your install of the modules. Directories following -I are prepended to @INC. You could also use unshift. i.e.
    ... unshift @INC, '/path/to/your/modules'; use YourModule; ...
    Update: As chromatic pointed out, that unshift needs to be in a begin block
Re: Precedence in @INC
by broquaint (Abbot) on May 19, 2003 at 22:16 UTC
    If you use lib that should give your path precedence as it is the equivalent to
    BEGIN { unshift @INC, 'your/path/here' }
    And because @INC is read from left-to-right/bottom-to-top this will mean that perl will look in your path first.
    HTH

    _________
    broquaint

      Why the unshifting inside a BEGIN block if you could use the lib module as well?

      Abigail

        Why the unshifting inside a BEGIN block if you could use the lib module as well?
        Er - it is the equivalent to, as in, that's basically what lib does (as the docs say), I figured that snippet might make it more obvious what lib achieves.
        HTH

        _________
        broquaint

        A 'use' statement is executed at compile time, so any 'use lib' is just like an @INC modification in a BEGIN block. He's right, they're essentially equivalent. The 'use lib' is a little more hands-free convenient and safe, especially with 'no lib' support, but otherwise he's just saying they're doing the same thing.

        --
        [ e d @ h a l l e y . c c ]

Re: Precedence in @INC
by Jaap (Curate) on May 19, 2003 at 22:15 UTC
    Since @INC is an array, have you tried to unshift your new path to @INC before useing CGI::Session?
Re: Precedence in @INC
by physi (Friar) on May 19, 2003 at 22:14 UTC
    update as Abigail-II showed below, that was the wrong way, and I still remember, that my problem was the PERL5LIB. Sorry for the confusion ..

    Not sure if this helps, but I've got a similar problem, that was fixed by using the -T switch!?

    But I have no clue, why ...

    Try:
    #!/usr/bin/perl -T
    in the first line.

    -----------------------------------
    --the good, the bad and the physi--
    -----------------------------------
    
      The effect of the -T switch on @INC is that the environment variable PERL5LIB will be ignored.

      That has nothing at all to do with the problem on hand.

      Please, if you have no clue whether your suggestion is useful, resist the urge for "first post", and wait if someone gives a useful answer. If after half a day the question is still unanswered, you could always come back with an answer. Remember that your answer will be archived and could show up on a site search. Wrong answer reduce the usefulness of site searches.

      Abigail

Re: Precedence in @INC
by digger (Friar) on May 21, 2003 at 17:10 UTC
    I will post code with my questions
    I will post code with my questions
    I will post code with my questions

    Now that I have that out of my system, thanks for pointing out what I should have been able to find out from the Camel. I just assumed that the problem was a precedence issue without RTFMing. In retrospect, the issue is simple, and posting the use lines from my code would have raised flags for you more experienced monks immediatedly. I was simply putting the use lib '/path/to/my/lib' just after the last use statement at the top of my code. I assume the use lib needs to be put before the use for the module in question.

    Moving the use lib line caused my local version to be called correctly, and everything is good with the world.

    digger