Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

BooK (2612)

BooK
  {book} {at} {cpan.org}
http://paris.mongueurs.net/
Yahoo! ID: philippe_bruhat (Add User, Send Message)

Obfuscation [plover.com]. Pink [axis-of-aevil.net]. HTTP::Proxy [cpan.org]. YEF [yapceurope.org]. Fishnet [perl.org]. Kapow [cpan.org]. Cog's [perl.org] bitch [cpan.org]. Invitation [perl.org]. White [perl.org] Camel [perl.org]. Nuff' said.

Journal of BooK (2612)

Wednesday October 16, 2002
09:09 AM

PREREQ_PM

[ #8403 ]

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).

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If using a regex to find all the use()d modules makes you feel dirty there's a snippet [perlmonks.org] over at PerlMonks that sticks a coderef in @INC to do the magic for you.

    --

    broquaint out

    • 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.

  • ...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.