[Edinburgh-pm] Dynamic library paths, that work in Test::More & under Apache/mod-perl

Stephen Quinney stephen at jadevine.org.uk
Wed Apr 24 08:11:07 PDT 2013


I would have thought the PerlSwitches directive would do the right thing.
You could try instead adding the following to the relevant httpd.conf
section:

PerlSetEnv PERL5LIB /foo/bar/perllibs





On 24 April 2013 15:40, Ian Stuart <Ian.Stuart at ed.ac.uk> wrote:

> So, I've some CGI scripts that work just ace...
>
> They pass a few hundred Test::More tests, and respond well as CGI
> scripts.... but there is one flaw: they have hard-coded paths in them
>
> Start with the working case - near the start of the script I have:
>
>   use common::sense;
>   use lib "/home/me/project_1/dev/perl5/**lib/perl5/site_perl";
>   use Apache2::RequestRec;
>
> and this works fine under Apache/mod-perl, and passes the tests I throw at
> it.
>
> Of course, to move this to a testing server, I need to edit the 'use lib'
> path (for each script, obviously) - not clever.... so I want to abstract
> the library path
>
> *First attempt*: rely on PERL5LIB in the environment.
>   Running the script from the command line is fine (@INC picks up
> PERL5LIB), but it fails under testing and through apache:
> "Apache2::RequestRec not found" - @INC does not have the stuff from PERL5LIB
>
> *Second attempt*: Add
>   PerlSwitches -I/home/me/project_1/dev/**perl5/lib/perl5/site_perl
>
> into an httpd conf file - nope: still fails
> (and I know the config file is being pulled in as both the cgi-bin and
> scriptAlias' defined in that file are working
>
> *Third attempt*: put something in a BEGIN block:
>   BEGIN {
>     unshift @INC, $ENV{BASE_APR_DIR}."/perl5/**lib/perl5/site_perl";
>     warn Dumper(\%ENV);
>     warn Dumper(\@INC);
>     use Apache2::RequestRec;
>   }
>
> %ENV has
>   'BASE_API_DIR' => '/home/me/project_1/dev'
> but @INC only gets
>    '/perl5/lib/perl5/site_perl'
>
>
> Any thoughts on how to set @INC dynamically?
> ... so I can put a file into Source Control, and it will work whatever the
> root path is?
>
> --
>
> Ian Stuart.
> Developer: ORI, RJ-Broker, and OpenDepot.org
> Bibliographics and Multimedia Service Delivery team,
> EDINA,
> The University of Edinburgh.
>
> http://edina.ac.uk/
>
> This email was sent via the University of Edinburgh.
>
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
> ______________________________**_________________
> Edinburgh-pm mailing list
> Edinburgh-pm at pm.org
> http://mail.pm.org/mailman/**listinfo/edinburgh-pm<http://mail.pm.org/mailman/listinfo/edinburgh-pm>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/edinburgh-pm/attachments/20130424/d938b70d/attachment-0001.html>


More information about the Edinburgh-pm mailing list