All over the year’s i’ve made several perl module distributions. I’ve used a diversity of tools to package the modules and create a cpan ready distribution.

I’ve bumped into several issues with the makefiles and the packaging itself but, for sometime now, i’ve a recipe to create a fully cpan compliant distribuition without any manual editing of the non-code distribution files.

First of all create the skeleton of the distro using Module::Starter

module-starter -mb -module=Foo::Bar --author="your name" --email=your@email

This will create your distro structure in the Foo-Bar directory.
Your code will live in the Foo-Bar/lib dir, and the tests in the Foo-Bar/t

Note: the -mb option tells module-starter to use Module::Build instead of ExtUtils::MakeMaker. This materializes in you ending up with a Build.PL script instead of the traditional Makefile.PL. Just remove -mb option if you want a Makefile.PL but ExtUtils::MakeMaker has some quirks that i personaly don’t like so i use Module::Build

Edit Build.PL file in the Foo-Bar directory, it should be similar to this:


#!/usr/bin/perl

use strict;
use warnings;

use Module::Build;

Module::Build->new(
        module_name => 'Foo::Bar',
        license => 'perl',
        requires => {
                'Other::Module' => '0',
        },
        build_requires => {
                'Test::More' => 0,
        },
        create_makefile_pl => 'traditional',
        sign => 0,
)->create_build_script;

The important bits are the ‘requires’ key, wich states all the depencies for you module and the ‘build_requires’ that states extra dependencies to build the module ( including running the tests you ship with the distro )

You can also sign the distro with pgp (which i recommend), just flip the ‘sign’ value to 1.

Now you just have to create the buld script

$ perl Build.PL

and create the first distribution package

$ ./Build dist 

You should have the Foo-Bar-0.01.tar.gz ready to drop on cpan.