tags:

views:

99

answers:

2

I have the follwing, simplest Perl CGI script:

use strict;
use warnings;
use CGI();
use CGI::Carp qw(fatalsToBrowser);

use Template;

print CGI::header();

foreach(@INC) {
    print "$_\n";
}

When called (http://[..]/cgi-bin/p.cgi) I am given the following error:

Can't locate Template.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at /home/pistacchio/webapps/htdocs/cgi-bin/p.cgi line 8.
BEGIN failed--compilation aborted at /home/pistacchio/webapps/htdocs/cgi-bin/p.cgi line 8.

I made sure that Template is installed and indeed when running this program from shell it works (loads Template) and outputs:

Content-Type: text/html; charset=ISO-8859-1

/home/pistacchio/lib/perl5
/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
/home/pistacchio/lib/perl5/lib
/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.8
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.8
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.8/i386-linux-thread-multi
/usr/lib/perl5/5.8.8

Template is installed in /home/pistacchio/lib/perl5/lib/i386-linux-thread-multi

[pistacchio@web118 i386-linux-thread-multi]$ pwd
/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
[pistacchio@web118 i386-linux-thread-multi]$ ls
auto  perllocal.pod  Template  Template.pm

This directory is correctly listed in env and, as previously posted, in @INC. In @INC it is shown twice, so I even tried to pop it out before calling use Template, but without result. From env:

[pistacchio@web118 i386-linux-thread-multi]$ env
[..]
PERL5LIB=/home/pistacchio/lib/perl5:/home/pistacchio/lib/perl5/lib:/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi
[..]

Removing use Template gets rid of the problem.

+4  A: 

I would suggest adding the following to your CGI

  use lib "/home/pistacchio/lib/" ;

The PERL5LIB env variable is presumably not available to CGI programs.

Edit What I meant, any value you have set in PERL5LIB from a shell will not be available.

justintime
hi, thanks for the input, but nothing changed
pistacchio
oh, it working adding use lib "/home/pistacchio/lib/perl5/lib/i386-linux-thread-multi"
pistacchio
The PERL5LIB environment variable is indeed available to CGI programs, it's just not the value you set in your user account.
brian d foy
+2  A: 

The webserver doesn't run as your user, so its environment isn't your user environment. You can set that up in a variety of ways depending on your webserver. In Apache, you can use the SetEnv directive:

 SetEnv PERL5LIB /path/to/your/libs

That then applies to everything under it. If you have it in a .htaccess file, for instance, it applies to everything under that directory.

If you can't do something like that, you're stuck setting the value of @INC in each script yourself with the lib pragma.

brian d foy