What are Perl Modules and Step for Creating Modules

What are Perl Modules and Step for Creating Modules

What are Perl Modules and Step for Creating Modules

Perl modules external link are a set of related functions in a library file. They are specifically designed to be reusable by other modules or programs. A Perl module is a discrete component of software for the Perl programming language. Technically, it is a particular set of conventions for using Perl’s package mechanism that has become universally adopted.

Modules may have dependencies on other modules and cannot be installed without them. Many modules on CPAN now require a recent version of Perl.  Most Perl modules are written in Perl, some use XS (they are written in C) so require a C compiler.

Perl modules are those files that end in .pm. It is common for Perl modules to have embedded documentation in Perl’s Plain Old Documentation format. If you do things right, you can make the process of writing, testing, and installing your module really slick. You’ll also be able to easily bundle up your module for testing and installation on other machines, or uploading to CPAN.

Each Perl module has a name. Module names must be unique. To minimize namespace collisions, Perl provides a hierarchal namespace for modules, similar to the namespace for Java classes.

The following are the steps in creating a module:

Create a place to develop your module  :

The simplest way to do this is to create one directory per module. Give this directory any name that clearly identifies the module that it contains. See the Math::BaseCalc module for a simple example, or the Apache:: Filter modules for a more involved one.

Create skeleton files for your module :

Perl is distributed with a program called h2xs. This program, while initially intended to help programmers implement C extensions to Perl, can also be used to generate skeleton files for a new module.

Document your module

One of the great things about Perl modules is that they can have their documentation right in the same file. Once this module is installed, its documentation can be read by typing “perldoc NewModule” at a Unix prompt. Keeping the code and documentation together is a great thing, since it means you’ll always have the most recent documentation if you’ve got the most recent code.

Write some Perl code

What you’ve got now is a documented, fully functional Perl module that doesn’t do anything. We’ve got to write some code in NewModule.pm to make it do something. This code should implement the interface defined in the documentation w

Write some tests for your code:

One of the benefits of developing modules this way is that you can maintain a list of tests for your code that make sure it’s working properly. This is what the test.pl file is for.

Install the module :

Installation involves copying files into the Perl library directory, which most people don’t have permission to copy into. The general procedure for installing any Perl module is:

perl Makefile.PL
make
make test
make install

Before creating a module first write the documentation for a module before writing any code. Plan the module first, before writing any code. Every module should have a purpose. The Perl standard for module names is that all modules start with a capital letter. Names starting with a lower case letter are reserved for programs.

For Perl Online Training please visit http://www.revanthtechnologies.com