Test::Prereq(3pm)
π Test::Prereq β the "bestie, is your Makefile.PL lying to you?" check π
okay so this is a Perl module page, Test::Prereq(3pm), and it's about one very specific flavor of chaos: making sure the pre-requisites in your Makefile.PL are actually, you know, correct. β¨
β¨ NAME β¨
Test::Prereq β check if Makefile.PL has the right pre-requisites. that's it. that's the whole job. π
πΈ SYNOPSIS πΈ
if you're a Makefile.PL girlie:
# if you use Makefile.PL
use Test::More;
eval "use Test::Prereq";
plan skip_all => "Test::Prereq required to test dependencies" if $@;
prereq_ok();
if you're a Module::Build girlie instead:
# if you use Module::Build
use Test::More;
eval "use Test::Prereq::Build";
plan skip_all => "Test::Prereq::Build required to test dependencies" if $@;
prereq_ok();
or, like, straight from the command line for a one-off vibe check:
# or from the command line for a one-off check
perl -MTest::Prereq -eprereq_ok
π«Ά real talk: the prerequisites test takes quite some time, so this next construct is what's recommended for non-author testers:
#The prerequisites test take quite some time so the following construct is
#recommended for non-author testers
use Test::More;
eval "use Test::Prereq::Build";
my $msg;
if ($@) {
$msg = 'Test::Prereq::Build required to test dependencies';
} elsif (not $ENV{TEST_AUTHOR}) {
$msg = 'Author test. Set $ENV{TEST_AUTHOR} to a true value to run.';
}
plan skip_all => $msg if $msg;
prereq_ok();
π¦ DESCRIPTION π¦
so the prereq_ok() function goes snooping through the modules it finds in blib/lib/, blib/script, and the test files it finds in t/ (plus test.pl). then it works out which modules those actually use and compares that whole list against the ones sitting in the "PREREQ_PM" section of Makefile.PL. it's giving detective energy π
if you're on "Module::Build" instead, go look at Test::Prereq::Build instead. different girl, same mission. π
β οΈ Warning about redefining ExtUtils::MakeMaker::WriteMakefile β οΈ
"Test::Prereq" has its own version of "ExtUtils::MakeMaker::WriteMakefile", and the reason is so it can actually run the Makefile.PL and grab the argument list of that function. so yeah β you may see warnings about this. not a bug, just the price of knowing things. π
π₯ FUNCTIONS π₯
prereq_ok( [ NAME [, SKIP_ARRAY] ] )β testsMakefile.PLto make sure all the non-core module dependencies are in"PREREQ_PM". and if you haven't set a testing plan already,prereq_ok()makes one for you β a plan of one test. cute, efficient, slay.
the valid versions come from "Module::CoreList" (which uses $]):
#!/usr/bin/perl
use Module::CoreList;
print map "$_\n", sort keys %Module::CoreList::version;
"prereq_ok" also tries to remove modules it found in lib/ and libraries it found in t/ from the reported prerequisites. because duh, those aren't real prereqs. π
the optional third argument is an array reference β a list of names that "prereq_ok" should ignore. you'd want this if your tests do funny things with "require". and yeah, "funny things" is doing a lot of work in that sentence, we all know.
ok so history lesson: versions prior to 1.038 would use CPAN.pm to virtually include prerequisites in distributions that you declared explicitly. and ngl, that isn't really a good idea. some modules have moved to different distributions, so you should just specify all the modules that you use instead of relying on a particular distribution to provide them. not only that β expanding distributions with CPAN.pm takes forever. like, forever forever. π
if you genuinely want that old behavior back, set the "TEST_PREREQ_EXPAND_WITH_CPAN" environment variable to a true value. you do you bestie π«Ά
π TO DO π
- set up a couple fake module distributions to test
- warn about things that show up in
"PREREQ_PM"unnecessarily
(the audacity of unnecessary PREREQ_PM entries, honestly. not on our watch. π
)
π SOURCE AVAILABILITY π
the source lives in Github:
http://github.com/briandfoy/test-prereq
π CONTRIBUTORS π
many thanks to:
Andy Lester, Slavin ReziΔ, Randal Schwartz, Iain Truskett, Dylan Martin
icons, all of them. π
π AUTHOR π
brian d foy, "<briandfoy@pobox.com>"
π COPYRIGHT and LICENSE π
Copyright Β© 2002-2025, brian d foy <briandfoy@pobox.com>. All rights reserved. This software is available under the Artistic License 2.
and that's the whole page bestie β this one's from perl v5.40.0, dated 2025-01-11, and it's Test::Prereq(3pm). go forth and make your PREREQ_PM honest β¨π¦π
π¦ where this page comes from
- debian trixie: libtest-prereq-perl 2.005-1 Β· Artistic-2.0
- ubuntu resolute: libtest-prereq-perl 2.005-1 Β· Artistic-2.0
- ubuntu stonking: libtest-prereq-perl 2.005-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms