CPAN

From LQWiki
Jump to: navigation, search

CPAN is an acronym for Comprehensive Perl Archive Network.

The CPAN houses a very large collection of Perl modules which you can use in your own programs. Most CPAN module distributions are available under the same licensing terms as Perl itself (or else the GPL). The name "CPAN" refers to both the online module archive, and also a core module included with Perl which helps you interact with the CPAN. When someone says "the CPAN", they're talking about the online module archive.

It's probably most common to use the CPAN module like this:

# perl -mCPAN -e CPAN::shell
cpan> install Foo::Bar

e.g.

cpan> install Math::XOR

You'll run that as root if your Perl is installed in a system-wide location. The first time you run that first command, you'll be prompted a number of questions to initially configure the module. For most of them, you just hit ENTER to accept the default.

Note, if you're running Debian and using it's stock Perl, you probably do not want to use the CPAN, since Perl modules on Debian are generally installed via apt-get instead of the CPAN shell.

Usecase

If you run a perl program and get the error message

Can't locate Net/DAV/Server.pm in @INC (@INC contains: /usr/lib/perl5/5.8.8/x86_
64-linux-thread-multi /usr/lib/perl5/5.8.8 /usr/lib/perl5/site_perl/5.8.8/x86_64
-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr
/lib/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_per
l/5.8.8 /usr/lib/perl5/vendor_perl .) at ./__webdav.pl line 14.
BEGIN failed--compilation aborted at ./__webdav.pl line 14.

You see it's time to install Net::Dav::Server.

# perl -mCPAN -e CPAN::shell
cpan> install Net::Dav::Server

See also