[Home]Use modules

HomePage | RecentChanges | Preferences | Newbie Help

CGI FAQs Q: How do I use modules that my web space provider doesn't have or won't install?

Here's a little trick I picked up somewhere. Let's say you want to use a Perl module, for instance MIME::Lite, but your Web space provider doesn't have it installed, and they're not going to install if for you. Note: the module you are going to use can't be dependent on other modules you don't have, otherwise you would have to do this for all the mods. At least I'm pretty sure. I've actually only done this with MIME::Lite, but it stands to reason this would work with other mods. Check the module's docs to see if it has any dependencies.

This works because modules are just Perl scripts with the .pm extension. So, go to [CPAN] and find the mod you want to use. Download the archive to your computer in whatever format makes sense for you (.zip, .tar, .gz). Find the .pm file that comprises the module in the archive. My example is still MIME::Lite. So, the file is Lite.pm. Connect via FTP to your Web space, and go to your cgi-bin. Create a directory in the cgi-bin directory. You could give it any name, but I call mine lib, because I store module libraries in it. chmod the new folder lib to 0755. The phrase MIME::Lite is Perl-ese "the file Lite.pm in the folder MIME." This is true for almost all modules. So, in the new lib folder, create a new folder called MIME and chmod it to 0755. Then in the MIME folder, upload Lite.pm and chmod it to 0755 so the server can run it.

Then, in the Perl script you want to use MIME::Lite in, just do the following:

#!/path/to/perl

use lib "/full/path/to/cgi-bin/lib";
use MIME::Lite;

Voila! use lib pushes/unshifts (I forget which) the location of your lib folder onto the script's @INC array, allowing the script access to all the modules therein. use lib must be the first uncommented line in your script (unless you have a BEGIN section, I suppose).

Good luck, I hope this is helpful! -- Chris Burch


HomePage | RecentChanges | Preferences | Newbie Help
This page is read-only | View other revisions
Last edited February 23, 2001 9:52 pm (diff)
Search:

This FAQ is happily hosted by Betadome Digital Media