tags:

views:

291

answers:

8

How do I know what modules are distributed with Perl?

My first guess is that the core modules listed here are always included, though I cannot find this stated explicitly. However, I have used modules outside this set (e.g. LWP) without having to install them on Mac OS X and Linux.

So to refine my question a little:

  • What modules are distributed with all Perl installations?

And: How do I find out what modules have been distributed with:

  • Linux (particularly Debian/Ubuntu)?

  • Mac OS X?

  • Solaris?

In each case I am using the version of Perl that comes standard with the most recent version of the operating system.

TIA.

Update: The reason for the question is that I am developing on Mac OS X and Linux for deployment to different Linux and Solaris, and I don't have root on some of these systems, and in the case of Mac OS X I don't even have a compiler AFAIK. So what I want to know what modules I have available in all four deployments without further installs.

A: 

look in you main symbol table, it will show you all the 'standard' packages available...

print %main::;
ForYourOwnGood
That does *not* show all modules distributed, only those that have been compiled in. Also it shows all kinds of other things.
Leon Timmermans
+12  A: 

If you install Module::CoreList, the command line program corelist can tell you everything about modules and their versions in different versions of perl. The page you linked to gives an overview for the latest version of perl.

Do note that distributions often provide much more by default than this list, but this list can be assumed to be present everywhere (unless it is explicitly a OS dependent module such as Win32).

Leon Timmermans
Although this should be the right answer, in practice vendors do wacky things when they build Perl. We'll need modules like Module::CoreList::Debian and so on :)
brian d foy
A: 

A simple reference for this is in the Appendix D from the Book Beginning Perl. Granted it applies to Perl 5.6 but, to my knowledge, Perl 5.8 did not remove any of these and only introduced new ones (like Digest::MD5, File::Temp, Filter::Simple, libnet, List::Util, Memoize, MIME::Base64, Scalar::Util, Storable, Switch, Test::More, Test::Simple, Text::Balanced, Tie::File, etc.)

For each version of perl you can look in perldoc. here is the list for perl 5.8.8

Pierre-Luc Simard
+7  A: 

Module::CoreList has already been mentioned. It comes with a command-line interface to make things easy. It's great if you have it installed already, or have a program that needs to figure out what may not come with a particular version of Perl.

If you want to know what modules come with your particular version of perl, you can run perldoc perlmodlib on the command line for a complete list. For older or newer versions of Perl, you can just go to Perl's page on the CPAN and select the version you want (eg, 5.6.2) from the drop-down, and then navigate to the perlmodlib page in the documentation. (typing perlmodlib into your browser's text search will help).

If you're thinking of not using a module because it's not core on an older version of Perl, then you may wish to consider using PAR, the Perl Archiver, to bundle your extra dependencies, or even Perl itself! Perl Training Australia also has a Perl Tip on using PAR which covers the basics on getting started with PAR.

All the very best,

Paul

pjf
+7  A: 

The correct straight forward answers have already been given, but I think you've asked the wrong question. You're probably trying to develop using only core modules. Why? You're probably doing this because you don't want to deal with dependencies. Why? Because they can be a pain in the ass. But developing Perl without CPAN is missing half the power. You're crippling yourself. It's worth it.

Update: Now that I know more about what you're trying to do, I can answer the right question. First is "how do I install a module when I don't have root?" The simple answer is this:

perl Makefile.PL PREFIX=/some/path LIB=/some/path/lib
...and all the rest as normal...

for MakeMaker based modules (LIB is used to control the otherwise inexact nature of PREFIX. INSTALL_BASE is preferred, but it is not backwards compatible).

and this for Module::Build

perl Build.PL --install_base=/some/path

and then modules will wind up in /some/path/lib and you can set the PERL5LIB environment variable or use lib qw(/some/path/lib) in your code.

This means you can stick dependent modules straight into your software distribution and ship them. Works fine for pure-Perl modules. For stuff that requires a compiler, look at PAR as others have suggested to be able to ship compiled executables.

Alternatively, you can distribute your stuff as a CPAN module, complete with dependencies spelled out, and let a CPAN client resolve them. You can even use Module::AutoInstall to perform this process outside of a CPAN client.

So you see, you're not restricted to using just core modules when shipping a Perl app.

Schwern
I'll add a little more detail to the question.
Anon Guy
Thanks, now I see what the right question is. :)
Schwern
Thanks, I really want to avoid installing any modules, even locally, if I can help it because it seems more trouble than its worth given the mix of platforms and lack of compiler on one of them (and I don't have much time for this work). So I really do want to use what is installed and/or pure perl.
Anon Guy
False economy. CPAN modules are extremely portable, and you're just using Unixen! There's plenty which are pure Perl. You'll take more time reinventing the wheel, poorly, then figuring out how to install modules. You're going to want CPAN modules for your next project, learning it is an investment.
Schwern
For Schwern's updated answer, there is a lot more information in perlfaq8 :)
brian d foy
As for saving time, re-using known, tested code is the biggest time saver.
brian d foy
Thank you all for your help. I know about CPAN and modules. I use them. IN this case it was more trouble than it is worth, IMO, and a five-minute workaround did the job.
Anon Guy
A: 

This question is a little less important now (I have root access on the eventual target machine so I'll just be installing the packages I need) but in case anyone is interested here's what I did:

First, run this code on each of the target systems:

foreach my $dir (@INC) {
    print "Directory: $dir\n";
    if (-d "$dir") {
        my @modules = `find $dir/ -name "*.pm"`;
        foreach my $m (@modules) {
            my $label = $m;
            $label =~ s|\n$||;
            $label =~ s|//+|/|g;
            $label =~ s|^$dir/||;
            print "$label\n";
        }
    }
}

Note you need a *nix system with a find command. Dump the output into three files, sorted. Then use commands like this (from memory):

grep -F -x -f list-1.txt list2.txt > list-12.txt
grep -F -x -f list-12.txt list3.txt > list-123.txt

Now list-123.txt should have the list of shared modules, more or less.

For what it's worth, all three systems shared a few extra modules, notably the XML::Parser modules.

Anon Guy
That gets a list of modules shared between individual machines, but it doesn't say what comes with Perl. OS vendors add more modules. Sysadmins install more both from packages and from CPAN. You can untangle this, somewhat. Look at the "perl" and "vendor" lib directories. But its so not worth it.
Schwern
A: 

sounds like you want local::lib. All the benifits of cpan without root (and leaves the system perl untouched).

singingfish
+2  A: 

For a quick way to see the modules and versions that you have installed, use the cpan tool to create an autobundle:

 cpan -a

ExtUtils::Installed can help you if you need something more sophisticated.

There used to be the idea of a "standard library", but it doesn't really exist in reality. Module::CoreList tells you what is in the "standard library", but many vendors install additional modules and some even remove or update modules. Additionally, distributions such as Strawberry Perl and ActivePerl come with many bonus modules.

Also, you don't need root to install modules. You only need root to install modules where root can install modules. perlfaq8 gives you all the details for installing modules wherever you like. I recommend that you install all modules outside of the distributed @INC directories so you keep your distributed Perl clean.

Good luck,

brian d foy
I did not use cpan -a (see my own answer being modded down below for the hack I did actually use) I would have if you had replied a month ago, so I'm flagging this as the right answer! Thanks. I was sure there had to be a way, and this will be useful information for the future.
Anon Guy