Perl-Sensitive Sunglasses | |
PerlMonks |
Perl Module administration with CPANPLUSby Juerd (Abbot) |
on Apr 19, 2002 at 23:56 UTC ( [id://160701]=perlmeditation: print w/replies, xml ) | Need Help?? |
I'm not sure why I wrote this. It started with telling a friend about how great CPANPLUS is, but I felt this urge to tell more people about how nice is actually is. CPANPLUS makes installing modules a lot easier.
Perl Module administration with CPANPLUS
IntroductionFor many reasons, Perl is a very powerful language. One of them is the CPAN, the Comprehensive Perl Archive Network, a great repository of Perl-related files. An important role of the CPAN is distribution of Perl modules. Modules are important to Perl, because they prevent needless re-inventing of wheels, and often provide a lot of functionality in just a simple API. Almost every user has installed some Perl modules, and most of the Perl modules are located at the CPAN. Downloading and installing a module is a trivial task, but when it comes to installing multiple modules, you would probably want to spend your time actually using them. When you have to administer more than one machine, it may be handy to automate some tasks. This can be done using the old CPAN.pm, but it has many unpleasant surprises - you may find that it wants to upgrade your perl. I prefer using the new CPANPLUS interface, which doesn't only have a great user interface shell, but also has an easy-to-use back end, which makes it easer for me to automate my tasks. Please note that this simple guide was meant for UNIX readers. Things may or may not work with Windows.
Installing CPANPLUSAs said, installing a single module is a trivial task, and if that enables me to install the other modules a lot faster, I think it's worth the trouble. Of course, you could use CPAN.pm, but since I decided to avoid it, I just grab the latest version of CPANPLUS from KANE's CPAN directory at http://cpan.org/modules/by-authors/id/K/KA/KANE and execute these commands: tar -zvxf CPANPLUS-0.031.tar.gz # at time of writing cd CPANPLUS-0.031 perl Makefile.PL # It asks a lot of questions. I usually hold down <Enter> ;) make make test make install Once CPANPLUS is installed, its shell can be started by using the cpanp executable, or by typing perl -MCPANPLUS -eshell.
Bundles, my wayWhen installing on new machines, I want to have a lot of modules pre-installed, because they just are handy. Of course, I could create a real bundle, but I haven't come round to finding out how to, and I prefer managing a simple text file. #!/usr/bin/perl -w use CPANPLUS; use strict; CPANPLUS::Backend->new( conf => { prereqs => 1 } )->install( modules => [ qw( DBI DBIx::Simple DBD::SQLite LWP ) ] ); The prereqs setting tells CPANPLUS to just install prerequisites, instead of asking about what I want to do. This setting only overrides the configured setting for this script. The list in modules is a qw list (see perlop for more information about it), where I can just add modules when I decide that I want more in my base installation. I keep this file on a site somewhere, accessible via http. With lynx and perl already installed, I can install a lot of modules with a single command! lynx -source http://undisclosed/cpan.pl | perl
MaintenanceModules are improved all the time, and of course, you want to keep your system up to date. The old CPAN.pm can display out-of-date modules, but provides no easy way of upgrading all of them. Fortunately, CPANPLUS can both list and upgrade the modules that need upgrading. The easiest way to do it, is by using the shell. I'll assume the default shell. Start the shell with cpanp or perl -MCPANPLUS -eshell. CPAN Terminal>o The o command lists all old modules that have newer versions in the CPAN. The output of it can have many lines that look like this: 1 1.83 1.89 Text::Balanced DCONWAY At first sight, this may not be much different from CPAN.pm's r command: both show version numbers, module names and the author's CPAN id, CPANPLUS just does it in a nicer way. But the magic becomes clear when you use the i command, which installs modules. The i command can take module names, but can also take search result numbers or ranges of search result numbers. The search result number is the first number in the list. If you have 10 out-dated modules, you will have numbers 1 thru 10. The corresponding range for the i command is 1..10, so you can upgrade them all by just typing i 1..10 (if you have 10 modules that need upgrading). CPAN Terminal>i 1..10
ConclusionCPANPLUS makes my life easier, and although it is relatively new, it is already a lot better than the old CPAN.pm. CPANPLUS has a nice Backend interface that can of course do more than just install a list of modules. I hope that CPANPLUS will completely replace its ugly predecessor soon.
Back to
Meditations
|
|