Packaging a Movable Type plugin with ExtUtils::MakeMaker
While you're just screwing around, it's easy to package a Movable Type plugin by zipping up the directory. However, as you write more advanced plugins with more moving parts, you'll start to have supporting files in your work directory. Hopefully you'll also use a revision control system like Subversion, which may leave files in your directory that you don't want to package up. (I learned this the hard way.)
While you don't need the buffness of the full CPAN packaging chain, you can use ExtUtils::MakeMaker to produce a Makefile that will package your plugin without all the junk. There are a few easy steps:
- Write a
Makefile.PLscript. - Create a
MANIFEST, either manually or automatically withMANIFEST.SKIP. - Whenever you need a package,
make zipdist. Tada!
The first thing you do is write a Makefile.PL script. Here's the MakeMaker tutorial, which shows the smallest possible Makefile.PL. There are many more options to WriteMakefile than NAME and VERSION_FROM, but the vast majority are for building binary modules. One you'll probably use is DISTNAME, which is the stem of the filenames make will give your archives; otherwise your packages will use the CPAN convention of mimicking your primary module name, which is unlikely for an MT plugin.
So your Makefile.PL should look something like this:
use ExtUtils::MakeMaker;
WriteMakefile(
NAME => 'MT::Plugin::OpenIDComment',
VERSION_FROM => 'plugins/openid-comment/openid-comment.pl',
DISTNAME => 'openid-comment',
);
(Note that you'll need to define a $VERSION variable in the file you specify in VERSION_FROM, but you already do that, don't you?)
Running the script with perl Makefile.PL will build you a regular Makefile for use with make. Next you'll write a MANIFEST file to tell make what to package. (The Makefile uses ExtUtils::MakeMaker to read the manifest when you run make.) The manifest is a simple text file listing all the files to package, as shown in the tutorial, so it's easy to write a MANIFEST for small plugins.
However, to always catch new files you add, you can automate the process by using make manifest and a MANIFEST.SKIP file. This is another simple text file, but instead of names of files to include in the package, it contains regular expressions of the files not to include. By default make will skip "things like version control directories and backup files." Because we're building an MT plugin instead of a CPAN module, you don't need to package all the packaging system files, so there are other files you could remove. Try this for a MANIFEST.SKIP:
# version control
\bCVS
(^|/)\.
# CPAN chain files
^MANIFEST
^Makefile
^META.yml$
^blib/
# packages
\.zip$
\.tar\.gz$</code></p></div>
With the MANIFEST.SKIP in place, you can type make manifest to build a MANIFEST file containing all the files in your working directory that don't match one of those expressions.
So with all this configured, whenever you need to package a new version, type:
make zipdist
and bamf, there's a zip file named your-project-1.0.zip, ready to upload! You can use regular make dist to make a tarball instead, if that's your flavor.
CPAN is still the premiere internet module distribution system for open source languages. Years of experience are built into its powerful tools for packaging and distributing Perl code. ExtUtils::MakeMaker is one tool you can use to make your own project management easier on plugins.



2 Comments
The make script may generate a META.yml in your zip file. To avoid generating this file, add a NO_META => 1 WriteMakefile setting in your Make.PL file.
Brilliant idea. btw. I really enjoyed reading all of your posts. It’s interesting to read ideas, and observations from someone else’s point of view… makes you think more. Keep up the good work. Greetings