[Previous] [Contents] [Next]


Modules and Extensions: Purpose and Design

Version 5 of Perl implements the module as the standardized means for extending its functionality. A Perl module is very much like a Perl library in that it provides the user with a set of functions or variables, within a separate namespace known as a Perl package. The purpose of these functions or variables is to simplify and standardize the implementation of a given task or tasks.

Modules can be much more powerful and useful than the old-style Perl libraries, however. First, they can now be implemented as a shared library and thus, on many platforms, eliminate the need for a separate, statically linked Perl executable for each external API that is desired as a Perl extension. Second, they can be implemented to provide an interface for use in the new, object-oriented way. Extension Modules: Modules That Interface to External APIs A Perl5 module provides the implementor with the means, through the use of XSUBs, to compile C code that "wraps" or "glues" the functionality of an API into a shared library that can be loaded by Perl at runtime. After Perl loads the shared library, through a use or require statement, the glue code enables the end user to call the API's functions from within the Perl program, passing Perl data types in and out. This capability is one of the most powerful and useful new features in Perl5.

Note:

Not all architectures support shared libraries. Many do, but on the ones that don't, you must still link the API libraries with Perl to produce a Perl executable that provides the interface to the API.


Modules: The Object-Oriented Way Another purpose of modules, briefly demonstrated and discussed previously, is to provide the ability to use them combined with Perl references to create object-oriented programs. You'll see and use the object-oriented features of modules extensively in this book to implement the examples and demonstrate the techniques that we consider to be the most up-to-date and cutting-edge for Web programming.

In the next section, you'll take a brief look at the general form of a module.

[Previous] [Contents] [Next]