Contributed by Dengue on from the more-of-the-old-content dept.
The CPAN module can be obtained ironically enough from CPAN . I find Perl to be still a bit of a black art, though I confess to being seduced by the same darkness that confounds me. Since I use a lot of perl (I just don't write a lot of perl) I often need to install perl modules of one ilk or another to get scripts to work. I have found a true saviour in the CPAN module. For those who are unfamiliar with perl's CPAN module, in a nutshell, it provides a command-shell type of interface to automate the installation and updating of perl modules. By issuing a command as simple as Install Bundle::libnet you can automagically download and install all of the libnet associated perl modules. It's really that easy, and consequently perfect for a perl agnostic such as myself. No more digging through Perl's rather arcanely organized module libraries to find the right module to download and install, instead I'll just tell perl what I want and let it do the rest. I've used the CPAN module pretty extensively under Linux (RedHat & Mandrake) to keep my perl installations up to date and wanted the same functionality from my OpenBSD systems. OpenBSD 2.5 ships with Perl 5.004 installed as a standard part of the OS (what OS doesn't include perl?), so from the start, we are nearly there. The first place to start obviously is by downloading the CPAN module itself from one of the module mirrors. I choose to get the tarball from Perl.com's site, though you should choose a geographically close mirror. As popular as Perl is, the main distribution sites can be frequently quite busy. Once the CPAN tarball is downloaded you will find that Perl 5.004 is missing a key module that the CPAN module depends on (evidence of perl's dark heart, modules depending on modules...) so it's back to Perl.com to get the File::Spec.pm module. This module is a part of Perl 5.005, so users of 2.6 shouldn't have to go get this. It is always recommended that you untar sources as your normal user account and not as root , and I prefer to do it in a subdirectory of my home directory (~/src). When you untar files as root, you can blow away files by mistake very easily.
Installing perl modules is pretty trivial even without cpan , involving merely three simple commands: perl Makefile.PL which generates the Makefile for the module, and the commonplace make and make install will finish the installation and register the modules with perl. Once you have the File::Spec module installed you can get started installing CPAN.
The CPAN modules installation varies slightly from other modules because of the extensive configuration required to make the module work correctly. Since you will need to run cpan as root to install the modules, I recommend you run perl Makefile.PL as root, since it will ask some user specific intallation questions such as where to cache files, etc. Pay attention to the configuration questions asked, especially when you pick the sites you want to use to grab your source files. For most questions, the defaults will suffice, though I did choose to have cpan use gtar which I had installed from the ports tree instead of the default tar . Once the lengthly configuration questions have been answered, installation is as straightforward as with other perl modules, simply make , and make install . Once installed, the fun really begins. To start cpan simply type: cpan . This will drop you into an interactive shell similar to csh , which is to say, unfamiliar to bash lusers such as myself. Oh well, nothing's perfect. Typing help at the resultant prompt will explain your options.
[root@ulysses dengue]# cpan cpan shell -- CPAN exploration and modules installation (v1.50) ReadLine support available (try ``install Bundle::CPAN'') cpan> help command arguments description a string authors b or display bundles d /regex/ info distributions m or about modules i none anything of above r as reinstall recommendations u above uninstalled distributions See manpage for autobundle, recompile, force, look, etc. make make test modules, make test (implies make) install dists, bundles, make install (implies test) clean "r" or "u" make clean readme display the README file reload index|cpan load most recent indices/CPAN.pm h or ? display this menu o various set and query options ! perl-code eval a perl command q quit the shell subroutine cpan>
As you can see, cpan is pretty easy to use. For instance, the command b will automagically fetch the file listing and display all of the bundles available from the CPAN archive. Correspondingly, m will list all of the individual modules available, which by the sheer number of modules available is of dubious value. Since it is perl we're dealing with here, all of perl's exceptional regex power is available to cpan and instead of wading through an incomprehensively large list of modules, you can narrow the search with the appropriate regular expression. To show all modules that might contain MD5 in their names, you can use something like this:
cpan> m /[m,M][d,D]5/ Module Authen::SASL::CRAM_MD5 (GBARR/perl-ldap-0.13.tar.gz) Module Crypt::HCE_MD5 (E/EE/EESTABROO/Crypt-HCE_MD5-0.45.tar.gz) Module Crypt::PasswdMD5 (L/LU/LUISMUNOZ/Crypt-PasswdMD5-0.1.tar.gz) Module Digest (GAAS/Digest-MD5-2.09.tar.gz) Module Digest::HMAC (GAAS/Digest-MD5-2.09.tar.gz) Module Digest::HMAC_MD5 (GAAS/Digest-MD5-2.09.tar.gz) Module Digest::HMAC_SHA1 (GAAS/Digest-MD5-2.09.tar.gz) Module Digest::MD2 (GAAS/Digest-MD5-2.09.tar.gz) Module Digest::MD5 (GAAS/Digest-MD5-2.09.tar.gz) Module Digest::SHA1 (GAAS/Digest-MD5-2.09.tar.gz) Module MD5 (GAAS/Digest-MD5-2.09.tar.gz) Module SHA (GAAS/Digest-MD5-2.09.tar.gz)
To install the MD5 module, you would simply type install MD5 . Cpan will automagically check dependencies and download the appropriate files from the ftp mirrors you have choosen during the configuration stage.
As a tool for automated software installation and maintenence, it is hard to beat the ease and versitility of cpan .
(Comments are closed)