Michael Carman Michael Carman - 2 years ago 56
Perl Question

Which framework should I use to write modules?

What's the best framework for writing modules -- ExtUtils::MakeMaker (h2xs) or Module::Build?

Answer Source

NOTE This advice is out of date. Module::Build has been removed from the Perl core but lives on as a CPAN module. The pros and cons still stand, and my opinions about MakeMaker still stand.

As the former maintainer of ExtUtils::MakeMaker, I like to recommend Module::Build because MakeMaker is a horror show. Module::Build is so much better put together. But those aren't your concerns and I'll present my "least hassle for you" answer.

Executive Summary:

Because Module::Build support is not 100% in place through all of Perl, start with MakeMaker. If you want to do any customization at all, switch to Module::Build. Since their basic layout, options and interface are almost identical this will be painless. As seductive as it looks, avoid Module::Install.

Fortunately, Module::Build can emulate MakeMaker which helps some, but doesn't help if you're going to do any customization. See Module::Build::Compat.

For CPAN releases using Module::Build is fine. There's enough Module::Build stuff on CPAN now that everyone's dealt with getting it bootstrapped already.

Finally, the new configure_requires option lets CPAN shells know to install Module::Build before they can start building the module. Unfortunately only the latest CPAN shells know about configure_requires.

Oh, whatever you do don't use h2xs (unless you're writing XS code... and even then think about it).

MakeMaker Pros:

  • Comes with Perl and used by the Perl core (therefore it is actively maintained and will remain so forever)
  • Everything knows what to do with a Makefile.PL.
  • Most module authoring documentation will cover MakeMaker.
  • Uses make (those who know make can debug and patch the build process)

MakeMaker Cons:

  • Requires make (think Windows)
  • Difficult to customize
  • Even harder to customize and make cross platform
  • Difficult to debug when something goes wrong (unless you understand make)

Module::Build Pros:

  • Easier to customize/subclass
  • Pure Perl
  • Easier to debug (it's Perl)
  • Can emulate MakeMaker in several ways
  • The CPAN shell will install Module::Build for you

Module::Build Cons:

  • The Module::Build maintainers (and indeed all of the Perl Toolchain Gang) hate it
  • Older versions of CPAN clients (including CPANPLUS) don't know anything about Module::Build.

Module::Install Pros:

  • Slick interface
  • Bundles itself, you have a known version
  • Everything knows how to deal with a Makefile.PL

Module::Install Cons:

  • Requires make
  • Always uses bundled version, vulnerable to external breakage
  • Difficult to customize outside its interface
  • Mucks with the guts of MakeMaker so a new MakeMaker release will eventually break it.
  • Does not know how to generate a META file using the v2 meta-spec (increasingly a problem with newer tools)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download