Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [tlug] Non-standard Perl Module Locations



On 2008-03-12 15:12 +0900 (Wed), Tod McQuillin wrote:

> On Tue, 11 Mar 2008, steven smith wrote:
>
>> Sometimes you will have to do your include path manipulation inside a 
>> BEGIN block so it will get executed before you have loaded any modules 
>> too.
>
> This is why Larry invented 'use lib'.  See 'perldoc lib' for details.

Right. I was actually using that at first, but it gets a bit tricky when
you need to dynamically generate the paths based on the the location of
the file.

(Much as libraries used by /usr/local/bin/program are in /usr/local/lib,
I know that if I am /a/b/c/release/bin/program, my libraries are in the
appropriate places under /a/b/c/release/lib.)

So what I ended up doing, which may not be optimial is adding the following
at the begining of each perl script in bin:

    BEGIN {
	require File::Basename;
	require(File::Basename::dirname($0) . "/../qam.pl");
	}

(I'd like to make this smaller, if anybody has any good ideas.)

This is release/qam.pl:

    package QAM;

    use File::Basename; 
    use Cwd 'abs_path';

    $base = dirname(abs_path(__FILE__));

    @inc_prefix = map {
	($path = $_) =~ s,.*/lib/,$base/lib/,; $path
	} grep(/\/lib\//, @INC);
    foreach (reverse @inc_prefix) { unshift @INC, $_; }

    1; 

One of the tricks of this is that the perl library paths vary
quite a lot among systems, beyond just the prefix. Between my
NetBSD box and Bryan's Linux box there's the obvious difference
of /usr/pkg/lib versus /usr/lib, but the differences below that
for, say, the architecture-specific library directory are quite
dramatic: lib/perl5/site_perl/5.8.0/i386-netbsd-thread-multi versus
lib/perl/5.8.0.

When I install a module to be used by my programs into my project
release directory with "perl Makefile.PL PREFIX=/a/b/c/release",
MakeMaker uses what ever the system perl uses in terms of paths below
lib. So I reckoned the easiest way to deal with that was just to look
at all standard @INC paths, and duplicate them with the prefix to my
release directory replacing .../lib/, e.g., /usr/lib/perl/5.8.0/ to
/a/b/c/release/lib/perl/5.8.0. That's what qam.pl does. Basically, if
you can find that, usually by knowing where you normally live relative
to qam.pl, you're set.

Thoughts?

cjs
-- 
Curt Sampson       <cjs@example.com>        +81 90 7737 2974   
Mobile sites and software consulting: http://www.starling-software.com


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links