Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How to run a legacy perl version smoothly from perlbrew & Carton

by chrestomanci (Priest)
on Dec 17, 2020 at 13:11 UTC ( #11125334=perlquestion: print w/replies, xml ) Need Help??

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

Greetings wise brothers, I seek your advice on how to concurrently access the old and the new.

I am working on a legacy Perl system that makes heavy use of Storable objects (in a database, traversing the network etc), so it has to run Perl 5.10.1 and no other version. Up until now, it has been run on Ubuntu 10.04 Lucid, which means running a 10 year old Linux distro (with no support) on 10 year old hardware also with no support that could die at any moment.

I would like to migrate the system to a modern OS (Ubuntu 20.04 Focal) and hardware, while using perlbrew to run the application using the correct Perl version. I have successfully built and installed Perl 5.10.1 and all the necessary libraries using Carton, but I have two problems with this setup that I would like to solve.

Firstly, to run a Perl script with the correct libraries, I need to put “carton exec” on the front of each script invocation. If you don’t do that then the correct Perl binary runs, but it fails because it cannot find the modules that carton installed.

How can I arrange things so that just running perl from a shell will do the right thing? (Run Perl 5.10.0 with the carton installed modules available), Perhaps by tweaking PERL5LIB for bash shells, or putting a wrapper script into the path? (note that I don't need to worry about multi user accounts here, all users login as root!)

Secondly, there are about 200 CGI scripts mostly in Perl, and each with a #!/usr/bin/perl shebang line. How should I configure Apache to call my perlbrew installed version of perl, again with the carton installed modules, preferably without re-writing the shebang line on every script, though if I must do that, then the change needs to be backwards compatible with the old setup.

Note that this is plain old CGI, not modperl FastCGI or anything like that. I would not object to using an FCGI wrapper if it can be dropped in painlessly, but not if it would require modifications to the scripts, or could be a source of bugs or incompatibilities.

And before you say it, Yes I am well aware that it would be better to migrate away from Perl Storable. I have seen Elizabeth Mattijsen’s talks on how Booking.com did so at various Perl events. I also know that plain old CGI is no longer considered best practice. My problem is that this is a legacy system, and there is not much time or money available for major system changes, and there is no appetite for anything that could introduce hard to find bugs.

Replies are listed 'Best First'.
Re: How to run a legacy perl version smoothly from perlbrew & Carton
by ikegami (Patriarch) on Dec 17, 2020 at 13:27 UTC
    I don't know what Carton is, so just covering this:

    Secondly, there are about 200 CGI scripts mostly in Perl, and each with a #!/usr/bin/perl shebang line

    find ... -name '*.cgi' -type f \ -exec perl -pe's{^#!.*?/perl}{#!/.../perl} if $. == 1' -i~ {} \;

      Alternately replace the hardcoded shebang path with #!/usr/bin/env perl and then you can diddle all of them using PATH rather than editing things in place.

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

        I strongly disagree. You don't want your script, especially a production application, to suddenly start using a different perl (which might not be compatible or might not have the correct modules installed).

        I would create a perlbrew alias for each project and use that. This would allow testing with different versions, etc. by modifying the alias.

plenv might serve your purpose
by gnosti (Hermit) on Dec 18, 2020 at 04:03 UTC
    Hi,

    I'm also unfamiliar with carton, just noting that it's possible plenv may suit your purpose better than perlbrew, as plenv allows setting the perl version globally, or per directory, without having to munge your $PATH.

    hth

Re: How to run a legacy perl version smoothly from perlbrew & Carton
by 1nickt (Canon) on Dec 18, 2020 at 18:00 UTC

    Hi, good choice of tools.

    "Firstly, to run a Perl script with the correct libraries, I need to put “carton exec” on the front of each script invocation. If you don’t do that then the correct Perl binary runs, but it fails because it cannot find the modules that carton installed.

    How can I arrange things so that just running perl from a shell will do the right thing? (Run Perl 5.10.0 with the carton installed modules available), Perhaps by tweaking PERL5LIB for bash shells, or putting a wrapper script into the path? (note that I don't need to worry about multi user accounts here, all users login as root!)"

    You can avoid having to use carton exec by setting the included library path:

    perl -Ilocal/lib/perl5 <cmd>
    ...or set PERL5lIB.

    Note however that you can avoid using local/ at all and install the modules into the normal location if you use carton bundle to make an archive of the sources (after having installed them one time with carton install). This will be placed into vendor/cache but you can move it somewhere. Then install your dependencies at build time using cpanm --from file://path/to/the/cache.

    I also recommend using perlbrew libs to keep your Perl version installation core-mdoules only. Then you can test installing dependencies multiple times without having to compile Perl over and over. I also use one perlbrew lib to build the cache, allowing carton to install in local/, and then after saving the cache as described above, I remove local/ and install to a fresh perlbrew lib for development, using the cache as described above.

    Hope this helps!


    The way forward always starts with a minimal test.
Re: How to run a legacy perl version smoothly from perlbrew & Carton
by perlfan (Vicar) on Dec 18, 2020 at 17:36 UTC
    Install perlbrew and get the perl you want into your PATH using the prescribed method of your choice. From there, use perlbrew --install-cpan to get cpanm (perl agnostic). The hook up cpanm to Carton (don't know how, but it should be possible), then boom you're off to the racest. The big thing to remember when installing modules is that it is critical that the correct perl is in your PATH.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11125334]
Approved by hippo
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2022-10-01 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (126 votes). Check out past polls.

    Notices?