Ali.as

What is CPAN?

"CPAN" is the abbreviation for "comprehensive Perl archive network". It has been called many names - for some it is "the killer application" of Perl, for others its soul. CPAN is a central place where extensions for Perl are collected. Because of Perl's flexibility, these extensions concern both linguistic expressiveness and functionality.

Extension of the linguistic expression possibilities

What do I mean by this? You can extend the language expression capabilities yourself within certain limits. For example, exceptions in Perl work basically the same as in other languages, it just looks different. If you want to use the look and feel of other languages in Perl, you can extend Perl with the module Try::Tiny. Without this module you throw an exception with the function "the" and get it exception in a variable. So exceptions look like a function call and a variable comparison. The formulation with "try" and "catch" is not possible without this module. So if you use this module, you extend your expression possibility with it.

Extending the functionality

From other languages you probably already know this possibility of extension. In fact, this is probably the reason why every developer uses extensions: Others have already developed something, and you want to use that to make your programs do more faster and be more powerful.

CPAN lives from participation

Everybody can download these extensions for free and extend his Perl with them. It also works the other way around: anyone can publish their code here and make it available to other developers. Technically, authors publish an archive of files here and provide it with a version number. The files contained in the archive then form the content of the module. The version number is used to indicate a different stage of development of the module.

How can I use it?

There are two use cases for CPAN, which I want to show here: searching and installing modules.

How can I search for a module?

The MetaCPAN page is your gateway to CPAN. How about searching there for Try::Tiny? Browse there a bit, I'm waiting so long. Well, how was it? I guess you scrolled a bit through the documentation and tried some of the many links. And then maybe you were a bit overwhelmed by the wealth of information and came back here. Each overview page for a module is packed with links that show you the different aspects: its documentation (the main section in the middle), something about the author (top left and right), what platforms the module works on (the "Testers" link on the left, and of course the contents of the archive ("Browse").

How can I install a module?

When you have found a module you want to use, you have to install it. The best way to do this is to use "cpanm". Let's install the module "Try::Tiny" I just showed you something about. The first line tells you which module is currently being worked on.

The second line tells you where the module is being fetched from. You can see from the URL that the author's name is "ETHER" and that the module was found in version 0.28. If you searched for this module on MetaCPAN while I was waiting, you will know this information - it was displayed there. Line three tells you that the module is being configured. This step lays the groundwork for the module to be installed and then for you to use it. What exactly happens there depends on the module; for example, this is where you tell the module where to install it.
The next step is to build the module. This is then followed by running the automated tests. If no errors are found here, "cpanm" installs the module. From now on you can use it. If the module was installed, then you should now have "caught" output. The first line tells you that the module could not be found. The long list of directories at the end of the line tells you where perl looked for the module. (This output will typically wrap your shell, so some directory names may be chopped up).

If a module could not be found, this is usually due to the following reasons: The module is not installed at all; the module is installed in such a way that perl cannot find it; or the name of the module is misspelled.

Summary

There it was in a nutshell about the CPAN. I described to you what it is and explained the two most common use cases. How to search for a module and how to install it. Have fun browsing!



Content copyright 2002 Ali.as
All rights reserved.