in reply to Where to install my own perl modules?

As the resident "Perlmeister" where I work I wrestle with that question all the time. There are several options that I use depending on the situation:

Some preconditions to consider:

The first thing I have to say to pre-qualify all that I am going to say on this subject is the fact we have a convention where I work that all third party software installed on our supported systems goes into /usr/local/software and each software package goes into its own subdirectory with some sort of revision tag in its name. Example we would put Perl version 5.8 into a subdirectory under /usr/local/software/perl-5.8 with appropriate symbolic links to places like /usr/bin and /usr/lib etc. This makes it real easy to deploy new versions of things onto our supported systems and roll back if necessary and other options.

Application Specific Modules

Keeping that scheme in mind if I or someone on my team has written a module specific to a patricular application then that module is going to get installed in the subdirectory that the application has been installed in. For instance if I have an application called "mailStripper" and its version number is 2.1 then it will get installed in /usr/local/software/mailStripper-2.1 with its modules installed in /usr/local/software/mailStripper-2.1/lib/perl5 and in subdirectories as appropriate. This means that I have to tell the individual scripts for that application where to find its modules. One of many ways of doing this of course is:
use lib qq(/usr/local/software/mailStripper-2.1/lib/perl5);
The weakness of doing that keep in mind is that if I change the version of the application and it gets installed somewhere else I have to make sure I update the use line as appropriate.

Still local, but I don't want to mix it into Perl's installation directory

Still keeping in mind the scheme we are using for installing third party software there are cases where I want to make locally developed modules available to multiple applications. We will install those in a directory /usr/local/software/lib/perl5. Again you need to do the use lib ... thing in scripts using those modules.

Put in with the rest of the modules!

If you really insist on not dealing with putting use lib... in your scripts to get to your modules then you can always do a
perl -e "print join($/,@INC);"
and see where Perl expects to find modules and put your stuff in there. The burden you now have is to keep track of what you put there in the event you upgrade Perl and have to re-install your modules.

TIAMTOWTDI in Perl...


Peter L. Berghold -- Unix Professional
Peter at Berghold dot Net
   Dog trainer, dog agility exhibitor, brewer of fine Belgian style ales. Happiness is a warm, tired, contented dog curled up at your side and a good Belgian ale in your chalice.

Replies are listed 'Best First'.
Re: Re: Where to install my own perl modules?
by rinceWind (Monsignor) on Mar 29, 2004 at 11:59 UTC
    I would suggest setting the environment variable PERL5LIB externally to running perl scripts, rather than hacking every script to add a use lib. This is considerably less maintenance if you decide to change your directory structure - like upgrading a version.
    The burden you now have is to keep track of what you put there in the event you upgrade Perl and have to re-install your modules.
    There's even a way round this. If you install to a common directory, you can share modules between perl versions:
    perl Makefile.PL LIB=$MYSHARE/lib PREFIX=$MYSHARE make make test make install
    Note that $MYSHARE is a shell environment variable pointing to a path to which you as installer have write access. This even means that you can set up modules without needing root or sysadmin rights.

    To use said directory, set PERL5LIB to include $MYSHARE in the path. It also makes installation possible to other nodes without invoking perl (just tar up the directory and distribute it).

    I tend to specify both LIB and PREFIX because for the following reasons: LIB is specified so that all .pm and XS code can be found. PREFIX is specified to provide placeholders for manpages and any other collateral that does not end up in the LIB. Note: you might get problems between perl versions if you have incompatible XS binaries.

    --
    I'm Not Just Another Perl Hacker