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

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

If I have a perl module installed on a development machine and I want to temporarily run a different version of that module (for example, a copy of the module in a local repo), I can modify the $PERL5LIB in my my bash profile and insert the path to the 'lib' directory in the temporary version of the module to the beginning of $PERL5LIB and then reload bash. Then, to restore the original module, I remove the path to the temporary module form $PERL5LIB and restart bash.

This isn't too bad but just curious to know if others do the same thing or if there is some less hassle free way of doing this. Perhaps I should be using local::lib instead? Note that I'm using perlbrew so I'm not sure if local::lib is a viable option for me. Thanks.

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
$nysus = $PM . ' ' . $MCF;
Click here if you love Perl Monks

  • Comment on Best approach for temporarily swapping out a single perl module for a different version?

Replies are listed 'Best First'.
Re: Best approach for temporarily swapping out a single perl module for a different version?
by choroba (Archbishop) on Jun 25, 2020 at 14:41 UTC
    What I usually do in such a situation: I go to the ~/perl5 directory (created by local::lib), run
    git init git add . git commit -m start
    (if it's not already there, then I don't need to run anything).

    Then I create a branch for experiments, e.g.

    git checkout -b module-3.4
    and actually upgrade the module.

    Installing several different versions in different branches is possible, you can then use git to switch between them and compare the behaviour of your app or tests.

    After the experiment is over, I either stay with the new version

    git checkout master git merge module-3.4
    or I return to master and delete the branch.

    I described the process when I first used it in my blog.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Let me see if I got this straight because I'm not familiar with local::lib and I'm using perlbrew which created ~/perl5 for me.

      So basically you create a giant git repo for all the modules located in the root of ~/perl5? And then when you want to upgrade a single module, you create a new branch and modify that single module? Is that right?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        Exactly. Adding a change can take a second or two, switching the branches is blazing fast.

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re: Best approach for temporarily swapping out a single perl module for a different version?
by Fletch (Chancellor) on Jun 25, 2020 at 14:54 UTC

    The git idea's pretty interesting/clever.

    Then again nothing says you can't whip up a new local::lib sandbox directory and install your new stuff into that and prefix that new directory on PERL5LIB. That'll let you combine possibly upgraded dependencies and still use the normal tools to manage installing everything. If/when you decide to go with the new version you just go back and install into your "normal" l::l directory.

    (And I really like the git idea.)

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: Best approach for temporarily swapping out a single perl module for a different version?
by jcb (Vicar) on Jun 25, 2020 at 23:34 UTC

    Other monks have mentioned a few solutions, but a big question is "how temporary?"

    You could put the special version of the module in its own directory and use the -Idir option when you want to use that version. Then perl will look in that directory before the regular @INC, find the special version first, and load it.

Re: Best approach for temporarily swapping out a single perl module for a different version?
by Flex (Initiate) on Jun 27, 2020 at 12:28 UTC

    I'm not exactly sure how your using the "insert the path to the 'lib' directory"
    but use lib LIST; has a remove no lib LIST; or you can just restore the original @INC = @lib::ORIG_INC;. see lib.

Re: Best approach for temporarily swapping out a single perl module for a different version?
by 1nickt (Abbot) on Jun 26, 2020 at 01:42 UTC

    hi, try perlbrew lib.

    Hope this helps!


    The way forward always starts with a minimal test.

      Thanks for the tip but I couldn't figure out how to use it, exactly. So I create a new lib with perlbrew lib create blah and then I switch to it but then what do I do from there?

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
      $nysus = $PM . ' ' . $MCF;
      Click here if you love Perl Monks

        OK, think I see now. When you switch to new lib, it falls back to the lib for the installed version of perl in ~/perl5 if the module is not yet installed in the new lib. I think this might be a great solution. Glad I asked the question.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks

Re: Best approach for temporarily swapping out a single perl module for a different version?
by Anonymous Monk on Jun 26, 2020 at 14:54 UTC

    This assumes "temporarily" means "only for a specific script." I put the "different version" in its own directory, then the script does a use lib 'different directory'; before it loads the module.