Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I start a new Perl module distribution?

I'm trying to set up a large-ish project, written in Perl. The IBM MakeMaker tutorial has been very helpful so far, but I don't understand how to link all the modules into the main program. In my project root, I have MANIFEST, Makefile.PL, README, a bin directory, and a lib directory. In my bin directory, I have my main script (Main.pl). In the lib directory, I have each of my modules, divided up into their own respective directories (i.e. Utils::Util1 and Utils::Utils2 in the utils directory, etc). In each module directory, there is also a t directory, containing tests

My MANIFEST file has the following:

bin/Main.pl
lib/Utils/Util1.pm
lib/Utils/Util2.pm
lib/Utils/t/Utils1.t
lib/Utils/t/Utils2.t
Makefile.PL
MANIFEST
README

Makefile.PL is the following:

use ExtUtils::MakeMaker;
WriteMakefile(
    'NAME'=>'Foo',
    'VERSION_FROM'=>'bin/Main.pl',
    'PREREQ_PM'=>{
    "XML::Simple"=> 2.18}, #The libraries that we need and their
                   #minimum version numbers
    'EXE_FILES' =>[("bin/Main.pl")]
);

After I make and run, the program crashes, complaining that it cannot find Utils::Util1, and when I run 'make test, it says no tests defined. Can anyone make any suggestions? I have never done a large scale project like this in perl, and I will need to add many more modules

like image 584
Tim Avatar asked Sep 30 '09 01:09

Tim


2 Answers

If you are just starting to create Perl modules (which is also Perl's equivalent of a project), don't use Makemaker. Module::Build is the way to go, and it's now part of the standard library. Makemaker is for us old salts who haven't converted to Module::Build yet. :) I'll strike that now that Module::Build is unmaintained and out of favor; I still use MakeMaker.

You should never start off a Perl project by trying to create the structure yourself. It's too much work and you'll always forget something.

There's h2xs, a program that comes with perl and was supposed to be a tool to convert .h files into Perl's glue language XS. It works fine, but its advantage is that it comes with perl:

% h2xs -AXn Module::Name

Something like Module::Starter is a bit more sophisticated, although you have to get it from CPAN. It's the tool we use in Intermediate Perl because it's simple. It fills in some templates with your information:

% module-starter --author=... --email=... --module=...

If you are doing to do this quite a bit, you might then convert that to Distribution::Cooker so you can customize your files and contents. It's a dinky utility I wrote for myself so I could use my own templates.

% dist_cooker Module::Name

If you're really hard core, you might want Dist::Zilla, but that's more for people who already know what they are doing.

like image 94
brian d foy Avatar answered Sep 24 '22 14:09

brian d foy


Might I also suggest module-starter? It'll automatically create a skeleton project which "Just Works". I learned what little I know about Perl modules organization by reading the generated skeleton files. It's all well-documented, and quite easy to use as a base for growing a larger project in. You can check out the getting-started docs to see what it gives you.

Running module-starter will give you a Perl distribution, consisting of a number of modules (use the command line option --module, such as:

module-starter --distro=Project --module=Project::Module::A,Project::Module::B [...]

to create multiple modules in a single distribution). It's then up to you whether you'd prefer to organize your project as a single distribution consisting of a number of modules working together, or as a number of distributions which can be released separately but which depend on each other (as configured in your Build or Makefile.PL file) to provide a complete system.

like image 33
Gaurav Avatar answered Sep 23 '22 14:09

Gaurav