Module::Build tutorial - simplest possible cases

Created: 2010-04-01

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-2010. All rights reserved. For comments, questions, and corrections, please email Ben Bullock/ Privacy/ Disclaimer