Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: Personal library with CPAN

by monkfan (Curate)
on May 18, 2006 at 05:20 UTC ( #550159=note: print w/replies, xml ) Need Help??

in reply to Re: Personal library with CPAN
in thread Personal library with CPAN

Dear Zaxo,
I had my CPAN installation setting following your ingenious solution above.
I never has compilation problem beforehand when running a Perl script (*.pl).

Recently, while trying a CGI script like below (let's call it 'test.cgi'). I had problem compiling it.
#!/usr/bin/perl -w use CGI ':standard'; use Mail::Sendmail;
Although Mail::Sendmail is successfuly installed, my CGI script can't recognize the location. I encounter this strange result.

When I run this:
$ perl -c test.cgi # it gives test.cgi syntax OK
But when I run this with taint:
$ perl -cT test.cgi It gives: Can't locate Mail/ in @INC (@INC contains: ~/lib/perl5/site +_perl/5.8.5/ /usr/lib/perl5/5.8.5/i386-linux-thread-multi /usr/lib/pe +rl5/5.8.5 /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr +/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/sit +e_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.2/i +386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.1/i386-linux-thre +ad-multi /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi /usr/ +lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/per +l5/site_perl/5.8.3 /usr/lib/perl5/site_perl/5.8.2 /usr/lib/perl5/site +_perl/5.8.1 /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl / +usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl +5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_per +l/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.2/i386 +-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.1/i386-linux-threa +d-multi /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi /usr +/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/li +b/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl/5.8.2 /usr/lib/p +erl5/vendor_perl/5.8.1 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl +5/vendor_perl) at temp.cgi line 4. BEGIN failed--compilation aborted at temp.cgi line 4.
How can I have my cgi script recognize the location of the library? I also tried using "use lib" construct like this:

#!/usr/bin/perl -w use CGI ':standard'; use lib "/lib/perl5/site_perl/5.8.5/"; use lib "/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi"; use Mail::Sendmail;

but also gives the same symptom.
Does it has anything to do to the way I install the module following your approach?

That may fail to influence a web server's Perl environment. If it does, you can use the SetEnv directive in .htaccess or the server configuration for regular cgi scripts.
Just realized you mentioned about the problem above. But how do you actually "SentEnv directive of server config" in my cgi scripts?


Replies are listed 'Best First'.
Re^3: Personal library with CPAN
by Zaxo (Archbishop) on May 18, 2006 at 11:06 UTC

    In a .htaccess file, put

    SetEnv PERL5LIB /where/the/mods/are/:/where/else/lib
    The web server must be able to read files in those directories, of course. Apache suExec is a great help with that, for security's sake.

    See the apache httpd manual for variations that might be handy. When mod_perl is involved, I believe PerlSetEnv is needed, but I've never tried that.

    After Compline,


      I do not have a root (SU) access. Thus, I believe .htaccess cannot be accessible to me. Am I right?
      Is there a way to include somekind of snippet in my CGI script to do the similar thing?
      As you mentioned also earlier as another alternative.

      Update: Along with Zaxo's suggestion above, I can only get my my script going after inserting the following snippet. For further info.
      #!/usr/bin/perl -w use CGI ':standard'; # Newly inserted BEGIN { if ( $ENV{PERL5LIB} and $ENV{PERL5LIB} =~ /^(.*)$/ ) { # Blindly untaint. Taintchecking is to protect # from Web data; # the environment is under our control. eval "use lib '$_';" foreach ( reverse split( /:/, $1 ) ); } } use Mail::Sendmail;


        No, you're not right. The .htaccess files are local to your web space and are owned by you. You should take a good read in the apache manual. All this stuff is covered there

        After Compline,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://550159]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2016-09-28 23:17 GMT
Find Nodes?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:

    Results (541 votes). Check out past polls.