Module::Build tutorial - simplest possible cases

DISCLAIMER (2010-11-09): I currently do not use Module::Build at all, for reasons which I've outlined at CPAN Ratings. I've switched everything which I do to ExtUtils::MakeMaker. I'm leaving this old page here, part of my abandoned effort to learn the module, in the hope that it's useful for someone. But, since I don't use Module::Build any more, if there's anything on this page which is wrong or misleading, please let me know by email (my address is at the bottom of this page) and I'll take this page down.

To use Module::Build, first create a directory to hold the module. In that directory, create a subdirectory called "lib" and a file called Build.PL. If your module is to be called "MoJo::Joe", as in
use MoJo::Joe;
create a subdirectory of "lib" called "MoJo", and in this directory create a file called "Joe.pm". "Joe.pm" needs to have the following contents:
package MoJo::Joe;

1;
"Build.PL" needs to have the following contents:
use warnings;
use strict;
use Module::Build;
my $build = Module::Build->new
 (
     module_name => "MoJo::Joe",
     dist_version => "none",
 );
$build->create_build_script();

Adding a version

If you add a version string to your module, you can dispense with the "dist_version => none" command here.
package MoJo::Joe;

our $VERSION="0.01";

1;
Module::Build then extracts the version information from the module.
use warnings;
use strict;
use Module::Build;
my $build = Module::Build->new
 (
     module_name => "MoJo::Joe",
 );
$build->create_build_script();

Adding a dependency

If MoJo::Joe depends on another module, for example "Hot::Spice",
package MoJo::Joe;

use Hot::Spice;

our $VERSION="0.01";

1;
you can specify that in your build script,
use warnings;
use strict;
use Module::Build;
my $build = Module::Build->new
 (
     module_name => "MoJo::Joe",
     requires => {
                  Hot::Spice => 0,
              },
 );
$build->create_build_script();
Here the "0" means that no particular version of the "Hot::Spice" module is required.
Copyright © Ben Bullock 2009-2012. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (ben.bullock@lemoda.net) / Privacy / Disclaimer