There are two styles you can use for Perl modules. Both are useful under different circumstances.
In the `exporting' style, the `module file' defines some functions which you can load into your program and use as if you had defined them yourself.
In the `object oriented' style, your module defines a `class' that knows how to construct `objects' that perform actions on behalf of the program when their methods are invoked.
You should visit the Module directory first. It has an extremely simple module, an example program that uses it, and a list of exercises. You should do all the exercises. When you are done you will know how to write a module in the `module' style. The examples are complete, but they are so simple that they will both fit on the screen at the same time. Together they are eighteen lines long.
Then you should move to the Class directory, which has an extremely simple object-oriented module, a sample program, and a list of exercises. Do the exercsises. When you're done you will know how to write a module in the `object oriented' style. The example is a complete object-oriented program that creates an object and calls a method on it. It is a little longer than the other example. It is thirty-nine lines long. Fourteen of the lines are blank.
There is also a third part, in the Inherit directory. It shows how Perl does method inheritance in object-oriented classes. You should do the exercises there last.
The module-tutorial.tar.gz and module-tutorial.zip files contain everything from all three directories.
Best of luck.
Author: M-J. Dominus
With useful suggestions and improvements from: