Test-Prereq-1.038/000755 000765 000024 00000000000 12261275120 014134 5ustar00brianstaff000000 000000 Test-Prereq-1.038/Changes000644 000765 000024 00000005771 12261275117 015447 0ustar00brianstaff000000 000000 1.037 - Mon Jun 1 00:20:54 2009 * Fix #46335: qualify calls to find() so Module::Install doesn't intercept them. 1.38 - Thu Jan 2 15:38:44 2014 * Use Makefile.PL instead of Build.PL since Module::Build is likely to be deprecated * Fix up Pod encoding issues 1.035 - Sat Aug 2 23:24:14 2008 * Cleaning up the Makefile a bit. No need to upgrade. 1.034 - Sat Jul 12 21:32:16 2008 * Various minor cleanups. No big whoop. 1.033 - Fri Mar 16 23:00:57 2007 * Fixed load test to not complain when trying to import the same symbol twice * No code fixes otherwise. No need to upgrade. 1.032 - Tue Jan 9 22:54:40 2007 * updated copyright and license info * no code changes, so no need to upgrade 1.031 - Wed May 17 22:23:23 2006 * updates to distro and kwalitee. No need to upgrade 1.030 - Wed May 17 22:15:01 2006 * Updates to distro and kwalitee. No need to upgrade. 1.030 - Wed Jan 11 00:11:21 2006 * Tests should now work even if there is nothing in PREREQ_PM. In the previous version, an empty PREREQ_PM made the module think Makefile.PL didn't exit cleanly. * Everyone should upgrade. 1.029 - Sun Dec 25 20:03:47 2005 * Updated some tests that had some problems. No need to upgrade. 1.028 - Wed Jul 13 17:31:13 2005 * Simple doc fixes. No need to upgrade. 1.027 - Tue Mar 8 00:18:28 2005 * fixed up the bits that deal with the plan, to make things consistent. prereq_ok will create the plan if it doesn't exist, or leave it alone if it does. * You don't need to use Test::More (and you didn't need to previously, despite the docs) 1.026 - Fri Mar 4 08:09:41 2005 * Documentation fix for command line invocation: Test::Prereq calls plan() for you, so you don't have to. 1.025 - Wed Sep 8 00:59:57 2004 * get rid of the 'redefine' warning when we read the Makefile.PL 1.024 - Tue Sep 7 19:52:30 2004 * cleaned up distro * bumped version to a full release (the interface is pretty much set) * no need to upgrade really (although some modules might require a version number above 1.x 0.23 - Tue Aug 24 19:58:53 2004 * Changed a few things for demo talk 0.23 - Fri Feb 20 05:42:18 2004 * got rid of the File::Find::Rule dependency 0.19 - Fri Dec 20 16:18:39 2002 * stripped bad whitespace from Pod, no code changes 0.18 Mon Nov 4 19:25:56 CST 2002 - skip CPANPLUS modules by default. still haven't figured this out. 0.17 Wed Oct 23 11:55:28 CDT 2002 - removed extra call to CPAN.pm. this should make things run faster. 0.16 Fri Oct 11 03:46:12 CDT 2002 - add MAN3PODS to WriteMakefile to make man pages show up in the right place 0.15 Thu Oct 10 19:34:20 CDT 2002 - more changes to get around CPANPLUS 0.14 Thu Oct 10 17:19:27 CDT 2002 - test suite gives better error output (so i can figure out what's up with CPANPLUS) 0.13 Wed Oct 9 19:37:47 EDT 2002 - expands distributions in PREREQ_PM to look for modules implicitly declared 0.10 Fri Oct 4 18:27:57 CDT 2002 - added support for Module::Build 0.07 Mon Sep 30 00:53:19 PDT 2002 - cleaned up Makefile.PL for perl5.8.0 weirdness Test-Prereq-1.038/examples/000755 000765 000024 00000000000 12261275120 015752 5ustar00brianstaff000000 000000 Test-Prereq-1.038/lib/000755 000765 000024 00000000000 12261275120 014702 5ustar00brianstaff000000 000000 Test-Prereq-1.038/LICENSE000644 000765 000024 00000000075 12261275117 015151 0ustar00brianstaff000000 000000 You can use Test::Prereq under the same terms as Perl itself.Test-Prereq-1.038/Makefile.PL000644 000765 000024 00000001653 12261275117 016121 0ustar00brianstaff000000 000000 use ExtUtils::MakeMaker 6.55; require 5.008; eval "use Test::Manifest 1.21"; WriteMakefile( 'NAME' => 'Test::Prereq', 'ABSTRACT' => 'Ensure a build file lists all pre-requisites', 'VERSION_FROM' => 'lib/Test/Prereq.pm', 'LICENSE' => 'perl', 'AUTHOR' => 'brian d foy ', 'NORECURS' => 1, 'BUILD_REQUIRES' => { 'ExtUtils::MakeMaker' => '6.55', }, 'TEST_REQUIRES' => { 'Test::Builder' => '0', 'Test::Builder::Tester' => '0', 'Test::More' => '0.95', }, 'PREREQ_PM' => { 'Module::CoreList' => '0', 'Module::Info' => '0', }, 'clean' => { FILES => 'Test-Prereq-*' }, 'META_MERGE' => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'git@github.com:briandfoy/test-prereq.git', web => 'https://github.com/briandfoy/test-prereq', }, }, }, ); Test-Prereq-1.038/MANIFEST000644 000765 000024 00000001014 12261275120 015261 0ustar00brianstaff000000 000000 Changes examples/README lib/Test/Prereq.pm lib/Test/Prereq/Build.pm LICENSE Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml README t/get_from_file.t t/get_from_prereqs.t t/get_loaded_modules.t t/get_prereqs.t t/import.t t/load.t t/pod.t t/pod_coverage.t t/prereq_ok.t t/prior_plan.t t/test_manifest testdir/bad_makefile/Makefile.PL testdir/build_pl/Build.PL testdir/good_makefile/Makefile.PL testdir/good_makefile/MANIFEST META.json Module JSON meta-data (added by MakeMaker) Test-Prereq-1.038/MANIFEST.SKIP000644 000765 000024 00000002045 12261275117 016041 0ustar00brianstaff000000 000000 #!start included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. #!end included /usr/local/perls/perl-5.18.1/lib/5.18.1/ExtUtils/MANIFEST.SKIP \.travis\.yml \.releaserc \.cvsignore \.lwpcookies hacks/ .*MYMETA.* Test-.* Test-Prereq-1.038/META.json000664 000765 000024 00000001300 12261275120 015551 0ustar00brianstaff000000 000000 { "abstract" : "Ensure a build file lists all pre-requisites", "author" : [ "brian d foy " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Test-Prereq", "no_index" : { "directory" : [ "t", "inc" ] }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "web" : "https://github.com/briandfoy/test-prereq" } }, "version" : "1.038" } Test-Prereq-1.038/META.yml000664 000765 000024 00000000731 12261275120 015410 0ustar00brianstaff000000 000000 --- abstract: 'Ensure a build file lists all pre-requisites' author: - 'brian d foy ' build_requires: {} dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Test-Prereq no_index: directory: - t - inc resources: repository: https://github.com/briandfoy/test-prereq version: 1.038 Test-Prereq-1.038/README000644 000765 000024 00000000743 12261275117 015026 0ustar00brianstaff000000 000000 $Id$ You can install this using in the usual Perl fashion perl Makefile.PL make make test make install The documentation is in the module file. Once you install the file, you can read it with perldoc. perldoc Test::Prereq If you want to read it before you install it, you can use perldoc directly on the module file. perldoc lib/Prereq.pm This module is also in CVS on SourceForge http://sourceforge.net/projects/brian-d-foy/ Enjoy, brian d foy, bdfoy@cpan.orgTest-Prereq-1.038/t/000755 000765 000024 00000000000 12261275120 014377 5ustar00brianstaff000000 000000 Test-Prereq-1.038/testdir/000755 000765 000024 00000000000 12261275120 015612 5ustar00brianstaff000000 000000 Test-Prereq-1.038/testdir/bad_makefile/000755 000765 000024 00000000000 12261275120 020175 5ustar00brianstaff000000 000000 Test-Prereq-1.038/testdir/build_pl/000755 000765 000024 00000000000 12261275120 017404 5ustar00brianstaff000000 000000 Test-Prereq-1.038/testdir/good_makefile/000755 000765 000024 00000000000 12261275120 020377 5ustar00brianstaff000000 000000 Test-Prereq-1.038/testdir/good_makefile/Makefile.PL000644 000765 000024 00000000770 12261275117 022363 0ustar00brianstaff000000 000000 use ExtUtils::MakeMaker; WriteMakefile ( 'NORECURS' => 1, 'NO_META' => 1, 'NO_MYMETA' => 1, 'NAME' => 'Test::Prereq', 'VERSION' => '0.05', 'CONFIGURE_REQUIRES' => { 'Test::Manifest' => '0', }, 'BUILD_REQUIRES' => { 'Test::Output' => '0', }, 'PREREQ_PM' => { 'HTTP::Size' => '0', 'XML::Twig' => '0', }, 'PM' => { 'lib/Prereq.pm' => '$(INST_LIBDIR)/Prereq.pm', }, depend => { Makefile => 't/test_manifest' }, test => { TESTS => $tests }, ); 1; Test-Prereq-1.038/testdir/good_makefile/MANIFEST000644 000765 000024 00000000053 12261275117 021534 0ustar00brianstaff000000 000000 this is here to make Module::Build shut up Test-Prereq-1.038/testdir/build_pl/Build.PL000755 000765 000024 00000001770 12261275117 020716 0ustar00brianstaff000000 000000 #!perl use strict; use warnings; use Module::Build; my $class = do { if( eval "use Test::Manifest 2.00; 1" ) { Test::Manifest->get_module_build_subclass; } else { 'Module::Build'; } }; my $build = $class->new( module_name => 'Test::Prereq', dist_abstract => 'Ensure a build file lists all pre-requisites', dist_version_from => 'lib/Prereq.pm', license => 'perl', dist_author => 'brian d foy ', recommends => { 'Test::Manifest' => '2.00', }, build_requires => { 'perl' => '5.010', 'Test::Builder' => '0', 'Test::Builder::Tester' => '0', 'Test::More' => '0', }, requires => { 'Module::Build' => '0', 'Module::CoreList' => '0', 'Module::Info' => '0', }, pm_files => { 'lib/Prereq.pm' => 'lib/Test/Prereq.pm', 'lib/Build.pm' => 'lib/Test/Prereq/Build.pm', }, add_to_cleanup => [ qw|Test-*| ], ); $build->create_build_script; Test-Prereq-1.038/testdir/bad_makefile/Makefile.PL000644 000765 000024 00000000557 12261275117 022164 0ustar00brianstaff000000 000000 use ExtUtils::MakeMaker; WriteMakefile ( 'NORECURS' => 1, 'NO_META' => 1, 'NO_MYMETA' => 1, 'NAME' => 'Test::Prereq', 'VERSION' => '0.05', 'PREREQ_PM' => { 'HTTP::Size' => 0, }, 'PM' => { 'lib/Prereq.pm' => '$(INST_LIBDIR)/Prereq.pm', }, depend => { Makefile => 't/test_manifest' }, test => { TESTS => $tests }, ); 0; Test-Prereq-1.038/t/get_from_file.t000644 000765 000024 00000001156 12261275117 017376 0ustar00brianstaff000000 000000 use Test::More 0.95; use Test::Prereq; my $modules = Test::Prereq->_get_from_file( 't/pod.t' ); my @modules = grep ! /^CPANPLUS/, @$modules; diag "Did not find right modules from t/pod.t!\n" . "Found <@modules>\n" unless ok( eq_array( \@modules, [] ), 'Right modules for t/pod.t' ); $modules = Test::Prereq->_get_from_file( 'lib/Test/Prereq.pm' ); @modules = grep ! /^CPANPLUS/, @$modules; diag "Did not find right modules for lib/Test/Prereq.pm!\n" . "Found <@modules>\n" unless ok( eq_array( \@modules, [ qw( Module::Info ) ] ), 'Right modules for lib/Test/Prereq.pm' ); done_testing(); Test-Prereq-1.038/t/get_from_prereqs.t000644 000765 000024 00000000273 12261275117 020137 0ustar00brianstaff000000 000000 use strict; use Test::Prereq; use Test::More tests => 1; use lib qw(.); print STDERR "\nThis may take awhile...\n"; my $modules = Test::Prereq->_get_from_prereqs( [ 'Tk' ] ); ok(1); Test-Prereq-1.038/t/get_loaded_modules.t000644 000765 000024 00000001640 12261275117 020412 0ustar00brianstaff000000 000000 use Test::More tests => 1; use Test::Prereq; { my $modules = Test::Prereq->_get_loaded_modules(); my $keys = [ grep ! /^CPANPLUS/, sort keys %$modules ]; print STDERR "Didn't find right modules! Found < @$keys >\n" unless ok( eq_array( $keys, [ qw( Module::Info Test::Prereq Test::Prereq::Build ) ] ), 'Right modules for modules and tests' ); } __END__ TODO: { local $TODO = "This interface changed, so these tests are not valid"; my $modules = Test::Prereq->_get_loaded_modules( ); my $okay = defined $modules ? 0 : 1; ok( $okay, '_get_loaded_modules catches no arguments' ); $modules = Test::Prereq->_get_loaded_modules( undef, 't' ); $okay = defined $modules ? 0 : 1; ok( $okay, '_get_loaded_modules catches missing first arg' ); $modules = Test::Prereq->_get_loaded_modules( 'blib/lib', undef ); $okay = defined $modules ? 0 : 1; ok( $okay, '_get_loaded_modules catches missing second arg' ); } Test-Prereq-1.038/t/get_prereqs.t000644 000765 000024 00000003355 12261275117 017120 0ustar00brianstaff000000 000000 use strict; use Test::More 0.95; use Cwd; use Test::Prereq; use Test::Prereq::Build; use lib qw(.); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # subtest 'get_prereqs' => sub { my $cwd = cwd; chdir "testdir/build_pl" or warn "Could not change directory! $!"; my $modules = Test::Prereq::Build->_get_prereqs(); diag "Didn't find right modules!\nFound <@$modules>\n" unless is_deeply( $modules, [ sort qw( Module::Build Module::CoreList Module::Info Test::Builder Test::Builder::Tester Test::Manifest Test::More ) ], 'Right modules for Build.PL' ); chdir $cwd or warn "Could not reset dirctory! $!"; }; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # subtest 'good_makefile' => sub { my $cwd = cwd; chdir "testdir/good_makefile" or warn "Could not change directory! $!"; ok( -e 'Makefile.PL', 'Makefile.PL is in the current working directory' ); my $modules = Test::Prereq->_get_prereqs(); isa_ok( $modules, 'ARRAY' ); diag "Didn't find right modules!\nFound <@$modules>\n" unless is_deeply( $modules, [ sort qw( HTTP::Size XML::Twig Test::Output Test::Manifest ) ], 'Right modules for Makefile.PL' ); chdir $cwd or warn "Could not reset dirctory! $!"; }; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # subtest 'bad_makefile' => sub { my $cwd = cwd; chdir "testdir/bad_makefile" or warn "Could not change directory! $!"; diag( "You might see an error about loading a Makefile.PL. That's fine." ); my $modules = Test::Prereq->_get_prereqs(); my $okay = defined $modules ? 0 : 1; ok( $okay, 'Bad Makefile.PL fails in right way' ); chdir $cwd or warn "Could not reset dirctory! $!"; }; done_testing(); Test-Prereq-1.038/t/import.t000644 000765 000024 00000001204 12261275117 016101 0ustar00brianstaff000000 000000 use strict; use Test::More tests => 4; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # package Mimi; my $value = not defined &prereq_ok; main::ok( $value, 'Test::Prereq has not imported yet' ); require Test::Prereq; Test::Prereq->import; main::ok( defined &prereq_ok, 'Test::Prereq imported prereq_ok' ); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # package Buster; $value = not defined &prereq_ok; main::ok( $value, 'Test::Prereq::Build has not imported yet' ); require Test::Prereq::Build; Test::Prereq->import; main::ok( defined &prereq_ok, 'Test::Prereq::Build imported prereq_ok' ); Test-Prereq-1.038/t/load.t000644 000765 000024 00000000442 12261275117 015511 0ustar00brianstaff000000 000000 BEGIN { @classes = qw(Test::Prereq Test::Prereq::Build); } use Test::More tests => 2 * scalar @classes; foreach my $class ( @classes ) { undef &main::prereq_ok; BAIL_OUT( "Could not compile $class!" ) unless use_ok( $class ); ok( defined &main::prereq_ok, "prereq_ok imported" ); } Test-Prereq-1.038/t/pod.t000644 000765 000024 00000000201 12261275117 015345 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); Test-Prereq-1.038/t/pod_coverage.t000644 000765 000024 00000000453 12261275117 017231 0ustar00brianstaff000000 000000 use Test::More; eval "use Test::Pod::Coverage"; if( $@ ) { plan skip_all => "Test::Pod::Coverage required for testing POD"; } else { plan tests => 2; pod_coverage_ok( "Test::Prereq" ); pod_coverage_ok( "Test::Prereq::Build", { trustme => [ qr/create_build_script|prereq_ok/ ] } ); } Test-Prereq-1.038/t/prereq_ok.t000644 000765 000024 00000000122 12261275117 016554 0ustar00brianstaff000000 000000 use Test::Prereq; prereq_ok( undef, undef, [ qw(CPANPLUS::Internals::System) ] ); Test-Prereq-1.038/t/prior_plan.t000644 000765 000024 00000000171 12261275117 016736 0ustar00brianstaff000000 000000 use Test::More 0.95; use Test::Prereq; prereq_ok( undef, undef, [ qw(CPANPLUS::Internals::System) ] ); done_testing(); Test-Prereq-1.038/t/test_manifest000644 000765 000024 00000000204 12261275117 017171 0ustar00brianstaff000000 000000 load.t pod.t pod_coverage.t prereq_ok.t import.t get_from_file.t get_from_prereqs.t get_loaded_modules.t get_prereqs.t prior_plan.t Test-Prereq-1.038/lib/Test/000755 000765 000024 00000000000 12261275120 015621 5ustar00brianstaff000000 000000 Test-Prereq-1.038/lib/Test/Prereq/000755 000765 000024 00000000000 12261275120 017057 5ustar00brianstaff000000 000000 Test-Prereq-1.038/lib/Test/Prereq.pm000644 000765 000024 00000026217 12261275117 017433 0ustar00brianstaff000000 000000 package Test::Prereq; use strict; use utf8; use warnings; no warnings; =encoding utf8 =head1 NAME Test::Prereq - check if Makefile.PL has the right pre-requisites =head1 SYNOPSIS # if you use Makefile.PL use Test::More; eval "use Test::Prereq"; plan skip_all => "Test::Prereq required to test dependencies" if $@; prereq_ok(); # specify a perl version, test name, or module names to skip prereq_ok( $version, $name, \@skip ); # 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 from the command line for a one-off check perl -MTest::Prereq -eprereq_ok #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(); =head1 DESCRIPTION The C function examines the modules it finds in F, F, and the test files it finds in F (and F). It figures out which modules they use, skips the modules that are in the Perl core, and compares the remaining list of modules to those in the C section of F. If you use C instead, see L instead. =head2 Modules Test::Prereq can't find C only tells C which modules you used, not which distribution they came in. This can be a problem for things in packages like libnet, libwww, Tk, and so on. At the moment C asks CPAN.pm to expand anything in C to see if one of the distributions you explicity list contains the module you actually used. This might fail in some cases. Please send me anything that does not do what you think it should. C only asks CPAN.pm for help if it needs it, since CPAN.pm can be slow if it has to fetch things from the network. Once it fetches the right things, it should be much faster. =head2 Problem with Module::Info C appears to do something weird if a file it analyzes does not use (or require) any modules. You may get a message like Can't locate object method "name" via package "B::NULL" at /usr/perl5.8.0/lib/site_perl/5.8.0/B/Module/Info.pm line 176. Also, if a file cannot compile, C dumps a lot of text to the terminal. You probably want to bail out of testing if the files do not compile, though. =head2 Problem with CPANPLUS C apparently does some weird things, and since it is still young and not part of the Standard Library, C's tests do not do the right thing under it (for some reason). C cheats by ignoring C completely in the tests---at least until someone has a better solution. If you do not like that, you can set C<$EXCLUDE_CPANPLUS> to a false value. You should be able to do a 'make test' manually to make everything work, though. =head2 Warning about redefining ExtUtils::MakeMaker::WriteMakefile C has its own version of C so it can run the F and get the argument list of that function. You may see warnings about this. =cut use base qw(Exporter); use vars qw($VERSION $EXCLUDE_CPANPLUS @EXPORT @prereqs); $VERSION = '1.038'; @EXPORT = qw( prereq_ok ); use Carp qw(carp); use ExtUtils::MakeMaker; use File::Find; use Module::CoreList; use Module::Info; use Test::Builder; use Test::More; my $Test = Test::Builder->new; my $Namespace = ''; $EXCLUDE_CPANPLUS = 1; { no warnings; * ExtUtils::MakeMaker::WriteMakefile = sub { my %hash = @_; my $name = $hash{NAME}; my %prereqs = map { defined $_ ? %$_ : () } @hash{qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES)}; $Namespace = $name; @Test::Prereq::prereqs = sort keys %prereqs; 1; } } #unless( caller ) { prereq_ok() } =head1 FUNCTIONS =over 4 =item prereq_ok( [ VERSION, [ NAME [, SKIP_ARRAY] ] ] ) Tests F to ensure all non-core module dependencies are in C. If you haven't set a testing plan already, C creates a plan of one test. If you don't specify a version, C assumes you want to compare the list of prerequisite modules to the version of perl running the test. Valid versions come from C (which uses C<$]>). #!/usr/bin/perl use Module::CoreList; print map "$_\n", sort keys %Module::CoreList::version; C attempts to remove modules found in F and libraries found in F from the reported prerequisites. The optional third argument is an array reference to a list of names that C should ignore. You might want to use this if your tests do funny things with C. Versions prior to 1.038 would use CPAN.pm to virtually include prerequisites in distributions that you declared explicitly. This 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. If you want the old behavior, set the C environment variable to a true value. =cut my $default_version = $]; my $version = $]; sub prereq_ok { $Test->plan( tests => 1 ) unless $Test->has_plan; __PACKAGE__->_prereq_check( @_ ); } sub import { my $self = shift; my $caller = caller; no strict 'refs'; *{$caller.'::prereq_ok'} = \&prereq_ok; $Test->exported_to($caller); $Test->plan(@_); } sub _prereq_check { my $class = shift; $version = shift || $default_version; my $name = shift || 'Prereq test'; my $skip = shift || []; $version = $default_version unless exists $Module::CoreList::version{$version}; unless( ref $skip eq ref [] ) { carp( 'Third parameter to prereq_ok must be an array reference!' ); return; } # get the declared prereqs from the Makefile.PL my $prereqs = $class->_get_prereqs(); unless( $prereqs ) { $class->_not_ok( "\t" . $class->_master_file . " did not return a true value.\n" ); return 0; } my $loaded = $class->_get_loaded_modules(); unless( $loaded ) { $class->_not_ok( "\tCouldn't look up the modules for some reasons.\n" , "\tDo the blib/lib and t directories exist?\n", ); return 0; } # remove modules found in PREREQ_PM foreach my $module ( @$prereqs ) { delete $loaded->{$module}; } # remove modules found in distribution my $distro = $class->_get_dist_modules( 'blib/lib' ); foreach my $module ( @$distro ) { delete $loaded->{$module}; } # remove modules found in test directory $distro = $class->_get_test_libraries(); foreach my $module ( @$distro ) { delete $loaded->{$module}; } # remove modules in the skip array foreach my $module ( @$skip ) { delete $loaded->{$module}; } # if anything is left, look for modules in the distributions # in PREREQ_PM. this is slow, so we should only do it if # we might need it. if( keys %$loaded and $class->_should_i_expand_prereqs ) { my $modules = $class->_get_from_prereqs( $prereqs ); foreach my $module ( @$modules ) { delete $loaded->{$module}; } } if( $EXCLUDE_CPANPLUS ) { foreach my $module ( keys %$loaded ) { next unless $module =~ m/^CPANPLUS::/; delete $loaded->{$module}; } } if( keys %$loaded ) # stuff left in %loaded, oops! { $class->_not_ok( "Found some modules that didn't show up in PREREQ_PM or *_REQUIRES\n", map { "\t$_\n" } sort keys %$loaded ); } else { $Test->ok( 1, $name ); } return 1; } sub _not_ok { my( $self, $name, @message ) = @_; $Test->ok( 0, $name ); $Test->diag( join "", @message ); } sub _master_file { 'Makefile.PL' } sub _get_prereqs { my $class = shift; my $file = $class->_master_file; delete $INC{$file}; # make sure we load it again { local $^W = 0; unless( do "./$file" ) { print STDERR "_get_prereqs: Error loading $file: $@\n"; return; } delete $INC{$file}; # pretend we were never here } my @modules = sort @Test::Prereq::prereqs; @Test::Prereq::prereqs = (); return \@modules; } # expand prereqs and see what we get sub _should_i_expand_prereqs { !! $ENV{TEST_PREREQ_EXPAND_WITH_CPAN} } sub _get_from_prereqs { my $class = shift; my $modules = shift; my @dist_modules = (); return [] unless $class->_should_i_expand_prereqs; require CPAN; foreach my $module ( @$modules ) { my $mod = CPAN::Shell->expand( "Module", $module ); next unless ref $mod; my $distfile = $mod->cpan_file; my $dist = CPAN::Shell->expand( "Distribution", $distfile ); my @found = $dist->containsmods; push @dist_modules, @found; } return \@dist_modules; } # get all the loaded modules. we'll filter this later sub _get_loaded_modules { my $class = shift; # return unless( defined $_[0] and defined $_[1] ); # return unless( -d $_[0] and -d $_[1] ); my( @libs, @t, @scripts ); File::Find::find( sub { push @libs, $File::Find::name if m/\.pm$/ }, 'blib/lib' ) if -e 'blib/lib'; File::Find::find( sub { push @t, $File::Find::name if m/\.t$/ }, 't' ) if -e 't'; File::Find::find( sub { push @scripts, $File::Find::name if -f $_ }, 'blib/script' ) if -e 'blib/script'; my @found = (); foreach my $file ( @libs, @t, @scripts ) { push @found, @{ $class->_get_from_file( $file ) }; } return { map { $_, 1 } @found }; } sub _get_test_libraries { my $class = shift; my $dirsep = "/"; my @found = (); File::Find::find( sub { push @found, $File::Find::name if m/\.p(l|m)$/ }, 't' ); my @files = map { my $x = $_; $x =~ s/^.*$dirsep//; $x =~ s|$dirsep|::|g; $x; } @found; push @files, 'test.pl' if -e 'test.pl'; return \@files; } sub _get_dist_modules { my $class = shift; return unless( defined $_[0] and -d $_[0] ); my $dirsep = "/"; my @found = (); File::Find::find( sub { push @found, $File::Find::name if m/\.pm$/ }, $_[0] ); my @files = map { my $x = $_; $x =~ s/^$_[0]($dirsep)?//; $x =~ s/\.pm$//; $x =~ s|$dirsep|::|g; $x; } @found; return \@files; } sub _get_from_file { my( $class, $file ) = @_; my $module = Module::Info->new_from_file( $file ); $module->die_on_compilation_error(1); my @used = eval{ $module->modules_used }; my @modules = sort grep { not exists $Module::CoreList::version{$version}{$_} } @used; @modules = grep { not /$Namespace/ } @modules if $Namespace; return \@modules; } =back =head1 TO DO * set up a couple fake module distributions to test * warn about things that show up in C unnecessarily =head1 SOURCE AVAILABILITY This source is in Github: http://github.com/briandfoy/test-prereq =head1 CONTRIBUTORS Many thanks to: Andy Lester, Slavin Rezić, Randal Schwartz, Iain Truskett, Dylan Martin =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT and LICENSE Copyright 2002-2014, brian d foy, All rights reserved This software is available under the same terms as perl. =cut 1; Test-Prereq-1.038/lib/Test/Prereq/Build.pm000644 000765 000024 00000003544 12261275117 020470 0ustar00brianstaff000000 000000 package Test::Prereq::Build; use strict; use base qw(Test::Prereq); use vars qw($VERSION @EXPORT); use warnings; no warnings; =encoding utf8 =head1 NAME Test::Prereq::Build - test prerequisites in Module::Build scripts =head1 SYNOPSIS use Test::Prereq::Build; prereq_ok(); =cut $VERSION = '1.038'; use Module::Build; use Test::Builder; my $Test = Test::Builder->new; =head1 METHODS If you have problems, send me your F. This module overrides methods in C to make it work with C. This module does not have any public methods. See L. To make everything work out with C, this module overrides some methods to do nothing. =over 4 =item create_build_script =item add_build_element =item args =item notes =back =head1 AUTHOR brian d foy, C<< >> =head1 COPYRIGHT AND LICENSE Copyright (c) 2002-2014 brian d foy. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut sub import { my $self = shift; my $caller = caller; no strict 'refs'; *{$caller.'::prereq_ok'} = \&prereq_ok; $Test->exported_to($caller); $Test->plan(@_); } sub prereq_ok { $Test->plan( tests => 1 ) unless $Test->has_plan; __PACKAGE__->_prereq_check( @_ ); } sub _master_file { 'Build.PL' } # override Module::Build sub Module::Build::new { my $class = shift; my %hash = @_; my @requires = sort grep $_ ne 'perl', ( keys %{ $hash{requires} }, keys %{ $hash{build_requires} }, keys %{ $hash{configure_requires} }, keys %{ $hash{recommends} }, ); @Test::Prereq::prereqs = @requires; # intercept further calls to this object return bless {}, __PACKAGE__; } # fake Module::Build methods sub create_build_script { 1 }; sub add_build_element { 1 }; sub args { 1 }; sub notes { 1 }; 1; Test-Prereq-1.038/examples/README000644 000765 000024 00000000105 12261275117 016634 0ustar00brianstaff000000 000000 See the tests in the t/ directory for examples until I add some more.