Ken
Ken

Reputation: 636

Can't locate Config.pm in @INC

I have a Perl app on my development server that I would like to replicate on my local machine (mac osx). I'm not a perl programmer by trade (I'm a PHP/Rails developer), and the developer of this app is no longer around so I can't contact him for help. I've gotten pretty close to getting it to work. I was able to install all the packages using CPAN (at least I think I got them all) but I keep running into the following error:

Can't locate WebCNP/Config.pm in @INC (
    @INC contains: /Library/Perl/5.16/darwin-thread-multi-2level 
                   /Library/Perl/5.16 
                   /Network/Library/Perl/5.16/darwin-thread-multi-2level 
                   /Network/Library/Perl/5.16 
                   /Library/Perl/Updates/5.16.2/darwin-thread-multi-2level 
                   /Library/Perl/Updates/5.16.2 
                   /System/Library/Perl/5.16/darwin-thread-multi-2level 
                   /System/Library/Perl/5.16 
                   /System/Library/Perl/Extras/5.16/darwin-thread-multi-2level 
                   /System/Library/Perl/Extras/5.16 .
    ) 
    at webcnp_lib.pl line 30.

On the server, the app's file structure looks like this:

/var/www/cgi-bin (empty dir)
/var/www/conf
/var/www/error
/var/www/html (empty dir)
/var/www/icons
/var/www/perl (the config file is located in this directory)
    - /WebCNP/Config.pm
/var/www/ssi (all the .pl files for the app are located here, including all the JS and CSS files)

Line 30 of /var/www/ssi/webcnp_lib.pl has the following:

use WebCNP::Config;

Any ideas what I could be doing wrong?

Just so you know I've copied the file structure of the app from my development server to my local machine and created a virtual host so that it points to the app's root directory (/var/www).

Thanks in advanced for any insight!

Upvotes: 3

Views: 21448

Answers (4)

user2867849
user2867849

Reputation: 51

Old post, I know, but there is a much more portable way. When you install the modules, you need to do two things.

  1. Add the installation path to PERL5LIB (i.e. PERL5LIB=$PERL5LIB:/My/Module/Path/lib) in your environment configuration (.profile or other files which get read on system initialization)
  2. Add a PREFIX to your perl Makefile.PL call (perl Makefile.PL PREFIX=/My/Module/Path)

It goes without saying that you need to make certain your Makefile.PL is written correctly.

Upvotes: 0

David W.
David W.

Reputation: 107090

was able to fix this with a symbolic link

ln -s /path/to/my/app/WebCNP /Library/Perl/5.16/WebCNP

I take this isn't a module from CPAN.

I would be a bit hesitant to use a symbolic link. This will work, but you're basically linking in a file you have under your own control to the master /Library directory on MacOS X. You delete your file, and that link won't be pointing to anything.

You can use use lib to add directories that contain your modules to the @INC directory:

use lib qw(/path/to/my/app);

This will now include this path for module searches.

If you rather install the module itself, why not simply copy it into /Lbrary/Perl/5.16 itself? It's what cpan would have done. At least this way, you're Perl module directory isn't dependent upon a link that can be removed.

Upvotes: 2

Ken
Ken

Reputation: 636

I was able to fix this with a symbolic link

ln -s /path/to/my/app/WebCNP /Library/Perl/5.16/WebCNP

Not sure if this is the most elegant approach, but seems to work well for this app. Thanks everyone for your replies! This has been very insightful.

Upvotes: 0

ikegami
ikegami

Reputation: 386561

/var/www/perl isn't present in @INC, so Perl won't look there. The most common approach to solve this for CGI scripts would be to add the following to your scripts (but not modules):

use FindBin qw( $RealBin );
use lib "$RealBin/../perl";

Upvotes: 1

Related Questions