Scott Wiersdorf
and 1 contributors


Module::Build::Prereq - Verify your Build.PL/Makefile.PL has all the modules you use()


  use Module::Build::Prereq;


  WriteMakefile(CONFIGURE_REQUIRES => {
                  'Module::Build::Prereq' => '0.01' },
                PREREQ_PM => \%prereq_pm);

  # or Module::Build->new(requires => \%prereq_pm)->create_build_script;


Module::Build::Prereq helps you as a developer make sure you've captured all of your dependencies correctly in your Makefile.PL or Build.PL. This module is meant to be used during development or for non-public modules that need to guarantee modules are installed during deployment.

Module::Build::Prereq naïvely crawls through your source files (*.pm by default) looking for 'use ...' statements. It then subtracts any module that is part of Perl's core module list (as determined by Module::CoreList), subtracts any modules you've told it to ignore, skips any modules already in the PREREQ_PM hashref, then warns you about the rest.

What then? Ideally you'd include those modules in your Makefile.PL's PREREQ_PM list (or Build.PL's requires list) or add them to the ignore_modules pattern in assert_modules for the next run.

For more thorough and careful dependency checks (including CPAN lookups) see BDFOY's Module::Release::Prereq, RJBS's Perl::PrereqScanner, and other related modules.


Module::Build::Prereq has one exported function: assert_modules. It takes the following parameters:


Required. This is the same hashref you would supply to WriteMakefile's PREREQ_PM argument:

    my $prereq_pm = { 'Foo' => '1.22',
                      'Bar' => '0.27a' };

    assert_modules(prereq_pm => $prereq_pm);

    WriteMakefile(PREREQ_PM => $prereq_pm, ...);

Optional. A regular expression of module names assert_modules should ignore when looking for missing modules.

    assert_modules(prereq_pm => \%modules,
                   ignore_modules => qr(^(?:Corp::|BigCorp::|InHouse::)));

Optional. A listref of paths to crawl for your *.pm (or see pm_extension) files; by default this is set to lib.

    assert_modules(prereq_pm => \%modules,
                   module_paths => ['lib', 'examples']);

Optional. A regular expression of what your module names look like. By default this is set to /\.[Pp][Mm]$/.

    assert_modules(prereq_pm => \%modules,
                   pm_extension => qr(\.p[ml]$));

If assert_modules finds one or more modules you are use()ing but not found in your Makefile.PL, it will die() saying which modules were not found.


The author uses the following general pattern for deployment in one particular case:

    $ perl Makefile.PL
    $ make
    $ make test
    $ make dist
    (copy tarball to production and install it)

Every now and then someone will add a new dependency via a use() statement in a module but forget to update Makefile.PL with that dependency. When the module rolls out, sometimes the dynamic nature of things allows things to run except for the one module that's missing its dependency.

Module::Build::Prereq is one simple-minded effort to prevent that from happening.


Test::Prereq (BDFOY) for a more thorough way to do this in your module tests rather than at Makefile.PL. Module::Release::Prereq is also by BDFOY and far more throrough than this module. Perl::PrereqScanner (RJBS) is a mature scanner implementation as well.


Scott Wiersdorf, <>


Copyright (C) 2013 by Scott Wiersdorf

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16.3 or, at your option, any later version of Perl 5 you may have available.