klassa has asked for the wisdom of the Perl Monks concerning the following question:
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:
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?
|
|---|