I'm working with some legacy code that I'd like to tweak, so it's easier to develop and test, and so that its users can use older versions of the code if the current production version happens to have a serious bug.

Give or take, it's in /x/foo/bin and /x/foo/lib, where "foo" is owned by my team and is only used for this particular code base.

My plan is to deploy new versions as, e.g., /x/foo/v1.2/bin and /x/foo/v1.2/lib, and then make the real "bin" and "lib" into symlinks that point to what's in /x/foo/v1.2.

Question is, how best to configure the code so that you can:

as unobtrusively as possible.

If a script has:

use lib "/x/foo/lib";

in it, it's hard-wired to use the production version of the code. If I do something like this instead:

use vars qw( $ROOT );
BEGIN { $ROOT = (defined $ENV{XX_ROOT}) ? $ENV{XX_ROOT} : "/x/foo" }
use lib "$ROOT/lib";

then I get the production version by default, or I can set an XX_ROOT environment variable to point to somewhere else (development code, old production code, whatever) if I want to use a different version, and things work.

However, that's three lines of boilerplate that I have to put into every script (and potentially every library), and seems ugly.

Is there a clean, standard way to do this sort of thing?


In reply to layout/configuration of deployed files by klassa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.