<div dir="ltr">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:<div><br></div><div>PerlSetEnv PERL5LIB /foo/bar/perllibs<br>
</div><div><br></div><div style><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 24 April 2013 15:40, Ian Stuart <span dir="ltr"><<a href="mailto:Ian.Stuart@ed.ac.uk" target="_blank">Ian.Stuart@ed.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So, I've some CGI scripts that work just ace...<br>
<br>
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<br>
<br>
Start with the working case - near the start of the script I have:<br>
<br>
  use common::sense;<br>
  use lib "/home/me/project_1/dev/perl5/<u></u>lib/perl5/site_perl";<br>
  use Apache2::RequestRec;<br>
<br>
and this works fine under Apache/mod-perl, and passes the tests I throw at it.<br>
<br>
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<br>
<br>
*First attempt*: rely on PERL5LIB in the environment.<br>
  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<br>
<br>
*Second attempt*: Add<br>
  PerlSwitches -I/home/me/project_1/dev/<u></u>perl5/lib/perl5/site_perl<br>
<br>
into an httpd conf file - nope: still fails<br>
(and I know the config file is being pulled in as both the cgi-bin and scriptAlias' defined in that file are working<br>
<br>
*Third attempt*: put something in a BEGIN block:<br>
  BEGIN {<br>
    unshift @INC, $ENV{BASE_APR_DIR}."/perl5/<u></u>lib/perl5/site_perl";<br>
    warn Dumper(\%ENV);<br>
    warn Dumper(\@INC);<br>
    use Apache2::RequestRec;<br>
  }<br>
<br>
%ENV has<br>
  'BASE_API_DIR' => '/home/me/project_1/dev'<br>
but @INC only gets<br>
   '/perl5/lib/perl5/site_perl'<br>
<br>
<br>
Any thoughts on how to set @INC dynamically?<br>
... so I can put a file into Source Control, and it will work whatever the root path is?<br>
<br>
-- <br>
<br>
Ian Stuart.<br>
Developer: ORI, RJ-Broker, and OpenDepot.org<br>
Bibliographics and Multimedia Service Delivery team,<br>
EDINA,<br>
The University of Edinburgh.<br>
<br>
<a href="http://edina.ac.uk/" target="_blank">http://edina.ac.uk/</a><br>
<br>
This email was sent via the University of Edinburgh.<br>
<br>
The University of Edinburgh is a charitable body, registered in<br>
Scotland, with registration number SC005336.<br>
<br>
______________________________<u></u>_________________<br>
Edinburgh-pm mailing list<br>
<a href="mailto:Edinburgh-pm@pm.org" target="_blank">Edinburgh-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/edinburgh-pm" target="_blank">http://mail.pm.org/mailman/<u></u>listinfo/edinburgh-pm</a><br>
</blockquote></div><br></div>