Jump to content

Perl module

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Chrisdolan (talk | contribs) at 09:13, 15 March 2004. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A Perl module is a discrete component of software for the Perl programming language. A modulea is distinguished by a unique namespace, e.g. "CGI" or "Net::FTP" or "XML::Parser". By conventions, there is typically one module per file with a .pm extension. A collection of one or more modules, with accompanying documentation and build scripts, compose a package. The Perl community has a sizable library of packages available for search and download via CPAN.

It is common for Perl modules to have embedded documentation. Many modules favor an object-oriented style, but many are procedural instead, especially old modules.

Below is an example of a very simple object-oriented Perl module and a short program which makes use of the module.

Hello/World.pm

 package Hello::World;
 our $VERSION = "1.0";
 sub new {
    my $pkg = shift;
    my $self = bless({
       message => "Hello, world!",
    }, $pkg);
    return $self;
 }
 sub