PREREQ_PM

BooK on 2002-10-16T14:09:07

Like every CPAN author did probably once, I just released a project with an incomplete PREREQ_PM parameter in Makefile.PL.

I've read brian d foy's journal entries Finding Prerequisites and Finding Prerequisites II, but still produced a very simple script to help write a correct PREREQ_PM

Here it is:

#!/usr/bin/perl -w
# $Id: prereq,v 1.1 2002/10/16 13:55:33 book Exp $
use strict;
use Module::Info;
use Getopt::Long;

# configure @INC
my @lib;
Getopt::Long::Configure("bundling_override");
GetOptions ("I=s" => \@lib);
push @INC, @lib;

# the list of tested files
my %prereq;
my $modules = join '|',
  sort map { s!/!::!g; s/\.pm$//; quotemeta; } @{ [@ARGV] };

# look for simple 'use' strings
while (<>) {
    next if not /^use ([\w:]+)/;
    my $name = $1;
    my $module = Module::Info->new_from_module($name);
    die "$name is not in your \@INC!\n" if not defined $module;
    $prereq{$name}++ unless $name =~ /$modules/o or $module->is_core;
}

# print the modules
local $\ = $, = $/;
print keys %prereq;

It's biggest shortcoming is that it looks for modules with /^use ([\w:]+)/, so it's not very bright.

But it can be called from your working directory, and "use" modules you develop but haven't installed yet, thanks to the -I option (works just like perl's -I).

$ prereq -Iblib/lib HeavensAbove.pm t/*.t
LWP::UserAgent
HTML::TreeBuilder
HTML::Form
Test::More

Good enough for my needs (and my coding style).


Dependencies without the regex

broquaint on 2002-10-16T16:27:19

If using a regex to find all the use()d modules makes you feel dirty there's a snippet over at PerlMonks that sticks a coderef in @INC to do the magic for you.

Re:Dependencies without the regex

BooK on 2002-10-16T17:02:39

Ooh. A coderef in @INC. Nice stuff.

Well, I've just tested it, and it's far too verbose for my needs, since it lists every module that ever gets used. Module::Info could help by filtering out the core modules, but many modules in the same distribution will be listed.

By the way, the script that I posted has a few problems filtering some modules from the list.

Why not...

jhi on 2002-10-16T17:21:06

...instead have pristine copies (that is, non-installed-upon) of Perls (5.8.0, 5.6.0, 5.6.1, 5.005_03, 5.004_05) available and then just run Makefile.PL and make test with those? That should find assumptions about installed modules pretty quickly and also allow backward compatibility testing.