I have written a small perl application for deployment on a few servers. It consists of some scripts, some modules and some data files. It will be used by multiple users. I'd like to keep all these files together in one directory rather than moving the app modules to the site_perl directory.
For example, lets say the application consists of jump.pl swim.pl Common.pm and messages.txt
The application (either of jump.pl or swim.pl) will be invoked from another directory. The installation location of the application may not be on $PATH so the user (or another app) might invoke it by an absolute pathname such as /some/path/swim.pl
or a relative pathname such as ../path/swim.pl
I'd like relocating the application to be as simple as possible, this means having the path to the application in as few places as possible.
At the moment swim.pl and jump.pl start like this
#!/usr/bin/perl
use strict;
use warnings;
use lib '/some/path';
use Common;
#
my $basedir = '/some/path';
...
open my $fh, '<', "$basedir/messages.txt" or die ... ;
So I have /some/path
in several locations in several scripts and modules.
I've considered the following as possible means to minimise the number of different places to store /some/path
- Set environment variable
PERL5LIB=/some/path
and doopen my $fh, '<', "$ENV{PERL5LIB}/messages.txt"
- Set the shebang line to
#!/usr/bin/perl -I/some/path
- but then how find messages.txt? - Try
use Cwd qw(abs_path);
and find a way to usebasename abs_path($0)
foruse lib
inBEGIN
?
Any suggestions to maximise flexibility of location, keep everything together, minimise multiple hard-coding of installation location?