leocharre has asked for the wisdom of the Perl Monks concerning the following question:

I'm developing some web software. I'm testing on multiple apache/linux servers. I have a lib dir with my testing modules for each account, and for each cgi file, I have a use lib '/misc/home/path/lib';

So each account's cgi files need a diff use lib path. It's almost ok, I can run cli perl on these guys, still.. it's a pain.

Here's what I'm looking into..

Am I missing some more obvious solution? Keep in mind there is no root access.

udpate

Adding this to the .htaccess file:
SetEnv PERL5LIB '/path/you/want'; Works sometimes. It will not work if you use Taint mode, so.. no cigar.

Another interesting tidbit is Baselib.pm, but it requires BaseLib be installed .. so.. catch22 :).

It seemed intuitive to do use lib "$ENV{HOME}/lib";, but that is also not reliable. None of these accounts accept that.

One way that works with Taint:

BEGIN { $ENV{DOCUMENT_ROOT}=~m/^([\w\-\/]+)$/i; eval "use lib '$1/../lib';"; } # this is unreliable: #BEGIN { # use lib do { # $ENV{DOCUMENT_ROOT}=~m/^([\w\-\/]+)$/i; # } . '/../lib'; #}

Replies are listed 'Best First'.
Re: how to add web hosting account-wide use lib ?
by shmem (Chancellor) on Jun 21, 2006 at 13:45 UTC
    there are various ways, depending on your setup. If you use suexec you could use
    use lib "$ENV{HOME}/lib";
    Then there is also the posiblity to set environment variables in apache which get passed to CGI or fastcgi scripts. See SetEnv Directive. So, if you set
    SetEnv PERL5LIB /home/abraxas/lib
    in a .htacces file, you don't even need use lib, because perl prepends $PERL5LIB to the standard module path.
    _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                  /\_¯/(q    /
    ----------------------------  \__(m.====·.(_("always off the crowd"))."·
    ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
Re: how to add web hosting account-wide use lib ?
by sgifford (Prior) on Jun 21, 2006 at 15:58 UTC
    Taint mode was designed to protect against a shell user who can set environment variables, which is why it ignores $PERL5LIB. In a Web application, however, the environment is not under the control of a potential attacker, so it's not a threat. In many of my perl scripts, I use this code to pay attention to $PERL5LIB even in taint mode:
    BEGIN { # Blindly untaint. Taintchecking is to protect from Web data; # the environment is under our control. if ($ENV{PERL5LIB} and $ENV{PERL5LIB} =~ /^(.*)$/) { eval "use lib '$_';" foreach (reverse split(/:/,$1)); } if ($ENV{PATH} and $ENV{PATH} =~ /^(.*)$/) { $ENV{PATH}=$1; } }

      Thank you!!! This is very interesting, what I had ended up doing was this:

      BEGIN { $ENV{DOCUMENT_ROOT}=~m/^([\w\-\/]+)$/i; eval "use lib '$1/../lib';"; } # this is unreliable: #BEGIN { # use lib do { # $ENV{DOCUMENT_ROOT}=~m/^([\w\-\/]+)$/i; # } . '/../lib'; #}

      It's similar, (my HOME was not set )just a hack, so there must be some hole the size of *## that I'm not noticing yet.
      It checks a little bit for an ok path

      Is there any setup that by default looks for a perl lib for the user like home/perl-lib ? I guess I'm thinking of maybe some movement to do this by a hosting company, etc. Maybe it's just no big deal. It seems a lot of dabblers and devels would find that to be one more candy piece.

A reply falls below the community's threshold of quality. You may see it by logging in.