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

I want to use perl libraries that are not in the standard locations for. The problem I am having is that the script gets executed by Apache(with Mason templates), so I cannot change the library path at the point of of execution.

So my question is, is how can I change the search path to search my custom directories for modules? If I install it in modules that need to use it, will the change cascade down to dependencies?

Replies are listed 'Best First'.
Re: use lib in modules
by moritz (Cardinal) on Apr 03, 2008 at 16:08 UTC
    You can set the PERL5LIB environment variable to the location of your external modules. You can use mod_env to set this.
Re: use lib in modules
by Corion (Patriarch) on Apr 03, 2008 at 15:55 UTC

    What have you tried so far?

    The traditional way to configure Apache is by having a <Perl> section in your site configuration file. Otherwise, have you looked at the lib pragma? In what way does it not work for you?

      The problem I have is that I cannot change the Apache environment.

      Basically I am trying to incorporate new modules in environment where I cannot change anything because of the paranoia of the current developer.

      My solution was to install/upgrade modules in my home directory. If it was a cgi script it would be easy to do this, but with Apache controlling execution I am unsure what other options I have for changing the search path.

      If I use lib in a module (for example) does that globally change the @INC variable? Is there something that would happen that I should know about? I don't know so I figure I would ask.

        If I use lib in a module (for example) does that globally change the @INC variable?
        Yes. What are you (and the paranoid developer) afraid of?
Re: use lib in modules
by leocharre (Priest) on Apr 03, 2008 at 18:10 UTC

    Maybe you are trying to dynamically resolve the path to the lib.. like $ENV{HOME}/mystuff/lib, if you're running as apache, it won't work, HOME won't be set. But DOCUMENT_ROOT will be...

    If you have stuff in /home/username/lib you could do..

    #!/usr/bin/perl use lib '../lib'; use HereThingOnly;

    Which would work in /home/username/cgi-bin/* scripts
    Then there would be a symlink at
    /home/username/public_html/cgi-bin

    Here's another possible solution.. BEGIN { $|=1; use CGI::Carp qw(fatalsToBrowser); eval qq|use lib "$ENV{DOCUMENT_ROOT}/../lib";|; }

    Hope that helps.