Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl Module administration with CPANPLUS

by 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.

The original is a POD document, so I'll just copy pod2html's output here, and escape any square brackets out there :). Hm, yes, let's put a readmore tag right over here.


Perl Module administration with CPANPLUS

Introduction

For 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 CPANPLUS

As 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 way

When 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

Maintenance

Modules 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

Conclusion

CPANPLUS 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.

  • Comment on Perl Module administration with CPANPLUS

Replies are listed 'Best First'.
Re: Perl Module administration with CPANPLUS
by thunders (Priest) on Apr 20, 2002 at 19:44 UTC

    CPANPLUS does work in windows, I have cygwin installed, so i used the programs from cygwin/bin (i.e. tar, wget, gunzip, etc) during configuration, but instead of cygwin make i used nmake, which doesn't use the cygwin .dll, and is more reliable on Windows.

    Many packages install fine, I tried a few of the Crypt-*_PP packages cause I knew that they were Pure Perl and platform independent. All installed were sucessful. You are still limited, of course, by the fact that many CPAN Authors develop *NIX-centric modules.

    CPANPLUS is my second choice after ppm, which works very well but has a somewhat limited/outdated package library.

Re: Perl Module administration with CPANPLUS
by Dog and Pony (Priest) on Apr 20, 2002 at 10:37 UTC
    An excellent account!

    Being partly lazy in a bad way, and partly not having the need as of yet, I haven't tried out CPANPLUS myself yet. I've read about it in perl.com and seen people here and otherwise referring to it as the new, cool way of doing things. Without actually trying it though, I don't really know what that means.

    You give lots of good examples and reasons why I should go install CPANPLUS right away, to at least play with it. I just wanted to say good job, well written and thanks. :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.
Re: Perl Module administration with CPANPLUS
by jplindstrom (Monsignor) on Apr 20, 2002 at 19:04 UTC
    WRT Windows, I can say that CPANPLUS.pm works a lot better than CPAN.pm for some reason. I don't think I ever got CPAN.pm working properly.

    So, the order for me is:

    1. Try PPM. That may or may not work with the Perl version I have. It works sometimes.
    2. Try CPANPLUS. I have VC++ which makes it a nice Unix-like installation experience (for all pure-Perl-modules nmake should be enough). Some modules require other libs which may be have poor support for win32 builds.
    3. Try a manual PPM install. Download the files and install from disk, maybe with some tweaks.

    /J

    Update: Oh, cool! This was my 100th post.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://160701]
Approved by VSarkiss
Front-paged by mdillon
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-25 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found