CGIScriptDepot.com
Your source for CGI Scripts, Tutorials, Remotely Hosted Scripts and more...

Home | CGI Scripts | 10 Newest Files | 10 Top Downloads | Suggest a Script |
CGI Script Resources
CGI Script Listings
Newest CGI Scripts
Most Popular CGI Scripts
CGI Script Code Bits
CGI Script Tutorials
Link Partners
 
 
Related Links
Web Hosting
Domain Names

Using Perl Modules in CGI Scripts

We are aware of what functions do in a program. They simply perform a set task that has been logically jotted down while defining them.

A module is basically a collection of functions that perform a set of tasks that work towards a common goal. Again, they are included in the program to save your headache of logically thinking and defining each and every function, especially those that are commonly used in the program.

A perl module is made up of a public interface, a set of variables and functions. While defining the interface from inside the module, you need to initialize certain package variables that the standard Exporter module looks at. If you want to access to the interface from outside the module, then you will be required to import the symbols as a side effect of the “use” statement. The public interface of a Perl module is whatever is documented to be public. In the case of undocumented interfaces, it's whatever is vaguely intended to be public.

Perl modules are classified into 3 categories:

  • Pragmatic modules
  • Library modules
  • Object modules

Pragmatic Modules

A pragma is a compiler directive that provides hints to the compiler. Therefore as significant from the name, a pragmatic module is the one that affects the compilation phase by changing the way a compiler works. They are generally named in lowercase, unlike the names of other types of modules, which begin with an uppercase letter and are of mixed case. They are supported by Perl 5.004 versions and above.

Some of the examples of pragmatic modules are strict, English, integer, vars, etc

Library Modules

As significant from the name, these are composed of a library of functions that have been packed together to perform a given set of task. The reason to pack a complete CGI library into a module is very comprehensible. It simplifies your task, especially when these functions have to be repeated through out the script.

Object Modules

A library module with an object-oriented style of reference can be regarded as an object module. Again they are advantageous when you wish to store the information internally to each piece of data, such as state information, etc.

Installing Perl Modules

You can install perl modules on to your unix or windows environment by following any of the these methods:

  • Go to CPAN (Comprehensive Archive Perl Network), download the required module and install it manually.
  • Use automated methods like CPAN module for Unix or the Perl Package Manager (PPM) for Windows.

The installation of a perl module is a simple four step process involving decompressing, unpacking, building, and installing.

Calling the modules

You can make use of "require" or "use" statements to call a module in to your program. These statements differ in the way they function, that is, a require loads the modules at a run-time. It also keeps a check on the redundancy in loading of the given module. The use statement is similar to the require statement, with an added advantage of compile-time loading and automatic importing. Use statement is employed for giving hints to the compiler because of its compile-time behavior.

Learn More

We maintain a handy list of Perl and CGI Scripting Tutorials that can help get you started creating your own CGI Scripts. Even ifyou are already writing your own CGI Scripts- you might learn a thing or two in our more advanced tutorials.

CGI Script Tutorials