Section 16.1.  There's More Than One Way To Do It

Table of Contents

16.1. There's More Than One Way To Do It

A distribution contains the module (or collection of related modules), plus all the support files required to document, test, ship, and install the module. While you could potentially construct all these files by hand, it's much simpler to use something to do it for you.

In the beginning,[*] we had to create modules by hand. Soon after, the h2xs program grew into a module distribution creator, and that worked well for a while. Andy Lester created Module::Starter to make a better starter distribution, Jim Keenan created ExtUtils::ModuleMaker to make a better h2xs, and many other module creation systems popped up.[Section 16.1.  Theres More Than One Way To Do It]

[*] Well, since Perl 5 at least, when the third party module system came into being.

[Section 16.1.  Theres More Than One Way To Do It] brian simply creates a template directory he processes with ttree from Template::Toolkit. You can read about it in the December 2004 issue of The Perl Journal at http://www.tpj.com/documents/s=9622/tpj0412e/0412e.html.

No matter which way we create our distribution or which tools we use, the process is the same. We run a Perl script that creates a file that pulls together all the information it needs to prepare and install the code. From there, we can test and install the modules.

If we are using the traditional Makefile.PL, we start the installation with:

$ perl Makefile.PL

After that, we can test and install the module by telling make to perform the actions for those targets.[Section 16.1.  Theres More Than One Way To Do It]

[Section 16.1.  Theres More Than One Way To Do It] We can specify the test and install targets in the same make invocation. If make encounters an error, it won't go on.

$ make all test install

We may not want to use a Makefile.PL, though. It relies on the external program make, which, since it started life as a Unix tool, may not be available on all systems.[§] Ken Williams created the pure-Perl Module::Build system as a make replacement. Since we know that we must already have Perl installed and that Perl is portable, we can use it to install modules.

[§] There is an nmake for Windows that is available from Microsoft.

The Module::Build process looks the same, except that we start with a Build.PL file.

$ perl Build.PL

From there, we do the same sort of thing we did before.

perl Build
perl Build test
perl Build install

There are reasons to decide to use one or the other. The Makefile.PL method has been around for a long time, and it mostly works, except in odd cases. Its underpinnings depend on ExtUtils::Makemaker, which comes with Perl. Unfortunately, ExtUtils::Makemaker has become a bear to maintain, since it has to handle all of the special cases for the many, many systems on which Perl works. The Module::Build method is much newer, so it's still maturing and not as many people use it.[*] However, since Module::Build doesn't require an external program, it's easier for some people to use.

[*] Yet. Module::Build will be part of the Perl standard distribution starting with Perl 5.10 and is likely the future for Perl modules.

Table of Contents
© 2000- NIV