Saturday, April 28, 2007

Perl Module Installation Woes and Lessons

If you have been programming in Perl for even a short time and have used modules in any of your scripts, then you more than likely have had some experience with installing the modules that you need. When you find out that you now have to learn how to install a Perl module, the first question that enters your mind is..."How?". Well, hopefully, this will help a little.

Thankfully for the lot of us, Perl modules are kept in one standard repository called CPAN(which stands for Comprehensive Perl Archive Network) and is located at You can use the search page on cpan in order to search for Perl modules related to your specific task.

For instance, say you are working with X509 based keys, you could search for X509 modules on CPAN. Funny, but that topic is what led me to write this post. I am working on a script that will examine X509 certificates and parse them for their expiration date, returning the certificates that expire within a certain time frame given by the user.

Upon my first searching for x509 on cpan, I came across the "OpenSSL" module, which includes a number of sub modules for dealing with different aspects of OpenSSL. One specific module is "OpenSSL::X509".

To install a perl module there are typically two routes that you can take:

1. using the command line you issue the command:

perl -MCPAN -e 'install moduleName'

replacing with the name of the module you want to install. In this case it is OpenSSL or OpenSSL::X509 to be more specific.

2. using the cpan interface. To access this, you need to type "cpan" on the command line and hit enter. This will bring you to the cpan prompt where you simply type:

cpan> install moduleName

Please be warned that with both of the above methods, if you have never run either of these, that you will need run through the initial configuration that it brings up in order to use it. The configuration has information in it, but personally, with the exception of a couple of questions, I simply took the defaults.

***Note: I am running on Ubuntu and since a lot of stuff is done using sudo, I typically use sudo at the beginning of either of the two above commands as cpan tends to install things where only Root can create items. So, it is recommended that you use it, unless your installation directory is a place you have full access to.

Now, after the cpan interface is configured, you may be warned to install the Bundle::CPAN module. This is a necessity as it has a number of updates to the different packages it comes standard with, so install it before continuing.

When installing the OpenSSL module, I ran into a whole slew of errors. After looking around for a while and not finding the files it was complaining about, I emailed the Perl Beginners mailing list with the issue to see if they could help. Well, Tom Phoenix was first to respond and informed me that modules below version 1.0 are typically considered pre-releases. That said, the module I was installing was pre-release. Not only that, look at all the documentation of your Perl module you are trying to install. The README of this module was haphazardly written with cursing and did not seem complete. I examined the README at the suggestion of Mumia W on the Perl Beginners mailing list.

All in all, the module is not even close to finished and is completely unusable. So I began a search again and came across Crypt::OpenSSL::X509, written by another author, but, ended up with the same issues and same errors. I believe it may have been written around the other one but is at an even lower version number than OpenSSL.

So, after more research and reading, I came across Crypt::X509. The module looked to be extremely well documented with examples and explanations. Not only that, it was a module specifically for parsing x509 certs. I did the install and there were no issues.

So, my lesson most important bit of advice, before actually installing a Perl module, is to do your research. Read all the associated modules in your search and try to find one that is well documented and also does almost if not exactly what you want to do. Crypt::X509 is only version 0.32, but at least it is fully functional from what I can see ( from the installation). Only coding will tell I guess.

Thanks to Tom Phoenix and Mumia W on Perl Beginners mailling list for all the input on this issue. It really helped guide me to an answer.

If you are a beginner to Perl, I highly recommend that you join the Beginner's mailing list. It is quite a handy resource!!!

No comments:

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 License.