NAME

ExtUtils::MakeMaker::Tutorial - Writing a module with MakeMaker

SYNOPSIS

use ExtUtils::MakeMaker;

WriteMakefile(
    NAME            => 'Your::Module',
    VERSION_FROM    => 'lib/Your/Module.pm'
);

DESCRIPTION

This is a short tutorial on writing a simple module with MakeMaker.

The Mantra

MakeMaker modules are installed using this simple mantra

perl Makefile.PL
make
make test
make install

There are lots more commands and options, but the above will do it.

The Layout

The basic layout of a module looks something like this.

Makefile.PL
MANIFEST
lib/Your/Module.pm

That's all that's strictly necessary. There's additional files you might want to add:

lib/Your/Other/Module.pm
t/some_test.t
t/some_other_test.t
Changes
README
INSTALL
MANIFEST.SKIP
bin/some_program
Makefile.PL

When you run Makefile.PL, it makes a Makefile. That's the whole point of MakeMaker. The Makefile.PL is a simple module which loads ExtUtils::MakeMaker and runs the WriteMakefile() function with a few simple arguments.

Here's an example of what you need for a simple module:

use ExtUtils::MakeMaker;

WriteMakefile(
    NAME            => 'Your::Module',
    VERSION_FROM    => 'lib/Your/Module.pm'
);

NAME is the top-level namespace of your module. VERSION_FROM is the file which contains the $VERSION variable for the entire distribution. Typically this is the same as your top-level module.

MANIFEST

A simple listing of all the files in your distribution.

Makefile.PL
MANIFEST
lib/Your/Module.pm
lib/

This is the directory where your .pm files go. They are layed out according to namespace. So Foo::Bar is lib/Foo/Bar.pm.

t/

Tests for your modules go here. Each test filename ends with a .t. So t/foo.t. 'make test' will run these tests. The directory is flat, you cannot, for example, have t/foo/bar.t run by 'make test'.

Changes

A log of changes you've made to this module.

README
INSTALL
MANIFEST.SKIP
bin/

SEE ALSO

perlmodstyle gives stylistic help writing a module.

There are modules to help you through the process of writing a module: ExtUtils::ModuleMaker, Module::Setup, CPAN::MakeMaker