Perl Module Features
Designing and Using a Perl Module – Part 1
Foreword: In this part of the series, I give you features of a Perl Module.
By: Chrysanthus Date Published: 2 Apr 2016
Introduction
Pre-Knowledge
At the bottom of this page, you have links to different series you should have read before coming here, to better understand this one.
Meaning of a Module
A module in Perl is a file that has commonly used functions. It can have a few or no variables. The variable types (functions) are coded in a Package. The name of the package is the name of the file. The extension of the filename is .pm . Here, pm, stands for Perl Module. The package name and file name should start with an uppercase letter. The variable types (functions and maybe a few variables) are generally used by many programs written by different developers independently.
Standard Library
Another word for “module” is “library”. The word, library can also mean a set of related modules (i.e. a set of related libraries); at the limit, the modules may have very little relationship between one another. The installation of Perl comes with a very big library. The library is a subdirectory, with sub and sub directories. A related set of modules is found in a subdirectory. If there are many modules in that directory, the more related ones are found in a more sub directory; there is a hierarchy of directories.
In my Windows Operating System the directory for the Perl library is, c:/Perl/lib . The rest of the library subdirectories are in this directory. Many of the modules in this directory can be considered as standard modules, to be used in a standard way by all programmers (developers).
A module is a package. A package is a class. So in a module, you can optionally have instantiated objects and inherited classes. The last expression in a module is just 1 and a semicolon; which means the module returns true (1).
Version
A package should have a version number. Each package has a predefined special version variable to which you can assign the version number. The variable is $VERSION. The version number is a positive number and is typed in quotes, as in "0.01". There should be at least two decimal digits after the decimal point. So you would have a statement like,
$VERSION = "0.01";
in the module. You can use the other version schemes, but I cannot guarantee that they will work with all related software.
Package Types
A package can be created in two ways. You can have a package in blocks or a package in the our scope.
A package (code) as a module is something like:
package pkgName;
our $VERSION = "0.01";
#maybe a few more variables
sub new #optional
{
bless {}, $_[0];
}
sub aFunc
{
//statements
}
# more functions (sub definitions)
1;
Do not forget to end the module with “1;” .
That is it for this part of the series. We stop here and continue in the next part.
Chrys
Related Links
Perl BasicsPerl Data Types
Perl Syntax
Perl References Optimized
Handling Files and Directories in Perl
Perl Function
Perl Package
Perl Object Oriented Programming
Perl Regular Expressions
Perl Operators
Perl Core Number Basics and Testing
Commonly Used Perl Predefined Functions
Line Oriented Operator and Here-doc
Handling Strings in Perl
Using Perl Arrays
Using Perl Hashes
Perl Multi-Dimensional Array
Date and Time in Perl
Perl Scoping
Namespace in Perl
Perl Eval Function
Writing a Perl Command Line Tool
Perl Insecurities and Prevention
Sending Email with Perl
Advanced Course
Miscellaneous Features in Perl
Perl Two-Dimensional Structures
Advanced Perl Regular Expressions
Designing and Using a Perl Module
More Related Links
Perl Mailsend
PurePerl MySQL API
Perl Course - Professional and Advanced
Major in Website Design
Web Development Course
Producing a Pure Perl Library
MySQL Course
NEXT