You are here

CPAN

Error message

Deprecated function: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in drupal_strip_dangerous_protocols() (line 1458 of /home2/crephoto/public_html/techblog/includes/common.inc).

An acronym for Comprehensive Perl Archive Network, CPAN maintains a huge library of perl modules and provides semi-automated access to them.

The first time I across CPAN was when I was working on a method of updating a URL containing a redirect request to send visitors to a web site hosted on a server with a dynamic IP address. (Yes, I'm aware of dyndns.com and its kin). Since then I've installed a number of CPAN modules. But now I need to install them on a server for which I have a shell account, but no root access. Here are the details of that process.

First, I followed these instructions on installing CPAN on a system when you don't have root access.

I logged into my shell account with the ssh utility, then downloaded MyConfig.pm with the following command:

user$ cd ~/.cpan/CPAN
user$ curl http://sial.org/howto/perl/life-with-cpan/MyConfig.pm -o MyConfig.pm

I suppose if I were a real perl geek, I would use the wget command. Next I followed the instructions for modifying the MyConfig.pm, and moved it to the appropriate location ~/.cpan/CPAN/MyConfig.pm. I changed the HOMEDIRFIX variable and paths to "tar" and "gzip" Then I checked the syntax with:


$ ~/.cpan/CPAN$ perl -c MyConfig.pm
MyConfig.pm syntax OK

Since I received the "syntax OK" message, I tried to install CPAN:


$ perl -MCPAN -e '$ENV{FTP_PASSIVE} = 1; install CPAN'

This appeared to succeed, so I loaded cpan and was pleased to see the cpan> prompt

From here, I went on to install whatever CPAN modules I needed.

Mac OS X Caveats

The default filesystem on Mac OS X (HFS+) folds case unlike traditional Unix filesystems; this can cause problems for Unix systems that assume File and file are two different things. For example, the LWP::UserAgent module installs /usr/bin/HEAD, which clobbers the existing /usr/bin/head utility. Solutions to this include not installing the HEAD and similar shortcuts, or ensuring these utilities are installed under /usr/local/bin instead. One way is to update the perl Makefile.PL arguments to install third-party utilities into a different directory than /usr/bin.


cpan> o conf makepl_arg "INSTALLBIN=/usr/local/bin INSTALLSCRIPT=/usr/local/bin"
cpan> o conf commit

Panther and /man

Perl 5.8.1 on Mac OS X 10.3 ships with broken settings that cause some modules installed from CPAN to install their manuals under the /man directory. This directory pollutes the root namespace, and is outside the places manuals are searched for by man(1).

To fix this problem, update the makepl_arg to set INSTALLSITEMAN1DIR and INSTALLSITEMAN3DIR manually.


$ grep makepl_arg /System/Library/Perl/5.8.1/CPAN/Config.pm
'makepl_arg' => q[INSTALLSITEMAN1DIR=/usr/share/man/man1 INSTALLSITEMAN3DIR=/usr/share/man/man3]

I discovered another problem when installing cpan modules as root using "sudo". CPAN uses configuration files from the HOME folder. The files under .cpan get created with root ownership & permssions set to disallow access from the user who "owns" the home directory. Adding the "-H" option to the sudo command takes care of this by temporarily setting the HOME directory to that of root.


$ sudo -H cpan -i CGI::Application