diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-11 22:32:06 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-11 22:32:06 +0000 |
commit | 467298a34215401cdcbb1dded51bc2aba5f1f41c (patch) | |
tree | 1923f32fbc9cf8f0b4ab291d1eb9fad5ab872d68 | |
download | Module-Build-tarball-master.tar.gz |
Module-Build-0.4214HEADModule-Build-0.4214master
97 files changed, 28391 insertions, 0 deletions
diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..21ec0b3 --- /dev/null +++ b/Build.PL @@ -0,0 +1,148 @@ +use 5.006001; +use strict; + +BEGIN { + die "CPANPLUS::Dist::Build version 0.08 or later is required to install Module::Build\n" + if $INC{'CPANPLUS/Dist/Build.pm'} && CPANPLUS::Dist::Build->VERSION lt '0.08'; +} + +# On some platforms (*ahem*, MacPerl 5.6.1) "use lib qw(lib);" doesn't +# find the local "lib" directory, so we use File::Spec to do it properly. +use File::Spec 0.82; +use lib File::Spec->catdir('lib'); # use our self to install +# XXX This doesn't carry over to sub processes +use lib File::Spec->catdir('t', 'bundled'); # use bundled modules +use lib File::Spec->catdir('t', 'lib'); # our utilities + +# bootstrap configure_requires prereqs +BEGIN { do 'inc/bootstrap.pl' } + +# We use Module::Build to test & install itself. +use Module::Build; + +# + +my $build = Module::Build->new( + module_name => 'Module::Build', + license => 'perl', + configure_requires => { + 'CPAN::Meta' => '2.142060', + 'Perl::OSType' => 1, + 'Module::Metadata' => '1.000002', + 'version' => '0.87', + }, + build_requires => { + 'File::Temp' => 0.15, # tmpdir() + fixes + 'Test::More' => 0.49, + 'Test::Harness' => 3.16, # PERL5LIB fixes + 'Parse::CPAN::Meta' => '1.4401', + 'CPAN::Meta::YAML' => 0.003, + }, + # KEEP 'requires' as low as possible and target Build/test/install + # Requirements for authors should be implemented as optional features + requires => { + 'perl' => '5.008000', + 'Data::Dumper' => 0, + 'File::Basename' => 0, + 'File::Compare' => 0, + 'File::Copy' => 0, + 'File::Find' => 0, + 'File::Path' => 0, + 'File::Spec' => ($^O eq 'MSWin32' ? 3.30 : '0.82'), # rel2abs() + 'ExtUtils::CBuilder' => 0.27, # major platform fixes + 'ExtUtils::Install' => 0, + 'ExtUtils::Manifest' => 0, + 'ExtUtils::Mkbootstrap' => 0, + 'ExtUtils::ParseXS' => 2.21, # various bug fixes + 'Cwd' => 0, + 'Text::Abbrev' => 0, + 'Text::ParseWords' => 0, + 'Getopt::Long' => 0, + 'Test::Harness' => 0, + 'CPAN::Meta' => '2.142060', + 'Perl::OSType' => ( $^O eq 'bitrig' ? 1.004 : 1 ), # needs 1.0 API + 'version' => 0.87, # No longer requires M::B + 'Module::Metadata' => 1.000002, # uses version.pm + 'Pod::Man' => 2.17, # utf8 support + }, + recommends => { + 'ExtUtils::Install' => 0.30, + 'ExtUtils::Manifest' => 1.54, # public maniskip() + }, + recursive_test_files => 1, + sign => 0, + create_readme => 1, + create_license => 1, + + # overwrite the M::B that shipped in core + installdirs => ($] >= 5.009004 && $] < 5.011 ? 'core' : 'site'), + + # Some CPANPLUS::Dist::Build versions need to allow mismatches + # On logic: thanks to Module::Install, CPAN.pm must set both keys, but + # CPANPLUS sets only the one + allow_mb_mismatch => ( + $ENV{PERL5_CPANPLUS_IS_RUNNING} && ! $ENV{PERL5_CPAN_IS_RUNNING} ? 1 : 0 + ), + + auto_features => { + dist_authoring => { + description => "Create new distributions", + requires => { + 'Archive::Tar' => 1.09, + }, + recommends => { + 'Pod::Readme' => 0.04, + 'Module::Signature' => 0.21, + }, + }, + license_creation => { + description => "Create licenses automatically in distributions", + requires => { + 'Software::License' => 0.103009 + }, + }, + PPM_support => { + description => "Generate PPM files for distributions", + }, + inc_bundling_support => { + description => "Bundle Module::Build in inc/", + requires => { + 'inc::latest' => 0.500, # split out from Module::Build + 'ExtUtils::Install' => 1.54, # also gets us ExtUtils::Installed 1.999_001 + 'ExtUtils::Installed' => 1.999, # technically 1.999_001 is what's available + }, + }, + manpage_support => { + description => "Create Unix man pages", + requires => {'Pod::Man' => 0 }, + }, + HTML_support => { + description => "Create HTML documentation", + requires => {'Pod::Html' => 0}, + }, + }, + + add_to_cleanup => ['t/Sample/pod2htm*'], + script_files => ['bin/config_data'], + meta_merge => { + resources => { + MailingList => 'mailto:module-build@perl.org', + repository => 'https://github.com/Perl-Toolchain-Gang/Module-Build', + IRC => 'irc://irc.perl.org/#toolchain', + } + }, +); + +$build->create_build_script; +if (-f "META.yml" && ! -f "MYMETA.yml") { # fallback if we don't have CPAN::Meta + require File::Copy; + File::Copy::copy("META.yml", "MYMETA.yml") or warn "Error: $!\n"; + if ( -f 'MYMETA.yml' ) { + warn "Copied META.yml to MYMETA.yml for bootstrapping\n"; + } + else { + warn "Could not copy META.yml to MYMETA.yml. That's odd!\n"; + } +} + +# vim:ts=2:sw=2:et:sta @@ -0,0 +1,4091 @@ +Revision history for Perl extension Module::Build. + +0.4214 - Fri Jun 12 00:25:00 CEST 2015 + + - Released 0.42_13 as 0.4214 + +0.42_13 - Sat Jun 6 21:18:24 CEST 2015 + + [BUG FIXES] + + - Handle failure to guess license from key better + + [ENHANCEMENTS] + + - Output data in a stable order [Jérémy Bobbio] + +0.4212 - Sun May 17 00:33:34 CEST 2015 + + [BUG FIXES] + + - Revert "Stop using version->normal(); prefer stringify()" + +0.4211 - Tue Jan 20 01:33:42 CET 2015 + + [BUG FIXES] + + - Fix t/actions/installdeps.t to work on "perl in space" [Ed J] + + - Stop using version->normal(); prefer stringify() [John Peacock] + + [DEPRECATIONS] + + - inc::latest has been split out to a separate distribution on CPAN. + It is an optional prerequisite, only needed for the experimental + bundling feature. + +0.4210 - Mon Sep 1 13:30:29 CEST 2014 + + [BUG FIXES] + + - Fixup CPAN::Meta dependency + + - Handle old releases of CPAN::Meta more gracefully. + +0.4209 - Mon Sep 1 12:24:40 CEST 2014 + + [BUG FIXES] + + - Stop calling UNIVERSAL::isa as a function + + [ENHANCEMENTS] + + - Use CPAN::Meta::Merge for meta_merge + + - Convert with CPAN::Meta::Convert in meta_add + + - Add configure requirements + +0.4208 - Mon Aug 18 21:44:38 CEST 2014 + + [BUG FIXES] + + - Removed missed references to Module::Build::Version + +0.4207 - Sat Aug 16 12:56:59 CEST 2014 + + [BUG FIXES] + + - Fix type installdir -> installdirs [Leon Timmermans, Vitaliy Tokarev] + + [DEPRECATIONS] + + - Module::Build::YAML has been removed + + - Module::Build::ModuleInfo has been removed + + - Module::Build::Version has been removed + + - Get rid of "use vars" + + - Added use warnings to all modules + +0.4206 - Sat Jul 12 14:03:01 CEST 2014 + + [BUG FIXES] + + - Formally declare 5.8 dependency [Karen Etheridge] + + - Fix MBTest to work with new and old versions of Test::Builder [Chad Granum] + + [ENHANCEMENTS] + + - Enable release and author tests during disttest [Leon Timmermans, Alberto Simões] + +0.4205 - Sun Feb 9 17:51:22 CET 2014 + + [BUG FIXES] + + - FIX license code regression for artistic license [Roy Ivy III, Leon Timmermans] + + - Don't swallow ExtUtils::CBuilder loading errors [Matthew Horsfall, Leon Timmermans] + + - Handle testing on cross-compile builds [Brian Fraser] + + - Protect against platforms without getpw{nam,uid} [Brian Fraser] + +0.4204 - Fri Jan 10 00:29:31 CET 2014 + + [BUG FIXES] + + - Map conflicts back to runtime [Leon Timmermans] + + - Use mod2fname whenever it's available [Leon Timmermans, Brian Fraser] + + - Accept custom entries in meta_merge 1.4 + +0.4203 - Wed Nov 27 19:09:05 CET 2013 + + [BUG FIXES] + + - Map recommends back to runtime recommends [Leon Timmermans] + + - Map restrictive license to restricted in meta 2.0 [Leon Timmermans] + +0.4202 - Tue Nov 19 12:48:19 CET 2013 + + [BUG FIXES] + + - Don't merge prereqs from meta to mymeta [Leon Timmermans] + +0.4201 - Mon Nov 18 23:23:25 CET 2013 + + [BUG FIXES] + + - Prefer META.json over META.yml [Leon Timmermans] + +0.4200 - Tue Nov 12 12:39:25 CET 2013 + + - Released 0.40_11 as 0.4200 + +0.40_11 - Wed Nov 6 12:46:59 CET 2013 + + [BUG FIXES] + + - Do not set provides in metadata if no_index is set [Leon Timmermans] + +0.40_10 - Tue Nov 5 12:11:37 CET 2013 + + [BUG FIXES] + + - Lowercase license in fallback logic [Leon Timmermans] + +0.40_09 - Tue Nov 5 00:13:11 CET 2013 + + [ENHANCEMENTS] + + - Converted to using Meta 2.0 + +0.4008 - Mon Nov 4 23:10:54 CET 2013 + + [BUG FIXES] + + - Fix test failing on ancient perls <= 5.8.1 [Peter Rabbitson] + + - Do not set default switches in Test::Harness; not even -w [Leon Timmermans] + + [DOCUMENTATION] + + - Fix a couple more broken links to CPAN::META::Spec that should + have been CPAN::Meta::Spec. [Reported by Mike Doherty] + +0.4007 - Fri Jul 19 13:44:39 CEST 2013 + + [BUG FIXES] + + - Removed undeclared test dependency on parent.pm [Leon Timmermans] + + - Declared dependency on Pod::Man 2.17 for utf8 support [Leon Timmermans] + + - Force generation of man pages in manify_with_utf8.t [Leon Timmermans] + +0.4006 - Thu Jul 18 14:19:49 CEST 2013 + + - Announcement: The Perl5-Porters have decided to remove + Module::Build from the perl core distribution. It will still be + available on CPAN, and development is planned to continue + regardless. + + For more information, see: + + * http://www.nntp.perl.org/group/perl.perl5.porters/2013/05/msg202041.html + * http://blogs.perl.org/users/joel_berger/2013/05/on-the-removal-of-some-core-modules.html + * http://www.dagolden.com/index.php/2140/paying-respect-to-modulebuild/ + * http://perlhacks.com/2013/06/removing-modules-from-core/ + + [BUG FIXES] + + - In the 'installdeps' action, w don't need to check for an + executable bit on the CPAN client, just try executing it. + Otherwise we needlessly fail on e.g. VMS. + + - Actually handle utf8 correctly in utf8-man tests. [Leon Timmermans] + + - Don't clobber standard array/hash attributes in subclasses that + have their own array/hash attributes. [Graham Ollis] + + - We now allow underscores in package names, when extracting the + name & abstract from POD. [Ricardo Signes, Shlomi Fish] + + - When building HTML docs, fix a problem with setting the --htmlroot + argument. [Ken Williams] + + - Lower Test::More dependency in the test metadata, so distgen + output won't mess up console with older Test::More installed. + [Tatsuhiko Miyagawa] + + - Revised detildification on VMS [Craig Berry] + + - Fix run_test_harness for case when $Switches is an empty string + [Victor Efimov, Ken Williams] + + [ENHANCEMENTS] + + - Significantly sped up some tests by not forcing HTML docs to be + built when the user's config doesn't ask for them anyway. + [Ken Williams] + + - The Module::Metadata package was split out from this distro back + in 2010. Removed its regression tests. [Ken Williams] + + - Removed dependence on IO::File, replacing it with safe invocations + of open(). [Sven Dowideit] + + - Added an 'extra_manify_args' parameter to facilitate man pages + containing Unicode. [Joenio Costa] + + - Added an '--html_links 0' argument for the 'html' action, which + can hugely speed things up. The main effect is speeding up the + M::B tests themselves. [Ken Williams] + + - Added continuous integration support for the Module::Build code + itself, through the Travis-CI project + (https://travis-ci.org/). [Tatsuhiko Miyagawa, Olivier Mengué] + + [DOCUMENTATION] + + - Removed suggestion in the INSTALL document to use the Makefile.PL + for installation. Making the Makefile.PL lower-profile in + general. [Ken Williams] + + - Fix link from UpperCase CPAN::META::Spec to CPAN::Meta::Spec in + API.pod. [Sven Dowideit] + + [OTHER] + + - Removed unused platform specific modules that never contained + anything. [Leon Timmermans] + + - Lots of typo fixes in comments & documentation. [David Steinbrunner] + + +0.4005 - Thu Apr 25 15:10:14 CEST 2013 + + [ENHANCEMENTS] + + - Added --pureperl-only support + + [BUG FIXES] + + - #72176: pod2html will fail with an empty podpath in some cases. [Phillip Moore] + + - Fix links between modules in HTML docs output [Michael Wild, Leon Timmermans] + +0.4004 - Fri Mar 29 15:05:00 CET 2013 + + [BUG FIXES] + + - Minor VMS fix for @INC [Craig Berry] + + [ENHANCEMENTS] + + - test_requires support has been added [Matsuno Tokuhiro] + +0.4003 - Sat Aug 18 11:17:49 CEST 2012 + + [BUG FIXES] + + - Get rid of outdated metadata tests [Steve Hay] + +0.4002 - Fri Jul 27 20:04:09 EEST 2012 + + [BUG FIXES] + + - Test for TAP::Harness version properly [Leon Timmermans] + + - Install to 'site' on 5.12+ [Leon Timmermans] + + [DOCUMENTATION] + + - Document extra_{compiler|linker}_flags accessors [Nick Wellnhofer] + +0.4001 - Tue Jun 26 20:54:15 CEST 2012 + [BUG FIXES] + + - Parse Pod name a litte more leniently [Paul Evans] + + [DOCUMENTATION] + + - Various spelling fixes [Leon Timmermans, Jonathan Yu] + + - Fixes configuration keys used for script location [Leon Timmermans, reported by Samuel Ferencik] + + [OTHER] + + - use warnings + +0.40 - Fri Feb 24 18:47:48 CET 2012 + + - Released 0.39_02 as 0.40 without any code changes + +0.39_02 - Thu Feb 17 00:33:18 MET 2012 + + [BUG FIXES] + + - Fixed bug where modules without $VERSION might have a version of '0' + listed in 'provides' metadata, which will be rejected by PAUSE + [David Golden, reported by Christopher Fields] + + - Fixed bug in PodParser to allow numerals in module names + [Tokuhirom] + + - Fixed bug where giving arguments twice led to them becoming arrays, + resulting in install paths like "ARRAY(0xdeadbeef)/lib/Foo.pm" + [Leon Timmermans] + + [DOCUMENTATION] + + - Fixed deviance from alphabetical order in documentation of + constructor parameters. [Eric Brine] + + - Add documentation for configure_requires constructor parameter. + [Eric Brine] + + - Change some of the docs' language describing relationship to + MakeMaker. [Ken Williams] + + [OTHER] + + - List Perl-Toolchain-Gang repo as official repo + +0.39_01 - Thu Jul 21 16:48:48 EDT 2011 + + [BUG FIXES] + + - Fixed bug with a nested directory named 'share' inside a ShareDir + (RT#68585) [David Golden] + + - Fixed failing tilde.t when run under UID without passwd entry + (RT#67893) [Dominic Hargreaves] + + [DOCUMENTATION] + + - Fixed typo in Module::Build (RT#67008) [David Golden] + + [OTHER] + + - Pod to HTML internals changed to support new Pod::Html work + in the Perl core + +0.3800 - Sat Mar 5 15:11:41 EST 2011 + + Summary of major changes since 0.3624: + + [ENHANCEMENTS] + + - Generates META.json and MYMETA.json consistent with version 2 of the + CPAN Meta Spec. [David Golden] + + Also in this release: + + [BUG FIXES] + + - Autogenerated documentation no longer includes private actions from + Module::Build's own release subclass. [Report by Timothy Appnel, + fix by David Golden] + +0.37_06 - Mon Feb 28 21:43:31 EST 2011 + + [BUG FIXES] + + - prerequisites with the empty string instead of a version are + normalized to "0". (RT#65909) + + [OTHER] + + - More Pod typo/link fixes [Hongwen Qiu] + +0.37_05 - Sat Feb 19 20:43:23 EST 2011 + + [BUG FIXES] + + - fixes failing ppm.t in perl core + + [OTHER] + + - Pod typo fixes [Hongwen Qiu] + +0.37_04 - Wed Feb 16 15:27:21 EST 2011 + + [OTHER] + + - moved scripts/ to bin/ for less confusing porting to bleadperl + +0.37_03 - Wed Feb 16 09:54:05 EST 2011 + + [BUG FIXES] + + - removed an irrelevant test in t/actions/installdeps.t that was causing + failures on some Cygwin platforms + + [OTHER] + + - dropped configure_requires as some CPAN clients apparently get + confused by having things in both configure_requires and requires + + - bumped Parse::CPAN::Meta build prereq to 1.4401 + + - bumped CPAN::Meta prereq to 2.110420 + + - Pod typo fixes [Hongwen Qiu] + +0.37_02 - Mon Feb 7 21:05:30 EST 2011 + + [BUG FIXES] + + - bumped CPAN::Meta prereq to 2.110390 to avoid a regression in 2.110360 + +0.37_01 - Thu Feb 3 03:44:38 EST 2011 + + [ENHANCEMENTS] + + - Generates META.json and MYMETA.json consistent with version 2 of the + CPAN Meta Spec. [David Golden] + + [BUG FIXES] + + - t/signature.t now uses a mocked Module::Signature; this should be + more robust across platforms as it only needs to confirm that + Module::Build is calling Module::Signature when expected + + [OTHER] + + - Added CPAN::Meta and Parse::CPAN::Meta to prerequisites and dropped + CPAN::Meta::YAML + +0.3624 - Thu Jan 27 11:38:39 EST 2011 + + - Fixed pod2html directory bugs and fixed creation of spurious blib + directory in core perl directory when running install.t (RT#63003) + [Chris Williams] + +0.3623 - Wed Jan 26 17:45:30 EST 2011 + + - Fixed bugs involving bootstrapping configure_requires prerequisites + on older CPANPLUS clients or for either CPAN/CPANPLUS when using + the compatibility Makefile.PL + + - Added diagnostic output when configure_requires are missing for + the benefit of users doing manual installation + +0.3622 - Mon Jan 24 21:06:50 EST 2011 + + - No changes from 0.36_21 + +0.36_21 - Fri Jan 21 11:01:28 EST 2011 + + - Changed YAML::Tiny references to the new CPAN::Meta::YAML module + instead, which is the YAML-variant that is going into the Perl core + +0.36_20 - Fri Dec 10 15:36:03 EST 2010 + + *** DEPRECATIONS *** + + - Module::Build::Version has been deprecated. Module::Build now depends + directly upon version.pm. A pure-perl version has been bundled in inc/ + solely for bootstrapping in case configure_requires is not supported. + M::B::Version remains as a wrapper around version.pm. + + - Module::Build::ModuleInfo has been deprecated. Module::Build now + depends directly upon Module::Metadata (which is an extraction of + M::B::ModuleInfo intended for general reuse). A pure-perl version has + been bundled in inc/ solely for bootstrapping in case + configure_requires is not supported. M::B::ModuleInfo remains as a + wrapper around Module::Metadata. + + - Module::Build::YAML has been deprecated. Module::Build now depends + directly upon YAML::Tiny. M::B::YAML remains as a subclass wrapper. + The YAML_support feature has been removed, as YAML is now an ordinary + dependency. + +0.36_19 - Tue Dec 7 13:43:42 EST 2010 + + Bug fixes: + + - Perl::OSType is declared as a 'configure_requires' dependency, but is + also bundled in inc (and loaded if needed) [David Golden] + +0.36_18 - Mon Dec 6 16:46:49 EST 2010 + + Changes: + + - Added dependency on Perl::OSType to refactor and centralize + management of OS type mapping [David Golden] + + - When parsing a version number out of a file, any trailing alphabetical + characters will be dropped to avoid fatal errors when comparing version + numbers. These would have been dropped (with a warning) anyway during + an ordinary numeric comparison. (RT#56071) [David Golden] + + Bug fixes: + + - A Perl interpreter mismatch between running Build.PL and running Build + is now a fatal error, not a warning (RT#55183) [David Golden] + + - Bundled Module::Build::Version updated to bring into sync with CPAN + version.pm 0.86 [David Golden] + + - No longer uses fake user 'foo' in t/tilde (RT#61793) [David Golden] + + - Won't fail tests if an ancient Tie::IxHash is installed + [Christopher J. Madsen] + + - Correctly report missing metafile field names [David Golden] + + - Suppress uninitialized value errors during Pod creation + on ActiveState Perl [David Golden] + + - Return to starting directory after install action; this is + an attempt to fix an install.t heisenbug (RT#63003) [David Golden] + + - A broken version.pm load won't cause Module::Build::Version to + die trying to install itself as a mock version (RT#59499) + [Eric Wilhelm and David Golden] + + - PERL_DL_NONLAZY is now always set when tests are run + (RT#56055) [Dmitry Karasik] + + - 'fakeinstall' will use .modulebuildrc actions for 'install' if + no specific 'fakeinstall' options are provided (RT#57279) + [David Golden] + + - Add install*script to search path for installdeps client + and search site, then vendor, then core paths + + - Skip noexec tmpdir check on Windows (RT#55667) [Jan Dubois] + + - Arguments with key value pairs may now have keys with "-" in them + (RT#53050) [David Golden] + + - Add quotemeta to t/tilde.t test to fix Cygwin fails + [Chris Williams and David Golden] + + - Build script now checks that M::B is at least the same version + of M::B as provided in 'configure_requires' in META + (RT#54954) [David Golden] + +0.36_17 - Wed Oct 27 18:08:36 EDT 2010 + + Enhancements: + + - Added 'distinstall' action to run 'Build install' inside the + generated distribution directory [Jeff Thalhammer] + +0.36_16 - Thu Aug 26 12:44:07 EDT 2010 + + Bug fixes: + + - Better error message in case package declaration is not found + when searching for version. [Alexandr Ciornii] + + - Skips 'release_status' tests on perl < 5.8.1 due to buggy + treatment of dotted-decimal version numbers [David Golden] + +0.36_15 - Wed Aug 25 10:41:28 EDT 2010 + + Bug fixes: + + - Added a mock Software::License to prevent t/properties/license.t + from failing. + +0.36_14 - Sun Aug 22 22:56:50 EDT 2010 + + Enhancements: + + - Adds 'release_status' and 'dist_suffix' properties in preparation + for adding CPAN Meta Spec 2 support. 'dist_suffix' will be set + to 'TRIAL' automatically when necessary. [David Golden] + + - Makes 'license' more liberal. You can now specify either a license + key from the approved list (c.f. Module::Build::API) or just a + Software::License subclass name (e.g. 'Perl_5'). This should + provide better support for custom or proprietary licenses. + [David Golden] + +0.36_13 - Wed Jul 28 22:40:25 EDT 2010 + + Bug-fixes: + + - Bundled Module::Build::Version updated to bring into sync with CPAN + version.pm 0.82 [David Golden] + +0.36_12 - Tue Jul 27 00:08:51 EDT 2010 + + Enhancements: + + - Module::Build::Compat will now convert dotted-decimal prereqs into + decimal rather than dying (and will warn about this). [Apocalypse] + + Bug fixes: + + - Caches case-sensitivity checks to boost performance, fixes + RT#55162 and RT#56513 [Reini Urban] + + - Won't try to use ActivePerl doc generation tools without confirming + that they are indeed installed. [David Golden] + + - Sets temporary $ENV{HOME} in testing to an absolute path, which fixes + some issues when tested as part of the Perl core [Nicholas Clark] + + - Module::Build::ModuleInfo now warns instead of dying when a module + has an invalid version. ->version now just returns undef + (RT#59593) [David Golden] + + Changes: + + - When authors do not specify Module::Build in configure_requires and + Module::Build is automatically added, a warning will be issued + showing the added prerequisite [David Golden] + + - Moved automatic configure_requires generation into get_metadata() + and added an 'auto' argument to toggle it (on for META and off + for MYMETA) [David Golden] + +0.36_11 - Thu May 27 09:41:23 EDT 2010 + + Bug fixes: + + - Handle META/MYMETA reading and writing within Module::Build to ensure + utf8 mode on filehandles. Now passes/gets only strings to YAML::Tiny + or Module::Build::YAML + +0.36_10 - Wed May 19 18:36:06 EDT 2010 + + Bug fixes: + + - Fix failing t/manifypods.t on Windows from 0.36_09 changes [Klaus + Eichner] + +0.36_09 - Tue May 11 09:19:12 EDT 2010 + + Bug fixes: + + - Improve HTML documentation generation on ActivePerl (RT#53478) + [Scott Renner and Klaus Eichner] + +0.36_08 - Mon Apr 26 08:00:15 EDT 2010 + + Enhancements: + + - Give a list of valid licenses when given one we don't recognize + (RT#55951) [Yanick Champoux] + + - Added 'Build manifest_skip' action to generate a default MANIFEST.SKIP + [David Golden] + + Changes: + + - When temporarily generating a MANIFEST.SKIP when none exists, it will + be removed on exit instead of hanging around until 'Build clean'. This + is less surprising/confusing and the 'Build manifest_skip' action + is now available instead to bootstrap the file [David Golden] + + Bug fixes: + + - Fixed runtime error on cygwin when searching for an executable command + during installdeps testing [David Golden] + +0.3607 - Thu Apr 1 11:27:16 EDT 2010 + + Bug fixes: + + - The 'dist' action now always ensures a clean dist directory before + creating the tarball [David Golden] + +0.36_06 - Thu Apr 1 01:23:58 EDT 2010 + + Other: + + - Migrated repository to git and updated META.yml to match + + - Removed bugtracker URL (let search.cpan.org use default) + + - Disabled SIGNATURE generation + +0.3605 - Wed Mar 31 12:05:11 EDT 2010 + + - No changes from 0.36_04 + +0.36_04 - Tue Mar 16 21:41:41 EDT 2010 + + Bug fixes: + + - Added missing newline to "Changing sharpbang" messages under verbose + output (RT#54474) [David Golden] + + - Added 'beos' to list of Unix-like os types (RT#53876) [Nigel Horne] + + - Sets $ENV{HOME} to a temporary directory during testing [David Golden] + + - For VMS: fixed prefix handling plus other test fixes [Craig Berry] + + - Support anonymous array of directories for c_source [Alberto Simões] + + - Small POD formatting fix [James Keenan] + +0.3603 - Mon Jan 18 22:28:59 EST 2010 + +(Oops, I released the last one before I realized this should have been +fixed along with it.) + + Bug fixes: + + - Module::Build::Compat would croak on distibutions that set requires + 'perl' to a dotted decimal like '5.6.2'. We now skip that key + since it doesn't go into PREREQ_PM and we numify it properly for + 'use 5.006002' in the generated Makefile.PL (RT#53409) + [David Golden, adapted from patch by G. Allen Morris III] + +0.3602 - Mon Jan 18 22:09:54 EST 2010 + + Bug fixes: + + - Fix failures in t/properties/needs_compiler.t when $ENV{CC} is set + (RT#53296) [David Golden, adapted from patch by Jens Rehsack] + +0.3601 - Mon Dec 21 14:39:33 EST 2009 + + Bug fixes: + + - When the currently running Module::Build is not the same as the one + that created the Build file, there is now a warning rather than a fatal + error. This helps installation of dependency chains where a dependency + might configure_requires a new Module::Build after Build.PL was already + run for an earlier distribution. [David Golden, on advice of Matt Trout] + + Other: + + - t/bundle_inc.t fails in odd ways. This test of an experimental feature + should not prevent users from installing Module::Build, so this test + now skips unless $ENV{MB_TEST_EXPERIMENTAL} is true + +0.36 - Sun Dec 20 15:02:38 EST 2009 + +No changes from 0.35_15 other than the version number. + +Summary of major changes since 0.35: + + Enhancements: + + - Added 'Build installdeps' action to install needed dependencies via + a user-configurable command line program. (Defaults to 'cpan'.) + + - Command line options may be set via the PERL_MB_OPT environment + variable (similar to PERL_MM_OPT in ExtUtils::MakeMaker) + + - Generates MYMETA.yml during Build.PL (new standard protocol for + communicating configuration results between toolchain components) + + - Reduced amount of console output under normal operation (use --verbose + to see all output) + + - Added experimental inc/ bundling; see Module::Build::Bundling for + details. + + New or changed properties: + + - Added 'share_dir' property to provide File::ShareDir support; + File::ShareDir automatically added to 'requires' if 'share_dir' is set + + - Added 'needs_compiler' property. Defaults to true if XS or c_source + exist. If true, ExtUtils::CBuilder is also added to build_requires. + + - 'C_support' is no longer an optional feature. Modern ExtUtils::CBuilder + and ExtUtils::ParseXS added to the 'requires' list. This ensures that + upgrading Module::Build will upgrade these critical modules. + + - Clarified that 'apache' in the license attribute indicates the Apache + License 2.0 and added 'apache_1_1' for the older version of the license + (RT#50614) + + Deprecations: + + - Module::Build::Compat 'passthrough' style has been deprecated. Using + 'passthrough' will issue warnings on Makefile.PL generation. See + Module::Build::Compat documentation for rationale. + + Internals: + + - Replaced use of YAML.pm with YAML::Tiny; Module::Build::YAML is now + based on YAML::Tiny as well + + - A new get_metadata() method has been added as a simpler wrapper around + the old, kludgy prepare_metadata() API. + + - Replaced guts of new_from_context(). Build.PL is now executed in a + separate process before resume() is called. (This is generally only of + interest to Module::Build or toolchain developers) (RT#49350) + + - Add support for 'package NAME VERSION' syntax added in Perl 5.11.1 + + Notable bug fixes: + + - The "test" action now dies when using the 'use_tap_harness' + option and tests fail, matching the behavior under Test::Harness. + (RT#49080) [initial patch from David Wheeler; revised by David Golden] + + - Updated PPM generation to PPM v4 (RT#49600) [Olivier Mengue] + + - When module_name is not supplied, no packlist was being written; fixed + by guessing module_name from dist_version_from or the directory name + (just like ExtUtils::Manifest does without NAME) [David Golden] + + - Failure to detect a compiler will now warn during Build.PL and be a + fatal error when trying to compile during Build. (RT#48918) [David + Golden] + + - Auto-detection of abstract and author fixed for mixed-case POD headers + (RT#51117) [David Wheeler] + + - resume() was not restoring additions to @INC added in Build.PL + (RT#50145) [David Golden] + + - When tarball paths are less than 100 characters, disables 'prefix' + mode of Archive::Tar for maximum compatibility (RT#50571) [David Golden] + + - Merging 'requires' and 'build_requires' in Module::Build::Compat could + lead to duplicate PREREQ_PM entries; now the highest version is used + for PREREQ_PM. (RT#50948) [David Golden] + + - Module::Build::Compat will now die with an error if advanced, + non-numeric prerequisites are given, as these are not supported by + ExtUtils::MakeMaker in PREREQ_PM [David Golden] + + +0.35_15 - Thu Dec 17 17:51:22 EST 2009 + + Bug fixes: + + - Make sure PPM tests are skipped if IO::File is too old [David Golden] + +0.35_14 - Thu Dec 17 16:02:14 EST 2009 + + Bug fixes: + + - If not set, the 'module_name' is detected from 'dist_version_from' + or from 'dist_name'. The directory is no longer used. [David Golden] + + - The 'share_dir' property no longer defaults to 'share' and must be + explicitly set instead; this fixes problems for CPAN distributions that + already have a 'share' directory for whatever reason [David Golden] + + - Change t/00-compile.t test for more portability [David Golden] + + - Skip ppm.t if Pod::Html is not available [David Goldenj] + + - Changed guts of inc::latest to work properly on older versions of Perl + [David Golden] + + - Ensure bundle_inc.t doesn't accidentally uninstall the installed M::B + during testing if the user had 'uninst=1' set during Build.PL + [David Golden] + +0.35_13 - Sat Dec 5 11:26:36 EST 2009 + + Bug fixes: + + - Protect against tempfile errors when checking ExtUtils::Installed + [David Golden] + +0.35_12 - Fri Dec 4 23:06:49 EST 2009 + + Bug fixes: + + - Protect inc/ bundling tests against broken ExtUtils::Installed + [David Golden] + +0.35_11 - Thu Dec 3 11:07:44 EST 2009 + + *** API CHANGE *** + + - The old API for prepare_metadata() has been restored to avoid breaking + distributions that were overriding it (e.g. BioPerl), but the method + has been marked deprecated and may be made private or may disappear in + some future version of Module::Build. [David Golden] + + - A new get_metadata() method has been added as a simpler wrapper around + the old, kludgy prepare_metadata() API. [David Golden] + +0.35_10 - Tue Nov 24 22:49:19 EST 2009 + + Bug fixes: + + - bundle_inc.t is more careful about permissions and open filehandles + to avoid failures/skips on Win32 [David Golden] + + - Fix compilation error in Module::Build::Platform::VMS (RT#51766) + [David Golden] + + - Don't generate a MANIFEST.SKIP during distclean and add any generated + MANIFEST.SKIP to cleanup list [reported by Zefram, fixed by David Golden] + + - Module::Build::ModuleInfo version parsing would fail if a module sets + its $VERSION from another module, but the other module is not installed. + We now try to detect such failures, prepend 'lib' to @INC and try again. + [David Golden] + + - MYMETA.yml used to be generated from scratch, overriding any + customizations used to create META.yml. Now, if META.yml exists, that + will be used as the base for MYMETA and only prereq fields will be + updated (to reflect any dynamic configuration); also, 'dynamic_config' + will be set to false and 'generated_by' will be updated [David Golden] + +0.35_09 - Thu Nov 19 01:30:42 EST 2009 + + Bug fixes: + + - The DB package should not be included in 'provides' in META files + [David Golden] + + - Fixed t/xs.t build failures in bleadperl for noexec temp directories + [Nicholas Clark] + + - Adjusted order of @INC in resume() (fixes par.t, ppm.t, xs.t fails): + @INC = @new_additions_to_inc, @saved_additions_to_inc, @default_inc + [David Golden] + + - Skip bundle_inc.t tests if bundled Module::Build for test can't be + tweaked (Works around test crashes on Win2) [David Golden] + + Other: + + - 'C_support' is no longer an optional feature. Modern ExtUtils::CBuilder + and ExtUtils::ParseXS added to the 'requires' list. This ensures that + upgrading Module::Build will upgrade this critical modules. + ExtUtils::CBuilder no longer requires a compiler, so it is "safe" to + require. + +0.35_08 - Mon Nov 16 22:38:28 EST 2009 + + Bug fixes: + + - Multiple tests were failing due to dependency problems. Author + dependencies have been largely removed from core 'requires' into + optional features. Feature prereq detection and messaging have been + expanded and bugs on older Perls have been removed. + +0.35_07 - Sat Nov 14 17:14:39 EST 2009 + + Bug fixes: + + - Auto-detection of abstract and author fixed for mixed-case POD headers + (RT#51117) [David Wheeler] + + - resume() was not restoring additions to @INC added in Build.PL + (RT#50145) [David Golden] + + - When tarball paths are less than 100 characters, disables 'prefix' + mode of Archive::Tar for maximum compatibility (RT#50571) [David Golden] + +0.35_06 - Fri Nov 13 14:51:28 EST 2009 + + Enhancements: + + - Added experimental inc/ bundling; see Module::Build::Bundling for + details. [David Golden and Eric Wilhelm] + + - Clarified that 'apache' in the license attribute indicates the Apache + License 2.0 and added 'apache_1_1' for the older version of the license + (RT#50614) [David Golden] + + Bug fixes: + + - Merging 'requires' and 'build_requires' in Module::Build::Compat could + lead to duplicate PREREQ_PM entries; now the highest version is used + for PREREQ_PM. (RT#50948) [David Golden] + + - Module::Build::Compat will now die with an error if advanced, + non-numeric prerequisites are given, as these are not supported by + ExtUtils::MakeMaker in PREREQ_PM [David Golden] + + - Made MYMETA generation non-fatal if fields required for META.yml + are missing [David Golden] + + - Added Pod::Simple to requirements for manpage support; avoids + problems if a user has a broken Pod::Man/Pod::Simple. (RT#50081) + [David Golden] + + - Won't die if installed Pod::Readme is broken [David Golden] + + Other: + + - Fixed Module::Build::Notes POD [David Golden] + + - Some commands had become silent by default, so added a few short status + messages so users know something actually happened [David Golden] + + - Cleaned up Changes file formatting [David Golden] + + - Removed most PERL_CORE customizations from test files due to + reorganization of dual-life modules in core (RT#49522) [David Golden] + +0.35_05 - Wed Oct 28 17:20:59 EDT 2009 + + Bug fixes: + + - Fix test failure in t/actions/installdeps.t when $^X is not the default + perl [David Golden] + + - Work around $VERSION numbers in ActiveState with multiple underscores + that prevent Module::Build from installing on Win32 [David Golden] + + - Fix bug cleaning compatibility Makefile when older ExtUtils::Manifest is + installed [David Golden with help from David Cantrell] + + Other: + + - Suppressed more warnings from tests [David Golden] + + - Add provisional support for 'package NAME VERSION' syntax added in + Perl 5.11.1 [David Golden] + +0.35_04 - Fri Oct 23 11:20:41 EDT 2009 + + Bug fixes: + + - Fix test failure if IPC::Cmd isn't installed [David Golden] + + Other: + + - Suppressed warning messages from various tests [David Golden] + +0.35_03 - Wed Oct 21 21:20:59 EDT 2009 + + *** API CHANGE *** + + - The prepare_metadata() method used to take a YAML::Node object as an + argument for modification. The method now takes no arguments and just + returns a hash reference of metadata. [David Golden] + + Enhancements + + - Command line options may be set via the PERL_MB_OPT environment + variable (similar to PERL_MM_OPT in ExtUtils::MakeMaker) + + Bug fixes: + + - Updated PPM generation to PPM v4 (RT#49600) [Olivier Mengue] + + - When c_source is specified, the directory scan will include additional, + less-common C++ extensions (RT49298) [David Golden] + + - When module_name is not supplied, no packlist was being written; fixed + by guessing module_name from dist_version_from or the directory name + (just like ExtUtils::Manifest does without NAME) [David Golden] + + - Bumped IO::File prereq to fix binmode failures in PPMMaker on Perl + prior to 5.8.8 [David Golden] + + Other: + + - Replaced use of YAML.pm with YAML::Tiny; Module::Build::YAML is now + based on YAML::Tiny as well [David Golden] + + - Reduced amount of console output under normal operation (use --verbose + to see all output) [David Golden] + +0.35_02 - Mon Sep 7 22:37:42 EDT 2009 + + Enhancements: + + - Added 'needs_compiler' property. Defaults to true if XS or c_source + exist. If true, ExtUtils::CBuilder is also added to build_requires. + [David Golden] + + - File::ShareDir automatically added to 'requires' if 'share_dir' is set + [David Golden] + + - Added 'Build installdeps' action to install needed dependencies via + a user-configurable command line program. (Defaults to 'cpan'.) + [Eric Wilhelm] + + Bug fixes: + + - Failure to detect a compiler will now warn during Build.PL and be a + fatal error when trying to compile during Build. (RT#48918) [David + Golden] + + - Fixed directory sorting failure in share_dir.t [David Golden] + + - Property defaults that are data structures were being assigned as + references to new objects. Changed so that defaults are cloned instead. + (This mostly affects testing, which often creates multiple objects in the + same process) [David Golden] + + - Simplified error message on exit under use_tap_harness [suggested by + David Wheeler] + + - Fixed typemap search to use a dist-level typemap if a typemap is not + found in the directory with the *.xs file; (was manifesting as warnings + in Perl 5.6 tests) [David Golden] + + Other: + + - Replaced guts of new_from_context(). Build.PL is now executed in a + separate process before resume() is called. (This is generally only of + interest to Module::Build or toolchain developers) (RT#49350) [David + Golden, Eric Wilhelm, Ken Williams] + + - Revised test helper classes to fix potential bugs and add new features + to make writing tests simpler and easier. Changes incorporated into + t/README.pod and t/sample.t as examples for new testing. [David Golden] + +0.35_01 - Mon Aug 31 12:11:10 EDT 2009 + + Enhancements: + + - Generates MYMETA.yml during Build.PL (new standard protocol for + communicating configuration results between toolchain components) + [David Golden] + + - Added 'share_dir' property to provide File::ShareDir support; + set automatically if a directory called 'share' exists + [David Golden] + + Bug fixes: + + - Fix the t/destinations.t fix. [David Golden, with thanks to Eric Wilhelm] + + - Fix recursive test files in generated Makefile.PL (RT#49254) [Sawyer X] + + - Guard against trying :utf8 when :utf8 isn't available + + - The "test" action now dies when using the 'use_tap_harness' + option and tests fail, matching the behavior under Test::Harness. + (RT#49080) [initial patch from David Wheeler; revised by David Golden] + + Other: + + - Added t/README.pod and t/sample.t to guide developers writing new tests + [David Golden, with some code from Eric Wilhelm] + + - Module::Build::Compat 'passthrough' style has been deprecated. Using + 'passthrough' will issue warnings on Makefile.PL generation. See + Module::Build::Compat documentation for rationale. + +0.35 - Thu Aug 27 09:12:02 EDT 2009 + + Bug fixes: + + - Fix t/destinations.t segfault on 5.6.2 [David Golden] + +0.34_06 - Sat Aug 22 21:58:26 EDT 2009 + + Bug fixes: + + - Multiple test fixes for OS2 [Ilya Zakharevich] + + - Generated.ppd files use :utf8 if possible (RT#48827) [Olivier Mengue] + + - Fixed preservation of custom install_paths on resume (RT#41166) + [David Golden] + + - Warn instead of crashing when Pod::Man tries to create files with + colons on vfat partitions on unix (RT#45544) [David Golden] + +0.34_05 - Sun Aug 9 22:31:37 EDT 2009 + + Bug fixes: + + - When auto_configure_requires is true (the default), Module::Build will + only add last 'major' version of Module:Build (e.g. 0.XX) to + configure_requires to avoid specifying a minor development release not + available on CPAN [David Golden] + +0.34_04 - Sat Aug 8 11:02:24 EDT 2009 + + Other: + + - Added documentation warning that 'get_options' should be capitalized + to avoid conflicting with future Module::Build options and changed + the examples accordingly. + +0.34_03 - Sat Aug 8 07:39:16 EDT 2009 + + Bug fixes: + + - Fixed failing xs.t if /tmp is mounted noexec (RT#47331) [David Golden] + + - Fixed failing debug.t on VMS (RT#48362) [Craig Berry] + + - Prevent par.t from dying on error in .zip extraction [David Golden] + + - Fixed potential runthrough.t failure on 5.6.2 [David Golden] + + Other: + + - Archive::Tar changed from 'requires' to 'recommends' so non-authors + without IO::Zlib can still use Module::Build to install modules + [reported by Matt Trout, fix by David Golden] + +0.340201 - Sun Aug 9 22:11:04 EDT 2009 + + Other: + + - Version bump for Perl core for 5.10.1 release; no other changes + +0.34_02 - Sun Jul 26 22:50:40 EDT 2009 + + Bug-fixes: + + - Bundled Module::Build::Version updated to bring into sync with CPAN + version.pm 0.77 [John Peacock] + +0.34_01 - Sat Jul 18 16:32:09 EDT 2009 + + Enhancements: + + - Added --debug flag to trace Build action execution (RT#47933) + [David Golden] + + Bug-fixes: + + - Bundled Module::Build::Version version code updated to fix unsafe use + of $@ (RT#47980) [John Peacock] + +0.34 - Tue Jul 7 16:56:47 EDT 2009 + + No changes from 0.33_06 + +0.33_06 - Sun Jul 5 10:11:40 EDT 2009 + + Bug-fixes: + + - Bundled version code will use pure Perl on 5.10.0 to work around + a corner case involving eval and locale [John Peacock] + + - Reversed VMS patch from 0.33_03 [Craig Berry] + + - PL_files in Build.PL that are in the bin/scripts directory should not be + installed as if they are scripts (fixed for case-tolerant systems). + [David Golden, reported by Craig Berry] + +0.33_05 - Sun Jun 28 22:06:49 EDT 2009 + + Enhancements: + + - New 'auto_configure_requires' parameter (default 1) controls + whether Module::Build should add itself to configure_requires + in META.yml if not specified in Build.PL [David Golden] + + Bug-fixes: + + - The default MANIFEST.SKIP created by the "manifest" action + was out of date. It will now use the installed MANIFEST.SKIP + and add some Module::Build and distribution specific items + to it. [Michael Schwern] + + Other: + + - configure_requires do not necessarily need to be in requires + or build_requires; warning to that effect has been removed + [David Golden] + +0.33_04 - Fri Jun 26 07:09:06 EDT 2009 + + Bug-fixes: + + - Don't try utf8 YAML I/O on Perl 5.6 [David Golden] + + Other: + + - configure_requires added to prereq report (RT#47254) [Curtis Jewell] + + - updated Module::Build::Version to match forthcoming version.pm 0.77 + (RT#47256) [John Peacock] + + - skips xs.t and ppm.t when perl was not compiled with dynamic loading + since Module::Buld does not support static linking (RT#46178) + [David Golden] + + - skip failing test in par.t if Archive::Zip is broken [David Golden] + + - Added YAML utf8 patch in 0.33_03 changes list + + - Added attribution for patches in 0.33_03 changes list + +0.33_03 - Mon Jun 22 17:22:56 EDT 2009 + + Bug-fixes: + + - Removes Module::Build from its own configure/build_requires + [David Golden] + + - ConfigData->feature() confirms that modules actually load successfully, + not just that they are present. (RT#43557) [David Golden] + + - Module::Build::Compat handling of INSTALL*LIB (RT#43827) + [Tony Payne, David Golden] + + - Module::Build::Compat and recursive test files (RT#39171) [Dave Rolsky] + + - Fixed bug linking non-standard XS names on Windows (RT#38065) ["snaury"] + + - Run PL files that don't generate any file (RT#39365) + [Matisse Enzer, David Golden] + + - HTML generation failure no longer fatal (RT#36660) [David Golden] + + - realclean might not delete Build.bat on Windows (RT#43863) + [Roy Ivy, David Golden] + + - include_dirs parameter now works correctly when given a single + string argument (RT#40177) [David Wheeler] + + - Lots of spelling fixes in the POD (RT#45528r) [Lars Dieckow] + + - On Unix-like systems, tilde expansion is more liberal in username + characters accepted (RT#33492) [Jon Jensen] + + Other + + - On MSWin32, bumped File::Spec prereq to 3.30 for a variety of fixes + + - Add support for VMS in Unix compatibility mode (RT#42157) + [John E. Malmberg + + - Added a can_action($name) method (RT#45172) [brian d foy] + + - Documented that subclass methods should not permanently change + current directory (RT#46919) [David Wheeler] + + - META.yml encoded in UTF-8 (RT#43765) [Olivier Mengue] + +0.33_02 - Mon Jun 15 12:23:55 EDT 2009 + + Bug-fixes: + + - Fixed tests for bleadperl + +0.33_01 - Sat Jun 13 20:24:42 EDT 2009 + + Bug-fixes: + + - Fixed RT#42724: consolidated VMS fixes [patch by Craig Berry] + + - Fixed RT#46338: passthrough Makefile.PL cleans Makefile during distclean + + - Fixed RT#45700: t/compat.t for HP/UX make + + Other: + + - Adds current Module::Build to configure_requires (and build_requires) + if no configure_requires is specified + + - Always normalizes version number tuples in META.yml (e.g. 'v1.2.0') + (Partially addresses RT#46150) + + - Normalizes a generated dist_version (e.g. from a .pm file) -- + dist_version set manually in Build.PL is not normalized + + - Documentation update for create_license + + - Minor POD cleanup + +0.33 - Sun May 3 20:16:34 PDT 2009 + + Bug-fixes: + + - Fixed RT#45462: Compat.pm needs to reference 'Build.com' on VMS + [patch from John Malmberg] + + - Fixed RT#45461: ext.t on VMS [patch from John Malmberg] + + - Fixed RT#43861: Module::Build::PPMMaker has broken PPD name + versioning for v5.10+ + +0.32_01 - Tue Apr 14 17:14:22 PDT 2009 + + Bug-fixes: + + - Module::Build::Compat had stopped adding "PL_FILES => {}" when no + PL_files property was set in Build.PL; restored old behavior and fixed + tests and documentation related to this issue [David Golden] + + - Caches ExtUtils::CBuilder object in a temporary stash instead of properties + + - Fixed undef resources->license in META.yml (RT #44453). + + - Use $^X instead of 'perl' in t/ext.t [David Golden] (RT #43485) + + Other: + + - Generated META.yml will indicate version 1.4 of the specification + (RT #37478) [patch from Alexandr Ciornii] + + - Archive::Tar now the default for generating tarballs on all platforms + (avoids problems with incompatible tar binaries) + + - dist_dir() now uses dist_name() and dist_version() accessors rather + than using its properties directly. [brian d foy] (RT #45038) + +0.32 - Wed Feb 25 17:40:02 PST 2009 + + No changes since 0.31_04. + +0.31_04 - Fri Feb 20 11:04:59 PST 2009 + + Other + +- Bumped Test::Harness prereq to 3.16 for latest PERL5LIB fixes (solves + test failures when installing Module::Build using CPANPLUS::Dist::Build) + [David Golden] + +0.31_03 - Sun Feb 8 14:54:01 PST 2009 + + Enhancements + + - added a "prereq_data" action that prints a Perl data structure of + all prerequisites; can be loaded by external tools using eval() + [David Golden] + + Bug-fixes + + - 'fakeinstall' action warns and skips without ExtUtils::Install 1.32+ + [David Golden, reported by Zefram] + + - allows Module::Build version mismatch when installing self; works around + limitations in CPANPLUS::Dist::Build [David Golden] + +0.31_02 - Tue Jan 27 09:16:43 PST 2009 + + Other + + - tests now use File::Temp (added to build_requires); appears to fix + Win32 testing heisenbug on directory removal during high system loads + + - use_tap_harness.t will skip unless a release version of TAP::Harness + is installed + + - improved diagnostics to ensure_blib() tests in t/lib/MBTest.pm + + Compat + + - passthrough Makefile.PL will now play nice with cpantesters' on + exit(0) (RT#32018) [Eric Wilhelm] + + Bug Fixes + + - fix for doubling-up of --prefix (RT#19951) + +0.31012 - Wed Jan 14 01:36:19 PST 2009 + + Bug Fixes + + - t/tilde.t maybe actually fixed on MSWin32 now. + +0.31011 - Mon Jan 12 21:57:04 PST 2009 + + Bug Fixes + + - t/tilde.t had been failing on MSWin32 (RT#42349) + +0.3101 - Mon Jan 12 13:52:36 PST 2009 + + Other + + - added 'mirbsd' as a Unix-type OS [BinGOs] + + - added 'haiku' as a Unix-type OS (backported from bleadperl) + + - skips certain tests on VMS (backported from bleadperl) + + - sets $^X to absolute path in tests (backported from bleadperl) + +0.31 - Sat Dec 20 15:03:33 2008 + + Deprecations + + - Use of attributes as class methods is deprecated (this was never a + documented feature and appears to only have worked accidentally.) + +0.30_02 - Mon Dec 15 12:23:55 PST 2008 + + Bug Fixes + + - make Software::License dependency "softer". + +0.30_01 - Thu Dec 11 18:25:53 PST 2008 + + New Docs + + - Added a recipe for writing a new action to the Cookbook + + - Added a recipe for bundling Module::Build to the Cookbook. + + Doc Fixes + + - Clarified dist_abstract search procedure in API.pod (RT#41056) [Mario + Domgoergen] + + Bug Fixes + + - Workaround HARNESS_TIMER env issue in t/compat.t (RT#39635) + + - Fix ~ expansion when $HOME is different from /etc/passwd as + when running sudo. [rt.cpan.org 39662] + + - Fixed a small POD error in the Cookbook. [Damyan Ivanov] + + - Unset group/other write permission bits when using Archive::Tar to + build the dist tarball. (RT#39804) [David Golden] + + Enhancements + + - We now support a 'create_license' parameter to new() that will + create a LICENSE file during the 'dist' phase with the full text of + the license. This requires Software::License on the author's + machine. + + - Added lgpl2/lgpl3 entries to the supported licenses (RT#40532). + + - Support for validating properties with a check subref. [David + Wheeler] + + Test Fixes + + - Defend against more stray environment variables interfering + with the tests. + + Other + + - Updated our embedded version.pm to 0.76, enhanced documentation on + dist_version_from. [John Peacock] + +0.30 - Thu Sep 25 20:57:36 2008 + + - First non-beta release since April 2007. In the meantime, Sarkozy + became president of France, the 35W bridge fell in Minneapolis, + Phelps won a lot of gold, a new tribe of indigenous people was + discovered in the Amazon, and Bob Barker stopped doing The Price Is + Right. As of this moment though, the U.S. economy still hasn't + collapsed completely. + +0.2808_05 - Thu Sep 18 23:30:39 PDT 2008 + + - Skip test in t/ext.t which tickles shellwords() in Text::ParseWords + below 3.23 [David Wheeler, Ken] + + - Fixed some shell-quoting issues in do_system() on Windows [Ken, + Schwern, reported by Curtis Jewell] + + - Fixed t/xs.t failure for missing 'const char *' typemap in 5.6 + [Schwern] + + - Added build_requires for Test::More 0.49 and Test::Harness 2.03. + Removed bundled Test::More (was not working for 5.005x anyway). + [Schwern] + + - Minimum required perl version is now 5.6.1. [Schwern] + +0.2808_04 - Thu Sep 11 22:51:27 PDT 2008 + + - Backed-out incompatible Module::Build::ModuleInfo change (first in + 0.2808_02.) + +0.2808_03 - Mon Sep 1 14:43:27 PDT 2008 + + - Made adjustments for the format changes of recent Test::Harness + output. [Nicholas Clark] + + - Fixed the documentation for script_files to indicate that we search + bin/ for scripts by default. It has been this way for several + years. [Spotted by Ron Savage] + +0.2808_02 - Wed Jul 9 16:45:08 PDT 2008 + + - Experimental support for TAP::Harness with --use-tap-harness option + and the tap_harness_args property. [David Wheeler & Eric Wilhelm] + + - Added test_file_exts property for main-run tests other than '*.t'. + [David Wheeler] + + - Fixed getcwd()/rmtree() failure case on 5.10+mac where something is + unhappy about all of the tests deleting their distgen directory + before leaving it. [Eric Wilhelm & David Wheeler] + + - Improved support for parsing qv() in modules' $VERSION + declarations, and made $VERSION-parsing errors more verbose. [Jos + Boumans] + + - Integrated an omnibus patch for various VMS fixes. [Craig Berry & + John E. Malmberg] + + - Some versions of Test::Harness (or something) seem to not be + stripping the ".t" suffix when outputting test reports, which was + causing one of our tests in t/compat.t to fail. Fixed. [Spotted by + a smoke tester] + + - Most Unix platforms seem to allow hyphens in usernames, so we honor + this in our de-tilde-fying methods now. [Spotted by s-murata] + + - If there are multiple assignments to the $VERSION variable in + someone's module and this generates warnings, tell the user what + line number the problem is at. + + - Added 'gnu' and 'gnukfreebsd' as Unix variants. [Niko Tyni] + + - Fixed a couple bugs in how we quote arguments to external processes + when they have to pass through the shell. Also much more + thoroughly tested our quoting now. + + - Edited the Module::Build::API docs prose about the 'license' field + in response to some comments on the module-authors mailing list. + + - Fixed a typo in some example code in the Cookbook. [Jeremy Leader] + + - Custom typemaps were being looked for in places that don't quite + exist; fixed. [Michael G Schwern] + + - QNX/Neutrino is now considered to be Unix. [rt.cpan.org 32214] + + - Added 'gpl2' and 'gpl3' to the list of valid licenses. [Allen + Engelhardt] + + - Fixed our Data::Dumper wrapper's sensitivity to users who might set + $Data::Dumper::Terse. [Spotted by Dominique Dumont] + + - Documented the fix_shebang_line() method. [Elliot Shank] + + - Applied the 'const' modifier to version() and xs_version() XS + functions we use during testing. [Robin Barker] + + - Fixed processing of INC=, POLLUTE=, INSTALLDIRS=, and LIB= for + passthrough/small Makefile.PLs. + + - perl Build.PL --sign=1 now signs. [Michael G Schwern] + + - Fixed processing of INSTALLDIRS=whatever for compatibility + Makefiles. [Spotted by John Peacock] + + - Zillions of special-cases have been added in Compat.pm for dealing + with the special Makefile system on VMS. [John E. Malmberg] + + - Fixed some stuff in how VMS command-args get quoted. [John E. Malmberg] + + - VMS now overrides localize_file_path() and localize_dir_path() so + we don't need to do special stuff in the general case. [John + E. Malmberg] + + - Added a few more VMS-specific entries to the default MANIFEST.SKIP + file that (sometimes) gets created during the 'manifest' + action. [John E. Malmberg] + + - Fixed a catdir() that should have been a catfile() when creating a + ppmdist. [John E. Malmberg] + + - Removed some assumptions about what makefiles are called (not + necessarily "Makefile") and how they take their arguments, to get + VMS tests working better. [John E. Malmberg] + + - Fixed our check for Archive::Tar in the t/runthrough.t test, which + fixes a common failure on Win32. [Spotted by Chris Williams] + + - Fixed a File::Spec mal-ism in t/destinations.t [Craig A. Berry] + + - Exposed the internal ExtUtils::CBuilder object as part of our API, + via the cbuilder() method. [Zefram] + + - Upgraded to version.pm 0.74 (fixes bug #30004.) + + - Overwrite core (post-5.9.4) Module::Build installs (bug #20528.) + + - Pass quiet() option to ExtUtils::CBuilder object. + +0.2808_01 - Wed Oct 24 11:51:25 2007 + + - All .pm files in the Module-Build distribution (except for + M::B::Version.pm, which is kind of tied to version.pm) now have the + same $VERSION number explicitly specified. + + - When checking prerequisites, the required version of perl is now + checked before we start finding the $VERSION declaration of the + distribution, which results in much more intuitive error messages + e.g. if the author is using 5.6-isms in their declaration but the + user doesn't have 5.6. [Slaven Rezic] + + - Added 'artistic_2' license, corrected 'lgpl' license url (bug #29783) + [David Thomas] + + - VMS find_perl_interpreter() is just $^X (bug #29810) [Craig A. Berry] + + - Some large VMS fixes, mostly having to do with the non-case- + preserving nature of most VMS filesystems, but also correcting for + illegal characters in VMS file specs. [John E. Malmberg and Craig + A. Berry] + + - Fixed the _detildefy() method on VMS. [John E. Malmberg and Craig + A. Berry] + + - We now use a much more reliable method when Data::Dumper-ing saved + state data. [Yves] + + - When a module had 0.000 as its version, a few places in the code + thought the module had no version at all. This is now + fixed. [Andrew "Zefram" Main] + + - When finding the default set of script_files, we now compute them + as relative paths, not absolute. [Spotted by Curtis "Ovid" Poe] + + - Got rid of a call to eliminate_macros, which isn't needed in + Module::Build since there is no external make utility involved. + Override expand_test_dir to make up for the fact that the + home-grown glob() returns absolute, not relative, paths. [Craig + A. Berry] + + - Fixed a catdir() that needed to be catfile() in the .packlist + creation code. [John E. Malmberg] + + - If a *.PL file ended abnormally during the build, processing should + have stopped, but it didn't. Fixed. [Matthew Cast and David + Golden] + + - Module::Build::Compat adds "require 5.XXXXX" to Makefile.PL when + 'perl' is specified as a 'requires' prerequisite [David Golden] + + - Refactored t/compat.t for modularity and transparency; added + labels for all tests; supressed subprocess output to + STDOUT and STDERR [David Golden] + + - Fixed bug in perl_version_to_float when version is already a float + [David Golden] + + - Removed a mention of $build->{config} from the documentation, the + official interface to Config.pm settings is now via the + $build->config() and has been for some time. [Suggested by Michael + Schwern] + + - Tweaked some text in the Cookbook to bring it into the modern age, + and added a recipe for accessing Config.pm settings. [Ibid] + + - Lots of POD link/readability improvements to the Module::Build::API + documentation [Salve J. Nilsen] + + - Added configure_requires as a new type of prereq. [Suggested by Adam + Kennedy] + + - Patch 31156 from bleadperl: some filename dot and extension help + for Module::Build on VMS. [Craig Berry] + + - Reworked the _detildefy() method so it doesn't depend on glob() + anymore. This gets rid of a problem with spaces or other special + shell characters in things like 'prefix' or 'install_path' + entries. [Prodding by Eric Wilhelm] + + - Added midnightbsd to the list of Unix-like OSes we know about + [Rafael Garcia-Suarez] + +0.2808 - Sat Apr 28 12:59:43 2007 + + - Added is_vmsish(), is_windowsish(), and is_unixish() boolean + convenience functions. Fixes some test failures on platforms where + $^O is set to a value we don't know about (like 'gnu'). + + - Upgraded to version.pm 0.7203. [John Peacock] + + - Support get_action_docs() =head2 style. [ewilhelm] + + - Workaround Test::Pod::Coverage @INC bug. [Eric Wilhelm] + + - Fixed the command-line args --extra_compiler_flags and + --extra_linker_flags so they properly shell-split their arguments. + +0.2807 - Sat Mar 24 22:19:02 2007 + + - Upgraded to version.pm 0.71. [John Peacock] + + - Removed a couple small constructs in the tests ("use warnings;" and + "qw$foo bar$[1]") that caused test failures under perl 5.005. + + - Added support for an explicit default value of undef in prompt(). + [Eric Wilhelm] + + - Improved our prompt() method, which could sometimes hang before the + user got a chance to see a prompt. [Andreas Koenig] + + - Added a note about --allow_mb_mismatch to the error message that + happens right before someone might want to use that parameter. + + - Added DragonflyBSD to the list of known Unix OSes. + + - get_action_docs() dies on error rather than twiddling $@ + + - Made ModuleInfo's _evaluate_version_line() compatible with 'use + version ...$VERSION' lines. [Eric Wilhelm] + + - Added some verbiage in Module::Build::API that officially blesses + the _build/prereqs file for external consumption. [Suggested by Andreas Koenig] + + - Added test profiles support via the test_types property and "testall" + target. [Eric Wilhelm, Jeff Lavallee] + + - Use syscopy() on OS/2 in copy_if_modified() so we make sure to + overwrite any existing target file. [Ilya Zakharevich] + + - Removed seemingly silly '~~' test in t/tilde.t. + + - In our test-time utility library t/lib/MBTest.pm, we need to know + about a few .exe-like extensions on OS/2. [Ilya Zakharevich] + + - In t/ppm.t, use DynaLoader::mod2fname() (if available) to determine + the correct translation of our test module's name into a DLL + name. [Ilya Zakharevich] + + - Avoid an unlink() error on OS/2 when fixing shebang lines. [Ilya + Zakharevich] + + - When we're protecting the world from the evils of long RedHat + $ENV{PERL5LIB} variables, don't assume $ENV{PERL5LIB} is already + defined. This gets rid of a huge number of warnings for some + people. [Dave Rolsky] + +0.2806 - Fri Dec 15 22:20:14 2006 + + - On some systems (haven't identified the actual problem yet) + $ENV{PERL5LIB} can grow to enormous enough sizes that we can't + launch any more subprocesses because the environment table is full. + This is the now-infamous "Couldn't run Build.PL: Argument list too + long" error. Now we detect such situations and trim the directory + list to only include directories that actually exist, listed only + once each. Not the ideal solution, but it should work. + + - Silence a warning in M::B::ModuleInfo that happens when the author + is using the "$VERSION = eval $VERSION" idiom. + + - When running the 'testcover' action, do "cover --delete" if any of + the test files have changed (we already did so if any of the code + under test has changed). [Suggested by Chris Dolan, RT #23584] + + - Fixed a broken link in the documentation about PREFIX. [Spotted by + David Steinbrunner] + + - Changes to do_system() & friends on VMS to get system calls working + much better there. [Craig Berry] + + - Added the "pardist" target which creates a PAR binary distribution + akin to a PPM distribution. [Steffen Mueller] + + - Added the Interix platform as a Unix variant. [Stephen Hartland] + + - Improved the error message we emit when a distribution contains XS + files but the user has no C compiler. [Suggested by Andreas Koenig] + +0.2805_01 Thu Sep 7 21:57:29 CDT 2006 + + - Because of a weird behavior of YAML::Node, any distribution that + used version.pm objects to define their versions was generating the + wrong syntax for the versions in their META.yml file. They will + now appear as strings like v3.42.1 or similar, including the + leading v. + + - Upgraded to version 0.67 of version.pm. [John Peacock] + + - Added a contrib/ directory with a bash completion function for M::B + actions and switches. [Julian Mehnle] + + - When we eval() the embedded version.pm code we will now die() if + the eval() was unsuccessful, rather than continuing blindly on and + dying mysteriously later. + + - Added a 'retest' action that lets users run the current regression + tests on a previously-installed version of a distribution. + + * Instead of storing an entire dump of the Config.pm hash in the + _build/ directory upon startup, we now just store any overrides the + user or author has specified. Note that if you were doing anything + you weren't supposed to be doing, like poking around in the + internals of $buld->{config}, your code might break, so I've put + the asterisk of incompatibility on this one just to cover my + tuchus. [Idea originally by Randy Sims] + + - Made copying files via copy_if_modified() a little less chatty. + +0.2805 Sat Jul 29 22:01:24 CDT 2006 + + - We now embed a copy of version.pm right in the + Module::Build::Version source code, with John Peacock's blessing, + in case the user has a rough time installing version.pm. This + helps alleviate troubles people were still having with working out + a seemingly circular dependency (even though version.pm now ships + with a standard Makefile.PL too). A version.pm >= 0.661 installed + on the system will take precedence over our bundled one. [John + Peacock] + + - Fix some test warnings (or failures?) related to version.pm + numification. [John Peacock] + + - The top-level 'version' entry in META.yml files we'd generated was + in the wrong format (it was being treated as a version.pm object + rather than a serialized copy) due to a weird YAML::Node issue. + Fixed. + + - Don't 'use base qw(version)' anymore in our M::B::Version wrapper, + just set @ISA directly, because some people have reported that the + 'use base' line is croaking. + + - Added an 'allow_mb_mismatch' parameter to suppress the startup + check that ensures the version of M::B currently running is the + same as the one initially used to run the Build.PL. Use with + caution. + + - Module::Build::ModuleInfo will no longer detect things that look + like $VERSION assignments after an __END__ or __DATA__ token. + + - Updated documentation to mention the new mailing list on perl.org + rather than the old one on sourceforge. + +0.2804 Sun Jul 16 16:41:25 CDT 2006 + + - Added 'use version;' in Module::Build::Version, because some + versions of base.pm won't automatically load version.pm when we do + 'use base qw/version/;'. [Spotted by Erik Tank] + +0.2803 Sat Jul 15 08:26:34 CDT 2006 + + - The META.yml file in the last release was all screwed up, so the + distribution wasn't indexed properly. Fixed in this release. + +0.2802 Fri Jul 14 22:40:34 CDT 2006 + + - Added reliance on version.pm, which means we should deal much + better with the wide range of version specifications one finds on + CPAN. This is made possible by recent releases of version.pm that + give the user a pure-perl option, so installing version.pm + shouldn't be too onerous for most users. [John Peacock] + + - We should be accepting the default when we're in unattended mode, + not acting dumb and ignoring both the default and the [empty] + answer from the user. Fixed. [Spotted by Nik Clayton] + +0.2801 Sun May 21 00:07:40 CDT 2006 + + - Module::Build::Compat's emulation of INC is incorrectly prepending + a -I to the value of INC. This is incorrect because there should + already be a -I on the value. I.E. it's "perl Makefile.PL INC=-Ifoo" + not "perl Makefile.PL INC=foo" so Compat should not prefix a -I. + [Michael Schwern] + + - Native batch scripts under Windows should not be converted by + pl2bat. [Spotted by Ron Savage] + + - Tweaked the way we determine whether a file is executable on Unix. + We use this determination to decide whether to make it executable + during installation. [Julian Mehnle] + + - Replaced a vestigial 'next' with 'return' now that the code is in a + subroutine (htmlify_pods()), not a loop. [Ron Savage] + + - Fixed a guaranteed failure in t/signature.t when TEST_SIGNATURE was + set. [Eric R. Meyers] + + - Fixed a test failure that occurred when testing or installing in + unattended mode - the code to test whether unattended mode and + attended mode are working properly was assuming that we started out + in attended mode. [Steve Peters] + + - Improved our stand-in YAML generator that we use to generate + META.yaml when authors don't have a copy of YAML.pm installed on + their machine. It was unable to handle things like embedded + newlines in the data, now it has a much more extensive escaping + mechanism. [Stephen Adkins] + + - Revised the docs for --prefix and PREFIX. [Michael Schwern] + +0.28 Thu Apr 27 22:25:00 CDT 2006 + + - When y_n() or prompt() are called without a default value and the + build seems to be unattended (e.g. in automatic CPAN testing), we + now die() with an error message rather than silently returning + undef for prompt(), or looping indefinitely for y_n(). + + - When searching for '.modulebuildrc', return the first HOME-like + directory that actually contains the file instead of the first + existing directory. Document the search locations and the order + searched. [Spotted by David Golden] + + - Split the API documentation out of Module::Build::Authoring into + its own document: Module::Build::API. + + - We should not emit a warning if a Module::Build subclass is + required in a Makefile.PL that is not bundled in the current + distribution; it may be installed on the user's system. [Spotted by + Tyler MacDonald] + + - copy_if_modified() now preserves the executable bit of the source + file. [Spotted by Julian Mehnle] + + - Fixed compatibility of our screen-scraping the Test::Harness output + so we can recognize the most recent Test::Harness version. [Steve + Hay] + + - Backing out a requirement added in 0.27_06 on the method y_n() + to always include a default. This behavior would cause existing + build scripts to start failing. We now fail with a missing default + only when $ENV{PERL_MM_USE_DEFAULT} is set because there is no + reasonable default. + + - Make install_types() method smarter with respect to custom install + types. + + - Add documentation for the install_base_relpaths() and + prefix_relpaths() methods. Improved their usage for a public API, + and added tests. + +0.27_10 Tue Mar 28 22:50:50 CST 2006 + + - Added the create_packlist property, default true, which controls + whether packlist files will be written during installation. This + was already part of Module::Build 0.2609, but for some reason we've + forgotten it in the 0.27_xx series. [Spotted by Steve Kirkup] + + - Document the versions of Module::Build where each feature, action, + constructor argument, and method was first publicly documented. + + - More fixes for find_perl_interpreter() to work with BSD flavored + UNIX: Ensure we always return absolute paths; throw an exception + upon failure to find correct interperter; document everything. + + - We now include our own YAML.pm work-alike that we can use when the + real YAML isn't installed. We might soon even start using it when + YAML is installed, because the YAML API and dependency chain have + been changing in unfavorable ways lately. [Stephen Adkins] + + - Fixed some shell-argument-quoting issues on VMS. In the process, + we have added some support for avoiding tripping over + shell-argument-quoting issues on other platforms too. [Initial + patch by Craig A. Berry] + +0.27_09 Sat Mar 11 22:48:54 EST 2006 + + - Fixed find_perl_interpreter() so we can find the perl executable + when running from uninstalled perl even when $^X contains a + relative path. [Yitzchak Scott-Thoennes] + + - Fixed warning message where we were printing the wrong field names. + [Chris Dolan] + + - Added a 'testpodcoverage' action that runs a POD coverage check for + all modules in the distribution. [Yanick Champoux] + + - Added a Cookbook example of subclassing to modify an action. [Dylan + Martin and David Golden] + + - When building HTML documentation, we were opening the POD file and + not checking whether the open succeeded, which of course caused + problems down the line if it failed. Now we do "or die(...)" like + everywhere else. [Spotted by Joerg Braun] + +0.27_08 Fri Mar 3 21:22:41 CST 2006 + + - Due to shell quoting issues and differences in syntax between + various flavors of Windows, the code for the 'pl2bat' utility + distributed with Perl has been incorporated into M::B::P::Windows. + [Thanks to Dr Bean and Ron Savage for help testing and isolating + the problem.] + + - Modify add_build_element() so that it only adds elements if they + don't already exist. [David Wheeler] + + - Fixed a bug in the 'pass-through' Makefile.PL in which we would die + if CPAN::Shell->install returned false, but apparently this return + value is unreliable. Now we only die if the module is actually + unavailable after installation. + + - Fixed testing problems on VMS related to non-case-preserving + filesystems. We now bundle Tie::CPHash in the distribution (just + for testing purposes, it doesn't get installed) to help with + this. [Craig Berry and Yitzchak Scott-Thoennes] + + - We incorrectly documented the 'dynamic_config' flag in the META.yml + file as having a default value of false, but according to the + META.yml spec (which, for heaven's sake, we wrote) its default + value is true. Fixed. [Spotted by Adam Kennedy] + + - The have_c_compiler() method was dying if the ExtUtils::CBuilder + module wasn't around, which is obviously an unhelpful thing to do. + Now it just returns false. [Spotted by John Peacock] + + - Fix detection of $VERSION expressions that are not + assignments. [Spotted by Chris Dolan] + + - Obfuscate one of our constructs that uses a $VERSION variable, + because it was getting picked up by ExtUtils::MakeMaker's + version-finder. [Spotted by Randal Schwartz] + + - The config_data script for querying and/or setting a module's + config data was forgetting to call write() after setting config + values (though setting feature values was working fine). + Fixed. [Brian Duggan] + + - On Windows, remove the pl2bat generated 'Build.bat' script without + the annoying "The batch file cannot be found." error. [Solution + provided by RazTK and foxidrive on newsgroup alt.msdos.batch] + + - Our version comparisons should now work correctly with modules that + use version.pm to delcare their versions (e.g. "our $VERSION = + version->new('1.0.0')"). [John Peacock and Ron Savage] + + - We now create a Build.bat script on versions of Windows where it + makes sense. [Yves] + + - Fixed the verbiage around choosing the correct make-alike on + different platforms to suggest using 'perl -V:make'. [Suggested by + anonymous user] + +0.27_07 Wed Feb 1 20:07:45 CST 2006 + + - The notes() method now returns the new value when called with two + arguments, just like when it's called with one argument. [Tyler + MacDonald] + + - The notes() method now distinguishes among the values undef, 0, and + the empty string, where previously it didn't. [Tyler MacDonald] + + - We now unshift(@INC) rather than push(@INC) for the directory where + a build subclass lives, so that we're sure to pick up the right + version and not some already-installed version. [perlmonkey] + + - The SIGNATURE file for version 0.27_06 (and I'm sure for lots of + versions before that too!) was messed up, since we were modifying + some files after signing. This has been band-aided for the time + being by signing twice. [Reported by Chris Dolan] + +0.27_06 Mon Jan 23 21:44:54 CST 2006 + + - Fixed an undefined-variable warning when building the META.yml file + and the author hasn't used the 'module_name' mechanism. [Chris Dolan] + + - We should now work with recent (> 0.49) versions of YAML.pm when + creating the META.yml file. [Yitzchak Scott-Thoennes] + + - The y_n() method now requires the default parameter, and the + prompt() and y_n() methods have been improved with respect to + how they behave/detect when there is no user to ask. We're now + more consistent with MakeMaker, including respecting the + PERL_MM_USE_DEFAULT environment variable. [Tyler MacDonald and + Yitzchak Scott-Thoennes] + + - When building a README file using Pod::Text, work around a bug in + Pod::Text 3.01, which expects Pod::Simple::parse_file to take input + and output filehandles when it actually only takes an input + filehandle. [Yitzchak Scott-Thoennes] + +0.27_05 Thu Jan 12 17:39:21 CST 2006 + + - In t/common.pl, we were attempting to let the user's installed + Test::More take precedence over ours, but getting thwarted by all + the test scripts' loading Test::More beforehand. Fixed. [Spotted + by Yitzchak Scott-Thoennes] + + - In various test scripts, we were outputting some strings that + weren't strictly conformant with Test::Harness's expected input, + though it didn't actually cause problems. Now we're more + conformant, though not yet strict. [Spotted by Yitzchak + Scott-Thoennes] + +0.27_04 Fri Dec 23 10:43:34 CST 2005 + + - Removed experimental feature that extended the prerequisite system + to apply ('requires', 'recommends', and 'conflicts') prereqs to all + actions. Most of the internal extensiblity has been retained so + that prereq types can easily be added, more selectively. + + - Added a 'prereq_report' action that shows the user a well-formatted + list of all prerequisites, the versions required, and the versions + actually installed. [David Wheeler] + + - Clarified the directory name that's created during the 'distdir' + action. [Suggested by Tyler MacDonald] + + - Fixed a bug when creating the META.yml file without the help of + YAML.pm - some common strings weren't quoted & escaped properly. + Now only some uncommon ones are. [Spotted by Joshua ben Jore] + + - Fixed a bug in which an "UNINST=1" argument specified to a + passthrough Makefile's "make install" wasn't actually seen by + Module::Build. + + - Rather than dying when the Build script is run from the wrong + directory, it now simply chdir()s into the right directory and + keeps going. [Suggested by Dominique Quatravaux] + + - Added an "Examples on CPAN" section to the cookbook, with an + initial entry pointing to John Peacock's SVN-Notify-Mirror + distribution. + + - Add an invoked_action() method to return the name of the original + action invoked by the user. + + - Add 'meta-spec' field to the generated META.yml file, including the + version of the specification followed by the current Module::Build + and the url where the specification can be found. + + - Introduced two actions, 'html' & 'manpages', that generate + documentation for POD when the respective feature is enabled. The + actions will generate the documents even if there is no set place + to install to. However, if the actions are invoked as a dependency + of another action (e.g. build), the documentation will only be + built when there is a default or user-specified place to install to. + + - Added support for environment variable, 'MODULEBUILDRC', which can + be used to specify the full path to an option file to use instead + of the default location of ~/.modulebuildrc. A special undocumented + setting of 'NONE' tells Module::Build not to load any user settings, + so tests can be run without tainting from user options. + + - Documented and improved preliminary support for more Getopt::Long + style options are supported, including boolean options (--verbose, + --no-verbose), and use of hyphens in option names in addition to + underscores. + + - The option to disable/enable reading of the ~/.modulebuildrc file + is changed from 'skip_rcfile' to 'use_rcfile' + + - Allow the 'distmeta' action to continue when 'MANIFEST' is missing, + omitting the generation of the 'provieds' field. [Steven Schubiger] + + - Fixed some failing regex from generated MANIFEST.SKIP file. + + - Fixed an edge case in $VERSION parsing where we thought a package() + declaration was happening but it wasn't. [David Golden] + + - Added docs for the install_destination() and install_types() methods. + +0.27_03 (Beta for 0.28) Mon Oct 10 11:19:23 EDT 2005 + + - We now use ExtUtils::CBuilder to do all compiling of C code (for + example, when compiling XS modules). (This change actually + occurred in 0.27_01, but it was mistakenly omitted from the Changes + file.) + + - Fixed an issue on Win32 (and other case-tolerant + non-case-preserving systems, possibly like VMS?) in which the + current working directory would sometimes be reported with + different case, fooling us into thinking that we were in the wrong + directory. [David Golden] + + - The extra_compiler_flags setting was not actually being passed + along to ExtUtils::CBuilder so it could pass it along to the + compiler. Now it is. + + - The synonyms 'scripts' and 'prereq' for 'script_files' and + 'requires' were broken in a previous version (0.27_01, probably), + but now they're fixed. [David Golden] + + - Previously, we assumed that any custom subclass of Module::Build + was located in _build/lib/. This is only true if the author used + the subclass() method, though. We now use %INC to find where the + custom subclass really is, so that we can "use lib" it. We also + issue a warning if it seems to be outside the build directory. + [Spotted by Peter Tandler] + + - Added a URL for each license type that we know about, which will + appear as resources=>license: in the generated META.yml file. + + - If the user passes a no_index parameter to our constructor, we now + pass that through when building the META.yml file. [Richard + Soderberg, RT #9603] + + - A few more status messages can now be suppressed by using 'quiet' + mode. [Dave Rolsky] + + - Added some more entries to the default MANIFEST.SKIP file. [Chris + Dolan] + + - Our POD parser will now accept "AUTHORS" as well as "AUTHOR" when + looking for the author list in a module. [David Wheeler] + + - When looking for the POD to auto-generate a README file, or for the + AUTHOR or ABSTRACT for the distribution, we now also look for a + *.pod with the same name as the *.pm file specified by + 'version_from'. [David Golden] + + - The recommended dependency on ExtUtils::ParseXS has been moved into + the "C_support" auto_feature. + + - When building XS files, we now pass the -DVERSION and -DXS_VERSION + flags to the compiler. [Spotted by Jerry Hedden] + + - If a distribution has XS files and Module::Build has not been + configured with the "C_support" feature, we now issue a + warning. [Suggested by Jerry Hedden] + + - Added a dir_contains() method. + + - Some versions of MakeMaker, CPANPLUS, and/or PAUSE thought that a + certain line of our code was declaring a $VERSION when we didn't + intend to. The line has been obscurified so they won't think that + anymore. [Jos Boumans, RT #14226] + + - Added the Apache, MIT, and Mozilla licenses to the list of licenses + that this module knows about. [Bob Ippolito] + + - Fixed a pretty significant typo in the documentation for + auto_features. [Spotted by Jonas B. Nielsen] + + - In order to aid people who want to do customization of the META.yml + file, we've added a "metafile" property that can then be easily + overridden in subclasses, changed do_create_meta_yml() to + do_create_metafile(), and split out the code that actually + generates the YAML into a new method, write_metafile(). [David + Wheeler] + + - Fixed a couple of non-helpful behaviors with extra_compiler_flags + and extra_linker_flags. These will automatically be run through + split_like_shell() when given to new() as strings. + + - When the user doesn't have ExtUtils::ParseXS installed and we use + the old 'xsubpp', the displayed command line for creating the .c + file from the .xs file was missing its newline. Now it's got it. + +0.27_02 (Beta for 0.28) Fri Jul 15 07:34:58 CDT 2005 + + - Provided initial support for the --prefix installation parameter, + which acts like MakeMaker's PREFIX. It is still highly recommended + NOT to use it when you could reasonably use --install_base or + --install_path or --install_dest, but that's just because the way + --prefix is designed is weird and unpredictable. Ultimately the + choice rests with the installing user. [Patches by Michael Schwern + and Rob Kinyon] + + - Fixed a bug in subclass() which prevented people from using it to + subclass subclasses of Module::Build. [Chris Dolan] + + - Added a 'pure_install' action, which for the time being is + identical to the 'install' action. [Jos Boumans] + + - Fixed a POD error in an L<http://...> tag. [Offer Kaye] + + - Note several options for automatically creating a new module dev + tree. [Suggested by Eric Wilhelm] + + - Removed some hard-coded references to File::Spec::Unix in the + creation of HTML docs, which should help that code work in more + places, and help people not to panic when they look at it. [Spotted + by Yves] + + - We now use Pod::Readme by default (instead of Pod::Text) to + generate the README file when the 'create_readme' option is used. + If Pod::Readme is not installed, we will still fall back to using + Pod::Text. [Robert Rothenberg] + + - The values of the "prefix", "install_base", "install_path", and + "install_dest" parameters can now begin with "~" or "~user", and + we'll de-tilde-ify them by using glob(). + + - The (optional) auto-creation of the README and Makefile.PL files + have been moved from the 'distdir' action to the 'distmeta' + action. [David Golden] + + - When looking for a .modulebuildrc file, we now use a fancier method + of trying to find the home directory, because $ENV{HOME} isn't a + very cross-platform variable. [Robert Rothenberg] + + - We now memoize the output of the internal _default_INC() method, + since it uses backticks and might be kind of slow. + + - When processing XS files, we now look for a typemap in lib/ as well + as using the system's default typemap. [John Peacock] + + - The DESTDIR, PREFIX, and INSTALL_BASE arguments to "make install" + are now supported for pass-through Makefiles (they've been + supported for quite a while as arguments to "perl + Makefile.PL"). [Requested by Guillaume Rousse] + + - Test::Harness has changed its output format in recent versions, + which threw off one of our tests. We now allow for this different + format. [Reported by Scott Godin] + + - Fixed an issue that prevented Module::Build from upgrading itself + using its own API (which is how CPANPLUS uses it). There are still + some issues with this solution, however. See ticket #13169 in + rt.cpan.org. [Reported by Jos Boumans] + + - Fixed a fatal error that occurred when a distribution's author + could not be determined from its POD nor from the call to + Module::Build->new() in its Build.PL. See ticket #12318 in + rt.cpan.org. [Reported by Jos Boumans] + + - Apparently on Windows and cygwin it's not possible to use the "-pi" + switch to perl without a backup extension, so now we use ".bak" and + remove the backup file when we're done. Thus the "dist" action for + Module::Build itself can now be run on those platforms. [Yitzchak + Scott-Thoennes] + + - Improved the handling of auto_features in the config_data access + script. [Yitzchak Scott-Thoennes] + +0.27_01 (Beta for 0.28) Fri Apr 15 21:12:57 CDT 2005 + + Backward-incompatible (but better) changes: + + * When using the 'install_base' option to choose a directory for + installing everything, perl modules now go into lib/perl5/ instead + of just lib/. It seems this is more consistent with people's + expectations, and the way I had it before was a bit peculiar to the + way I like things in my own home directory. [Michael Schwern] + + * When the user is using the 'install_base' option, scripts will now + be installed by default in $install_base/bin/ rather than + $install_base/script/ . [Jan Hudec and Michael Schwern] + + Major changes: + + - The auto_features mechanism will now re-evaluate dependencies every + time feature() is called for an auto-feature, rather than freezing + the success/failure value during 'perl Build.PL' and using that + value for all eternity (or module update, whichever comes first). + This applies to both $build->feature() and + FooModule::ConfigData->feature() calls. [Requested by many] + + - Added the meta_add and meta_merge mechanisms, which let the module + author add/merge arbitrary entries into the META.yml file. + + - Now reads per-action default options from '$ENV{HOME}/.modulebuildrc' + if it exists. Command line options override anything set in the rc file. + + - We now use ExtUtils::CBuilder to do all compiling of C code (for + example, when compiling XS modules). + + - The creation of Unix man pages is no longer a strict necessity - it + has now been turned into an 'auto-feature' contingent on the + presence of Pod::Man and a location specified for man pages to go. + + - A user-specified 'install_path' setting will now take precedence + over an 'install_base' setting. This allows the user to use + 'install_base' to set the base for all elements in one go, and then + use 'install_path' to override specific paths or add paths for + additional kinds of targets. + + - Split the main documentation from 'Module/Build.pm' into two + sections. The user level documentation and overview remains in + 'Module/Build.pm', while a new document, + 'Module/Build/Authoring.pod', has been created for module authors. + + Minor changes: + + - new_from_context() was losing its arguments in some cases (and not + because of inadequate training in forensic debate) - we now pass its + arguments directly to the Build.PL script rather than merging them + in afterwards. + + - Let resume() return an object blessed into the appropriate class + if the user has provided a subclass, as specified by the + 'build_class' property. This allows current() and new_from_context() + to behave more like factory methods returning objects of the correct + class based on context. [Ray Zimmerman] + + - Refactored methods relating to parsing perl module files for + package, version, and pod data into a new class: + Module::Build::ModuleInfo. It should not be considered part of + Module::Build's API, because we may split it out entirely as a + separate CPAN module that we depend on. + + - Added new method Module::Build::prepare_metadata() for authors to + override in order to add custom fields to META.yml. + + - We now use Test::More for our regression tests. If the user + doesn't have it installed, we include a copy in t/lib/ that we can + use during testing. + + - When copying files in the 'distdir' action, set permissions to match + the original files. [Julian Mehnle] + + - When adding files like META.yml to the MANIFEST, we now tell the + user we're doing so by printing one of the "Added to MANIFEST: ..." + lines. [Ron Savage] + + - Added a runtime_params() method, which lets a module author see + which parameters were overridden by the user on the command line + (or in whatever paradigm the user originally invoked Module::Build + from). [David Wheeler] + + - Added the current_action() method, which, surprisingly, returns the + name of the currently running action. [David Wheeler] + + - Added docs for run_perl_script(). + + - Added some stuff to the docs about why PREFIX is unsupported, and + what to use instead. [Steve Purkis] + + - The simple get/set accessor methods for all the 'parameters' like + verbose(), license(), etc. now have auto-generated documentation in + Module/Build.pm. + + - Created a Cookbook entry for 'Adding new elements to the install + process' + + - We now add META.yml to the MANIFEST when META.yml is created, not + when MANIFEST is created. [Spotted by Ron Savage] + + - Added some additional patterns to the suggested MANIFEST.SKIP + contents, and changed the docs so that we encourage the user to use + the MANIFEST.SKIP. [Ron Savage] + + - Eliminated a redundant recipe from the Cookbook, now that there are + some more extensive recipes on how to add stuff to the + build/install sequences. + + - Eliminated an undefined-variable warning when testing under perl 5.005 + + - When building HTML documentation, 'html_backlink' and 'html_css' + properties are now first-class properties, so they can be set from + the command line. [Suggested by Sagar R. Shah] + + - Have script_files default to everything in bin. I believe this is + the least surprising behavior. [Suggested by Michael Schwern] + + - If script_files is given a directory, consider each file in that + directory tree as a script to be installed. This avoids having to + remember to add to the script_files list every time you add a + program. [Suggested by Michael Schwern] + + - We now only load Pod::Man when we actually need to build man pages. + + - We now make Test::Harness use our carefully-selected path to a perl + executable regardless of Test::Harness's version. Previously we + let it figure stuff out for itself if it was a reasonably modern + version, but it's safer to make sure we're using the same perl + everywhere. + +0.2610 Fri Apr 15 08:25:01 CDT 2005 + + - new_from_context() was losing its arguments in some cases (and not + because of inadequate training in debate) - we now pass its + arguments directly to the Build.PL script rather than merging them + in afterwards. [Ray Zimmerman] + + - Fixed a bug in which config_data and feature data were being + forgotten and no ConfigData.pm module would get written. [Ray + Zimmerman] + + - Added a recipe to the cookbook showing how to run a single test + file from the command line. [William McKee] + + - For command-line arguments, we now accept the syntax "--foo=bar" in + addition to "--foo bar" and "foo=bar". This seems to fit well with + what GNU getopt and Getopt::Long do, and with people's + expectations. [Adam Spiers] + +0.2609 Wed Mar 16 22:18:35 CST 2005 + + - The html docs that were created during the first invokation of + './Build' were being found and treated as pod that needed to be + converted to html during subsequent invokations. We now are more + specific about the directories we scan for pod that needs to be + converted, effectively avoiding blib/html. [Ray Zimmerman] + + - If Pod::Man is not available, we now skip building man pages + (rather than dying) and tell the user why. + + - We now write a .packlist file upon installation, in the same place + that ExtUtils::MakeMaker does. [Johnny Lam] + + - On some Unix platforms (BSD derivatives, mostly) perl's $^X + variable isn't set to the full path of the perl executable, just + 'perl', when the 'Build' script is run as './Build' and not 'perl + ./Build'. This can lead to some other modules (maybe + Test::Harness, maybe IO::File, I dunno...) getting very confused + about where they are, and they try to load stuff from the wrong + perl lib, and big trouble ensues. To fix this, we now set $^X to + the value of Module::Build->find_perl_interpreter(). + + - The 'distcheck' action will now die() if it finds an error in the + MANIFEST, rather than just printing on STDOUT. [David Golden] + + - When the README and/or Makefile.PL are autogenerated using + create_readme or create_makefile_pl, we now automatically make sure + they're also listed in the MANIFEST file. [Suggested by Michael + Schwern] + + - Got rid of the t/MANIFEST file - it's superfluous, and it had + zero-length, which some versions of Tar don't like. [William + Underwood] + + - Added a mention in the documentation that each property that new() + accepts also has a corresponding get/set accessor. (In the version + 0.27_0x series each accessor method is mentioned explicitly in the + docs.) [Omission spotted by Ian Langworth] + +0.2608 Wed Jan 26 19:46:09 CST 2005 + + - Add workaround for test files because Devel::Cover causes + require to fail when the argument to require is an expression + involving File::Spec. We now assign the result of the File::Spec + call to a variable and then call require with that variable. + + - Tilde-expansion is now performed on arguments passed to a + compatibility-Makefile.PL [Spotted by Sam Vilain] + + - We now run the 'gzip' and 'tar' values through split_like_shell() + when running the 'dist' action, so that e.g. the 'gzip' value can + be set to something like "gzip -f --best" and it'll work + correctly. [Spotted by Chris Dolan] + + - Work around some bad mojo between Fedora Core [with its very long + @INC] and old versions of Test::Harness [with its propensity to + compound the number of @INC entries] that produced an "argument + list too long" error during testing. [assisted by Ville Skytta, + David Golden, & Randy Sims] + + - Killed an infinite loop that would happen in y_n() in interactive + mode if the author provided no default value. [Max Maischein] + +0.2607 (Bug fix release in 0.26 series) Sat Dec 18 14:14:09 CST 2004 + + - Instead of freezing @INC in the 'Build' script to the value it had + when Build.PL was run, we now just add those additional values that + aren't part of the default compiled-in @INC. [Michael Schwern] + + - The run_perl_script() method will now propagate any extra entries + in @INC (such as those added by "use lib" or the -I command-line + switch) to the subprocess. This helps situations in which you want + to tell the subprocess where to find a certain module, for + instance. [Michael Schwern] + +0.2606 (Bug fix release in 0.26 series) Tue Dec 7 22:33:11 CST 2004 + + - Fixed a linking bug on Win32, in which compiled C code object files + never got linked in with the modules being built. [Dominic + Mitchell] + + - Fixed a bug in the new_from_context() method in which any arguments + passed made us die. [Spotted by Jos Boumans] + +0.2605 (Bug fix release in 0.26 series) Tue Nov 30 07:16:13 CST 2004 + + - Fixed a bug in which zero-length arguments for hash-valued + parameters (e.g. " --config foo= ") weren't being allowed. + + - The tests now play better with environments in which version.pm is + pre-loaded, like in bleadperl. [John Peacock & Michael Schwern] + + - Fixed a syntax error in one of the tests under perl 5.005. + +0.2604 (Bug fix release in 0.26 series) Wed Nov 17 14:32:42 CST 2004 + + - Fixed a split_like_shell() bug introduced in 0.2603 for Windows, in + which an array reference passed as an argument was returned as an + array reference, rather than as a list. [Spotted by Steve Hay] + + - module_name() will now return '' instead of undef when module_name + is not set. This eliminates a couple uninitialized-value + warnings. [Suggested by Michael Schwern] + + - The expand_test_dir() method will now skip dotfiles (like ._foo.t, + which sometimes gets automatically created on Mac systems) when + 'recursive_test_files' is in effect. [Tom Insam] + +0.2603 (Bug fix release in 0.26 series) Mon Nov 15 10:28:00 CST 2004 + + - Added documentation for the new_from_context() method. + + - Completely rewrote the split_like_shell() method for the Windows + platform so it works like the command.com shell. [Randy Sims] + +0.2602 (Bug fix release in 0.26 series) Thu Nov 4 11:19:29 CST 2004 + + - The two bug fixes in 0.2601 gnashed against each other incorrectly, + resulting in a Win32 bug in split_like_shell(). Fixed. [Spotted + by Steve Hay & Randy Sims] + + - Removed a couple of 'use warnings' statements from the code - they + were causing compile failures on 5.005_04, where warnings.pm isn't + available. [Blair Zajac] + +0.2601 (Bug fix release in 0.26 series) Wed Nov 3 20:09:27 CST 2004 + + - Fixed some backslash problems with split_like_shell() on + Win32. [Steve Hay] + + - Fixed a bug in split_like_shell() in which leading whitespace was + creating an empty word, manifesting as something like "gcc - no + such file or directory" during tests. [Spotted by Warren L. Dodge] + +0.26 Sat Oct 9 17:51:01 CDT 2004 + + - Removed some language from the Module::Build::Compat documentation + that encouraged people to include a Build.PL without a Makefile.PL. + Also changed "a replacement for MakeMaker" to "an alternative to + MakeMaker" in the main documentation, which is basically what I + meant all along (i.e. a replacement for MakeMaker in your + particular build process - MakeMaker is never going to be fully + replaced in the perl world at large, of course), but some people + got the impression I was a little more truculent toward MakeMaker + than I really am. + + - Added the formal concepts of "features" and "config data" for + distributions. This allows the module author to define a certain + set of features that the user can switch on and off (usually + according to whether they have the proper prerequisites for them), + and to save build-time configuration information in a standardized + format. See the main documentation of Module::Build for more + details. (Note that the name of this system was called + "BuildConfig" for a while in beta, but now it's called + "ConfigData".) + + - Added an 'auto_features' capability, which simplifies the process + of defining features that depend on a set of prerequisites. + + - Added the 'get_options' parameter, which lets module authors + declare certain command-line arguments their Build.PL can accept + [David Wheeler] + + - Changed the split_like_shell() method to use the shellwords() + function from Text::ParseWords (a core module since 5.0), which + does a much better job than the split() we were using. + + - Added a 'testpod' action, which checks the syntactic validity of + all POD files in the distribution using Test::Pod. This eliminates + the need for doing so in a regression test. [Initial patch by Mark + Stosberg] + + - Added a process_files_by_extension() method, which generalizes the + kind of processing (essentially just copying) that happens for .pm + and .pod files, and makes it available to other user-defined types + of files. See the new cookbook entry. + + - Improved compatibility with version.pm when authors are using + version objects as their $VERSION variables. Now + version_from_file() can deal with these objects. Currently we + stringify them right away, but perhaps in the future we will + preserve them as objects for a while. + + - During 'distdir' and 'distmeta' actions, die a bit more gracefully + if there's no MANIFEST (i.e. explicitly say that a MANIFEST is + required). [Spotted by Adrian Howard] + + - Eliminated a recursive dependency between creating the MANIFEST + file and creating the META.yml file. [Spotted by Dave Rolsky] + + - On Win32, where a single directory might be known variously as + "Module-Build-0.25_03" or "MODULE~1.25_", we now use + Win32::GetShortPathName($cwd) to verify that the 'Build' script is + being run from the correct directory, rather than just a string + comparison. + + - The add_to_cleanup() method will now accept glob()-style patterns + in addition to explicit filenames. Also documented the fact that + they can be specified in either Unix-style or native-style + notation. + + - Passing a PREFIX value to a pass-through Makefile 'make install' + now has the same effect as passing it to 'perl Makefile.PL' (it + dies with a helpful message). + + - Added the 'testcover' action, which runs a test suite using + Devel::Cover. [Dave Rolsky] + + - Added the 'lib' and 'arch' installation directories to the search + path for the 'diff' action, since they won't necessarily (though + they usually will) be in @INC at installation time. [Suggested by + Kevin Baker] + + - The "=head3" POD directive isn't supported in older podlators + (particularly Pod::Man), so we don't use it anymore. + + - Fixed a typo & improved the docs in the SUBCLASSING section. [Ron + Savage] + + - Added the '.tmp' suffix to the default MANIFEST.SKIP file, which + should avoid adding things like pod2htmi.tmp to the MANIFEST [Ron + Savage] + + - Backup files from Emacs, containing the string '.#' in their names, + should no longer find their way into the blib/ directory (and from + there into installation directories). + + - Worked around an unpleasant interaction between version.pm and the + version-checking code that makes sure Module::Build's version + hasn't changed during the lifetime of the 'Build' script. [Reported + by Trevor Schellhorn] + + - Fixed a problem in htmlify_pods() that would produce test failures + on Cygwin (and probably elsewhere). [Yitzchak Scott-Thoennes] + + - Fixed a test failure on Cygwin (and probably elsewhere) in + t/compat.t, resulting from empty environment variables being set to + the empty string (as opposed to simply being unset) by their mere + presence in the "EXPORT:" list. + + - Fixed a fatal error that occurred when the author specified + 'dist_author' manually in their Build.PL script. [Spotted by Ron + Savage] + + - The 'provides' section of the META.yml file wasn't being built + properly on Win32, because of a mismatch between URL-format and + native-format pathnames. Fixed. [Reported by Robert Rothenberg] + + - The progress message "lib/Foo.xs -> lib/Foo.c" was previously being + output even when the Foo.c file wasn't being rebuilt. It's now + fixed. + + - Fixed a couple of places in Compat.pm where it could have forgotten + which perl interpreter it had been run with ($^X isn't very + trustworthy). + + - On some systems, the way we updated the timestamp on the + "lib/Foo.bs" file (one of the output files for XS-based modules) + was failing. It's been replaced by a simple call to utime(). + + - Fixed a problem in t/compat.t that prevented it from being run + individually using 'make test TEST_FILES=t/compat.t'. The problem + was that a couple environment variables (TEST_FILES, MAKEFLAGS) + were being passed through to subprocesses, and confused them. + + - Fixed an important typo in the documentation for the 'install_base' + parameter ('libdoc' and 'bindoc' were switched). [Ray Zimmerman] + + - The pass-through Makefiles (type 'small' or 'passthrough') now + support the TEST_FILES parameter to 'make test'. + + - Fixed a fatal error that would occur on perl 5.005 when building + HTML documentation, because its version of Pod::Html was old and + didn't like some of the parameters we fed it. [Spotted by Blair + Zajac] + + - The final line of the generated pass-through Makefile was missing + its trailing newline, which is now fixed. [Chip Salzenberg] + + - We now depend on YAML version at least 0.35 and at most version + 0.49, so that we don't pick up a new (and backward-incompatible) beta + version from CPAN. + + - Squashed a warning in t/basic.t about '"Foo::Module::VERSION" used + only once', and one in PPMMaker about $^V being undefined. [Blair + Zajac] + + - Added a couple temporary output files from HTML documentation + generation to the cleanup list. [Toby Ovod-Everett] + + - The PodParser module will now only extract paragraphs in the + 'AUTHOR' section of the pod if they contain an '@' character. This + tends to do a better job, heuristically speaking, of returning + relevant stuff. + + - Added regression tests and a helper method ( add_build_elements() ) + for adding new elements to the build process. Also some + documentation. + + - Wrote a recipe in the Cookbook for adding new elements to the build + process, and a recipe for changing the order in which the steps in + the build process will occur. + +0.25 Sun Apr 25 11:12:36 CDT 2004 + + - During the 'distdir' action, if no MANIFEST.SKIP file exists, we + will now create a reasonable default one. [Randy Sims] + + - In Makefile compatibility mode, some arguments (like UNINST, + TEST_VERBOSE, etc.) given to 'make' are now recognized and passed + through to Module::Build. [Randy Sims] + + - The regression tests now make sure that several pass-through + Makefile.PL parameters are dealt with correctly. + + - Added support for the 'LIB' parameter to passthrough + Makefile.PLs. [Spotted by Jesse Erlbaum] + + - Passing a 'PREFIX' parameter to a passthrough Makefile.PL was + supposed to make it die with a helpful error message, but instead + it just ignored it and blindly tried to install to the wrong place. + This is now fixed. [Spotted by Jesse Erlbaum] + + - Added an extra_compiler_flags() accessor method. + + - If the 'recursive_test_files' option was turned on, the test files + weren't sorted, but returned in an apparently random order. Now + they're sorted. [Martyn Peck] + + - Documented the 'tar' and 'gzip' parameters to the 'dist' and + 'ppmdist' actions. + + - The generation of HTML documentation now works (it was accidentally + partially implemented with an itchy patch-application finger in + 0.24). [Randy Kobes] + + - Fixed a fatal bug when building META.yml with YAML.pm and + 'dynamic_config' is set. [Reported by Jaap Karssenberg] + + - Fixed some incorrect error messages that occurred when + compiling/linking C sources went awry. + + - If the author uses a custom builder subclass, that subclass will + now be loaded correctly in the passthrough Makefile.PL if the + author uses the 'small' or 'passthrough' Makefile.PL options in + Module::Build::Compat. [Martyn Peck and Jaap Karssenberg] + + - If the author uses a custom builder subclass created dynamically + through the subclass() method, passthrough Makefile.PLs (of type + 'passthrough' or 'small') didn't work properly, because the custom + builder module wouldn't be loaded at the right time. This has been + fixed. [Reported by Toby Ovod-Everett] + + - In M::B-generated 'traditional' Makefile.PLs, the entries in + 'PREREQ_PM' are now sorted ASCIIbetically rather than randomly. + + - The install_types() method will now return any additional types + given as 'install_path' arguments, as well as all elements of the + current 'install_sets' entry. This makes it easier to add new + types of installable objects to the mix. + + - As a consequence of the previous change, there is no longer any + need to have an explicit 'install_types' data member, so it has + been removed. + + - In the second example code for the Module::Build->subclass() + method, the Module::Build module needed to be loaded before calling + its methods. [John Peacock] + + - Fixed minor error in the POD structure of Module::Build and + Module::Build::Platform::VMS docs. + + +0.24 Wed Feb 25 15:57:00 CST 2004 + + - Fixed a problem with incude_dirs not being propagated to the 'ccs' + file when compiling XS files on Win32. [Randy Sims and Steve Hay] + + - In 0.23, Module::Build::Compat->fake_makefile() started choking + when no 'build_class' parameter was supplied in the Makefile.PL. + Since these Makefile.PLs still exist on CPAN, we now default + 'build_class' to 'Module::Build', which was the old 0.22 behavior + anyway. [Reported by Martin Titz and Jeremy Seitz] + + - Added documentation for the 'include_dirs' parameter to + new(). [Steve Hay] + + - Changed the no-op command on Win32 from 'rem' to 'rem>nul' inside + pass-through Makefiles. [Randy Sims] + + - The 'autosplit' parameter now accepts an array reference if + multiple files should be split. [Jaap Karssenberg] + + - find_perl_interpreter() will now use $^X (if absolute), $ENV{PATH} + (if $^X isn't absolute), and $Config{perlpath}, in that order. + Also, we now make darn sure the result is the same version of perl, + by checking Config::myconfig() for a match against the current + perl. [Reported by Edward Sabol] + + - Fixed a fatal error on Win32 (and any other platform that doesn't + define an installation location for Unix-style man pages) during + installation. + +0.23 Sun Feb 8 22:01:18 CST 2004 + + - Fixed a compatibility problem in pass-through Makefiles (created by + Module::Build::Compat). Some 'make' utilities (for example, BSD + make) didn't like a '@' by itself on a line, so we stole some + 'NOOP' code from MakeMaker to fix it. [Reported by Mathieu Arnold] + + - Added a 'ppm_dist' action, which just makes the PPD file and then + makes a tarball out of the blib/ directory. [Randy Sims] + + - The @INC of the parent process is now propagated to child processes + when processing *.PL files. [Reported by Jaap Karssenberg] + + - We now only attempt to fix the shebang line on a script if the + shebang line matches the regex /perl/i . This fixes some instances + where people put shell scripts in their distributions. [Jaap + Karssenberg] + + - We no longer generate a 'requires', 'recommends', 'conflicts', + etc. entry in the META.yml file if there's no data to go in it. + + - Added a documentation reference to Michael Schwern's wiki for tips + on conversion from MakeMaker to M::B. [Randy Sims] + + - If there are script_files, we now add EXE_FILES to the + 'traditional' Makefile.PL generated by M::B::Compat. [Suggested by + Yuval Kogman] + + - Documented the 'test_files' parameter to new(). [Reported by Tony + Bowden] + + - Fixed a problem in "Build help <action>", which didn't find the + correct help chunk if <action> was the final element in a POD + list. [Jaap Karssenberg] + + - Fixed a problem in the get_action_docs() method which gave + incorrect results if the method was called more than once in the + same program. + + - Fixed a problem in which actions defined by user subclasses + wouldn't be available via the pass-through Makefiles created by + Module::Build::Compat. [Reported by Jaap Karssenberg] + + - We now use Data::Dumper instead of our own ad-hoc serialization + routines to create the 'traditional' Makefile.PL + arguments. [Suggested by Yuval Kojman] + +0.22 Sat Jan 10 22:05:39 CST 2004 + + - On Unixish platforms, the syntax "FOO=BAR /bin/baz arg arg" now + works when present in $Config{ld}. This solves a problem on Mac OS + X 10.3. [Reported by Adam Foxson] + + - The have_c_compiler() now also tests whether the linker seems to + work too. + + - Fixed a problem with creating the distribution tarball in which + permissions would usually be all read-only. We now use our own + file-copying routines rather than those in ExtUtils::Manifest, + because those do some annoying extra permissions-setting stuff for + no apparent reason. It makes me happy that this was a very very + easy patch to make. [Reported by Thomas Klausner] + + - The compile_c() method now includes $Config{cccdlflags} in its + command invocation. It's usually empty, but not always, so we + didn't notice for a while. [Richard Clamp] + + - On some platforms it's common to have a $Config{make} defined, but + no 'make' utility actually available. We now detect this and skip + some 'make' compatibility tests. [Randy Sims] + + - Fixed a spurious testing failure on non-Unix platforms that + happened because we accidentally call localize_file_path() on empty + strings in the test suite. [Spotted by Randy Sims on Windows] + + - Made the 'name', 'abstract', 'author', and 'version' properties + required when building a PPD file. [Spotted by Randy Sims, Dave + Rolsky, & Glenn Linderman] + + - When building a 'traditional' Makefile.PL with + Module::Build::Compat, we now use 'VERSION_FROM' when possible, + rather than always using 'VERSION'. This way the Makefile.PL + doesn't have to get modified every release. + + - Made some fixups to the 'PPM' info-file, improving compatibility + with ActiveState's PPM tools. [Randy Sims, Glenn Linderman] + + - The 'dist_author' property can now accept multiple authors, see the + docs for more info. [Randy Sims] + + - If the user doesn't have YAML.pm installed during ACTION_dist, we + now create a minimal YAML.pm anyway, without any dependency + information. + + - The 'distribution_type' field is no longer created in META.yml + files, in accordance with the finding made at the London CLPAN + meeting that it's essentially meaningless and ill-defined. + + - The 'dist' action now accepts an optional 'tar' parameter to use a + system utility for building the tarball, and a 'gzip' parameter for + compressing it. If these are used, Archive::Tar won't be invoked. + This was added because Archive::Tar is producing some very + non-cross-platform tarballs that many tar utilities can't handle. + + - During testing, if YAML.pm isn't installed, then we won't try + making a tarball either, since this would invoke YAML to create the + META.yml file. + + - Fixed a problem with chmod() being called incorrectly on MacOS + (i.e. MacPerl, not Mac OS X). [Spotted by Paul Sanford Toney] + + - Fixed a problem with the --config flag not being treated properly + (essentially ignored) on the command line for 'perl Build.PL' or + 'Build <action>'. [Spotted by Jakub Bogusz] + + - Added a new config() method to get at the Build object's notion of + the %Config hash. + + - Test::Harness is starting to contend for the Most Crotchety Module + Award. Work around a few of its nits when setting harness + switches. [Spotted by Diab Jerius] + + - Now the Build script will die() if we're run from the wrong + directory, rather than trying to chdir() to what it thinks is the + right directory and do its work there. See + https://rt.cpan.org/Ticket/Display.html?id=4039 . [Chris Dolan] + + - Changed the manpage separator on OS/2 to '.'. [Ilya Zakharevich] + + - On OS/2, disable C compilation, since apparently it isn't working + there. [Reported by Ilya Zakharevich] + + - Inserted a comment into auto-generated Makefile.PLs saying it was + auto-generated. [Randy Sims] + + - Fixed some annoying behavior in generated passthrough Makefile.PLs + when the user chose not to install Module::Build, or if + installation failed. [Reported by Ilya Zakharevich and Richard + Clamp] + + - Moved the documentation for 'codebase' to the section where it's + relevant. [Randy Sims, Glenn Linderman] + + - Fixed a have_c_compiler() failure on some platforms, we now define + a boot_compilet() function (since we're compiling a library, not an + executable). [Randy Sims] + + - Added a recipe to the Module::Build::Cookbook describing how to + maintain compatibility with older versions of CPAN.pm [Jim Cromie] + + - Removed caveat about "looking for alternatives" in how hashes are + specified on the command line, since an alternative has been found. + + - Previously most warnings about optional prerequisites looked like + they were actually error messages about required prerequisites. + This has been corrected. [Reported again by Sagar Shah] + + - Added support for building XS (and C in general) stuff on AIX. + This was done by a small reorganization of prelink_c() method from + Windows.pm to Build.pm, and it is only invoked for the platforms + that need it invoked. AIX also massages some very naughty bits + (MakeMaker macro variables) in $Config{lddlflags} that should never + have been put there, but alas, they're there, so we find & resolve + them. + + - Added OS/2 ($^O = 'os2') to the list of Unix-like platforms. This + basically means that most platform-specific operations will be done + in a Unix-like manner. + + - Pass-through Makefiles will now die() when they're given a PREFIX + parameter, and suggest using 'destdir' or 'install_base' instead. + Previously they just ignored the parameter and tried to install to + the default location, which is clearly not what the user wanted. + + - Updated my email address in the documentation to a more recent + variant. + + - Add NetBSD to the list of Unix-like systems. [Adrian Bunk] + + - Add SVR5 to the list of Unix-like systems. [Rafael Garcia-Suarez] + + - We now use Pod::Parser to find the ABSTRACT and AUTHOR when it's + available on the system. [initial patch by Randy Sims] + + - Fixed a little scalar/list buglet in a documentation example. + +0.21 Wed Oct 15 20:47:05 CDT 2003 + + - Added a have_c_compiler() method. + + - Added documentation for the requires(), recommends(), + build_requires(), and conflicts() methods. + + - On Unix platforms, we now create the "Build" script with a #! line + matching the perl interpreter that was used to invoke the Build.PL + script, rather than whatever is in $Config{startperl}. This avoids + a potential warning about the interpreters not matching. [Spotted + by Ken Y. Clark] + + - The Unix version now uses the safer multi-argument form of system() + when building distribution tarballs. + + - Added a regression test for the 'dist' action to the t/runthrough.t + test. + + - Fixed a problem with File::Spec usage when creating the names of + 'libdoc' manual pages - the code wasn't dealing with the volume or + file portions correctly on certain platforms. + + - When creating the names of the 'libdoc' manual pages, we no longer + assume that pods are under the hard-coded paths 'blib/lib' or + 'blib/arch'. + + - Fixed a crashing bug that could sometimes occur when the + distribution contained no 'lib' directory. [Chris Dolan] + + - Fixed a crashing bug that happened when the user had .PL files in + the lib/ directory and didn't explicitly name them in a hash + reference to the new() constructor. [Chris Reinhardt, bug #4036] + + - .PL files are now passed the names of their target file(s) on the + command line when they run. + + - When YAML.pm wasn't installed, t/runthrough.t wasn't properly + skipping some tests that required YAML. This is now fixed. + [Stephen J. Smith] + + - Added documentation for the dist_version() and dist_name() + methods. [Spotted by Johan Vromans] + + - Existing values in $ENV{HARNESS_PERL_SWITCHES} are now respected + and not squashed when we run the 'test' action. [Paul Johnson] + + - On cygwin, the separator string for manual page names has been set + to '.'. Previously it was '::', inherited from Unix. [Yitzchak + Scott-Thoennes] + + - Avoid a warning when Build.PL is run (i.e. when the new() method is + called) and no MANIFEST file exists. [Michael Schwern and Kevin + Ruscoe] + + - Added documentation for the 'code' and 'docs' actions. [Steve + Purkis and Mark Stosberg] + + - The internal method compile_support_files() has been renamed to + process_support_files() in order to make it consistent with other + processing methods. Note that it was never documented using the + old name. It's still not documented, actually. Maybe later. + + - Skip the 'write' pseudo-entry in the 'diff' action's installation + map. [Chris Dolan] + + - Fixed a bug in which notes() set in the Build.PL before + create_build_script() was called would get lost unless more notes() + were also set afterwards. [Spotted by Dave Rolsky] + + - The process of building elements of the distribution is now driven + by a list of build elements, paving the way for letting people add + their own types of build elements in future versions of + Module::Build (or in the current version with some difficulty). + + - Fixed some linking errors on Cygwin. [Randy Sims, Terrence Brannon] + + - Fixed a line-ending problem with detecting the dist_abstract + properly on Cygwin. [Randy Sims] + + - Fixed a problem with signatures that occurred if 'distsign' was + called before 'distdir' - the signature would be generated twice. + + - Added a 'create_readme' parameter to new(), which will use + Pod::Text to generate a README from the main (dist_version_from) + module file during the 'distdir' action. + + - We now refuse to run the 'Build' script if it was created using a + different version of Module::Build. This has caused a couple of + nasty bugs in the past, I don't want to know what it would cause in + the future. + + - Documentation for do_system() has been added. [Dave Rolsky] + + - run_perl_script() is now available as a class method, though it + will need to (re-)find the perl interpreter in this case. + + - Added a new_from_context() method that authors of automated tools + like CPANPLUS and CPAN can use instead of running all tasks as + sub-processes. We also use it in the regression tests for + Module::Build itself. ** Note that this method is currently + undocumented because its name may change in the future. ** + + - When signing distributions with Module::Signature, we now + automatically add the SIGNATURE file to the MANIFEST, avoiding an + unpleasant chicken/egg problem for the module author. + [unpleasantness spotted by sungo] + + - In Module::Build::Compat, added support for the 'verbose' parameter + to Makefile.PL [spotted by Soren Andersen, fixed by Michael + Schwern] + + - The Module::Build distribution now has a cryptographic 'SIGNATURE' + file created by Module::Signature. + + - Added proper documentation for the subclass() method. [spotted by + Jonathan Steinert] + + - Worked around a Config.pm bug in Red Hat 9 which prevented man + pages from being installed in the correct places. [spotted by Ville + Skytta] + + - Fixed a Module::Build::Compat bug in which setting INSTALLDIRS + caused a crash. [spotted by Ilya Martynov] + +0.20 Tue Aug 26 14:34:07 CDT 2003 + + - Separated the 'build' action into two separate actions, 'code' and + 'docs'. This is similar to MakeMaker's separation of the 'all' + target into 'pure_all' and 'manifypods'. This fixes a permissions + hassle in which doing 'sudo Build install' would often create local + doc files that needed superuser permissions to delete. + + - Enhanced the 'help' action - 'Build help foo' will now show the POD + documentation for the 'foo' action. + + - Added a notes() feature, which helps share data transparently + between the Build.PL and t/*.t scripts. + + - The installation process will now create man(1) and man(3) pages + from POD in modules & scripts, and install them. We don't build + man pages when there's nowhere to install them, such as on some + Win32 or most Mac systems. [large patch by Steve Purkis, 5.005 fix + by Mathieu Arnold] + + - The 'distdir' action now copies files to the distribution + directory, rather than making them hard links to the original + files. This allows authors to do last-minute alterations of the + files without affecting the originals. [Dave Rolsky] + + - If the author uses XS files in nonstandard locations, the copied + versions of those files will now be cleaned up properly. + + - In invoking the 'test' action or invoking 'xsubpp', we now use the + same perl executable as we use everywhere else, rather than blindly + using $^X or $Config{perlpath} (neither of which are very + reliable). + + - Fixed a problem with the 'install_path' parameter given to + 'Build.PL' being lost in subsequent actions. [Reported by Mathieu + Arnold] + + - Fixed yet another bug with installation directories, in which the + 'install_base' parameter wasn't being respected on the command + line. [Spotted by Jonathan Swartz] + + - Changed the way the depends_on() method works inside action + subroutines - now each action will only run once per dispatch() + invocation (similar to how perl's require() function works). This + helps avoid some difficult problems with dependency loops. + + - Changed the documentation for the 'autosplit' parameter to give + reasons why it may not be a good idea to use, but no longer + threaten to remove it. [Suggested by Martyn J. Pearce] + + - Improved the formatting of the 'traditional' Makefile.PL generated + by Module::Build::Compat->create_makefile_pl. [Michael Schwern] + + - The 'traditional' Makefile.PL will now use the 'module_name' + parameter (as NAME) if it's available, otherwise it will continue + to use the 'dist_name' (as DISTNAME). [Michael Schwern] + + - Created read/write accessor methods for all our 'properties'. + [Michael Schwern] + + - The 'test_files' parameter can now be specified using glob() syntax + (i.e. 't/*.t'), and the corresponding test_files() method is now a + read/write accessor. + + - The location of the 'blib' directory is now a property of the Build + object - nobody is likely to notice this change, with any luck, but + it makes the design and code cleaner. + + - The 'disttest' and 'distsign' methods now chdir() back to the + directory where they started, rather than to the base_dir of the + build. + + - Improved comparisons of version strings containing underscore + characters (indicating "beta" status). [Steve Purkis] + + - Added documentation for the 'dist_author', 'dist_abstract', and + 'codebase' parameters to new(), and for the 'ppd' action. [Dave + Rolsky] + + - Added documentation for the up_to_date() and contains_pod() + methods. [Dave Rolsky] + + - 'traditional' pass-through Makefile.PLs will now contain an + INSTALLDIRS parameter matching the Build.PL's 'installdirs' + setting. + + - version_from_file() now ignores $VERSION variables that are defined + in POD or comments. It can still be tricked by $VERSIONs in string + literals, though. [Steve Purkis] + + - The code to find packages in module files now uses Steve's scanning + method (above) to skip package-declaration-lookalikes in POD or + comments. + + - The 'disttest' action will now propagate its @INC settings to its + subprocesses. + +0.19 Wed Jul 9 22:34:02 CDT 2003 + + - Added support for the 'install_path' parameter, which allows custom + specification of where things should be installed. This is a major + improvement to Module::Build's functionality. + + - Added the 'install_base' parameter. Provides an easy way to + install to local or alternative directory trees. + + - We now install scripts by default to $Config{installsitebin} + instead of $Config{installscript}. Neither is a great choice, but + the former is likely to be [analogous to] /usr/local/bin, and the + latter is likely to be [something like] /usr/bin . If/when there's + a $Config{installsitescript}, we'll start using that automatically. + + - Fixed a problem on Win32 in which C and XS files wouldn't be + compiled properly, and the user would see an error about 'Can't + locate object method "format_compiler_cmd"'. + (http://rt.cpan.org/Ticket/Display.html?id=2391) + + - We now use the correct perl interpreter (via + Module::Build->find_perl_interpreter) in pass-through makefiles. + + - The t/compat.t test now uses $Config{make} instead of just 'make' + to test makefile compatibility. This fixes some failures on Win32. + We also skip this test entirely if no make utility is available. + + - Alternative distribution layouts are now supported via the + 'pm_files', 'pod_files', 'xs_files', 'PL_files', and 'script_files' + parameters to new(). This should help people transition from + MakeMaker, and might even help us write an automatic transition + tool. + + - Added tests to t/runthrough.t that check to see installation is + happening correctly. + + - Added experimental code to build a .ppd file, in support of + ActiveState's "Perl Package Manager". [original patch by Dave + Rolsky] + + - For authors who use Module::Signature to sign their distributions, + we now create the SIGNATURE file right in the distribution + directory, rather than creating it in the top-level directory and + copying it into place. This solves problems related to having + files get out of date with respect to their signatures. + + - We now don't depend on Module::Info to scan for packages during the + 'dist' action anymore, because it's way too aggressive about + loading other modules that you may not want loaded. We now just + (ick, yuck) scan the .pm files with a regular expression to find + "package Foo::Bar;" statements. + + - Silenced some annoying copyright/logo output from Microsoft 'nmake' + during Makefile compatibility testing. [Randy W. Sims] + + - Command-line arguments may now either be specified using the syntax + '--foo foovalue' as well as the traditional syntax 'foo=foovalue'. + The former is often more convenient for shell tab-completion when + the value is a filename (as in 'Build test --test_files t/basic.t'). + + - Command-line arguments may now include non-named parameters, which + make some actions more natural. For instance, the 'diff' action + may now be invoked as 'Build diff -u' rather than as + 'Build diff flags=-u'. + + - Pass-through Makefile.PLs now convert unknown Makefile.PL + parameters to lower-case and hand them to Build.PL, rather than + ignoring them. This means we only have to account for the + differences in the interface, not the entire interface, in + translating parameters. + + - We now issue a warning & don't proceed if asked to make a distdir + and there's no MANIFEST or it's empty. + + - Moved INSTALL to INSTALL.txt to increase compatibility with various + odd versions of 'make' during 'make install' on case-insensitive + filesystems (like nmake on Win32, often). Only affects the + Makefile compatibility layer. [reported by Andrew Savige] + + - Module::Build->known_actions() now works as a class method. + + - Pass-through makefiles now list each action individually rather + than using a ".DEFAULT" catch-all. This improves compatibility + with 'nmake' on Win32, and probably some other less common 'make' + dialects. [Andrew Savige] + + - We're now more aggressive about testing the pass-through makefiles, + e.g. making sure they can run 'all' and 'test' targets, and making + sure the Makefile itself actually exists. + + - Fixed a problem with check_installed_status() when installed + version contains non-numeric characters like underscores. + + - Fixed a problem with a bareword 'File::Spec' in one of the test + scripts that caused it not to compile under 5.8.0 (but is fine + under 5.6). + + - Fixed a problem with the 'destdir' installation parameter on + platforms that have volume identifiers in path names (like "C:" on + Win32). The identifier is now stripped from installation + directories before prepending the destdir path. The destdir path + may still have a volume identifier on it. + + - Added an 'add_to_cleanup' parameter to new() that calls + add_to_cleanup() immediately for the given files. + + - The distribution directory (e.g. Sample-Module-0.13/ ) will now be + deleted during the 'clean' or 'realclean' actions. + + - During testing of modules, blib/lib and blib/arch are now added as + absolute paths, not relative. This helps tests that load the + modules at runtime and may change the current working directory + (like Module::Build itself does during testing). + + - The $Config{cc} entry on some people's systems is something like + 'ccache gcc', so we now split that string using split_like_shell(). + [Richard Clamp] + + - Added documentation for 'extra_linker_flags' parameter, and added a + corresponding 'extra_compiler_flags' parameter. [original patch by + Richard Clamp] + + - The pass-through Makefile created by Module::Build::Compat now + supports MakeMaker options like POLLUTE=1 and INC. We also just + warn & skip when we see any unknown MM parameters, rather than + dying. [Dave Rolsky] + + - Fixed an error about how @INC and $ENV{PERL5LIB} interact during + the testing of M::B itself. [jk <billy2000@fastmail.fm>] + + - The pass-through Makefile doesn't include 'recommended' M::B + dependencies in the Makefile anymore, since they're not strictly + necessary. In particular, this makes installing M::B itself + easier. + + - A new 'create_makefile_pl' parameter lets you use + Module::Build::Compat during the 'distdir' (or 'dist') action to + automatically create a Makefile.PL for compatibility with + ExtUtils::MakeMaker. The parameter's value should be one of the + styles named in the Module::Build::Compat documentation. + + - When compiling C code, we now respect 'pollute' and 'inc' + parameters. (XXX - needs docs) [Dave Rolsky] + + - Made the creation of the "install map" more generic. (XXX - needs + documentation) + + - Fixed a problem in which add_to_cleanup() didn't note cleanup files + unless create_build_script() had been called already. [Dave Rolsky] + + - During 'Build dist', we no longer have to load each .pm file (via + Module::Info) to determine the $VERSION numbers inside. Instead, + we call our internal version_from_file() method, which is the same + thing MakeMaker and PAUSE and search.cpan.org do. Also fixes a + failure when Module::Info is installed in a nonstandard directory. + [reported by Teun Burgers] + + - Fixed some failing test code on Windows - open files can't be + deleted. [Andrew Savige] + + - The Cygwin platform is now treated as a flavor of Unix rather than + a flavor of Windows. [chocolateboy] + + - We're now more aggressive about adding temporary C compilation + files (*.c, *.bs) to the cleanup list. [Dave Rolsky] + + - When constructing the list in META.yml of packages provided by this + distribution, we now use the same rules as the PAUSE scanner does + when a single .pm file contains multiple VERSIONs. [Andreas Koenig] + + - check_installed_status() now works as both a class method and an + object method (and is documented so). [Spotted by Dave Rolsky] + +0.18 Tue Apr 8 13:24:23 CDT 2003 + + - We now rewrite the shebang lines of scripts ourselves, rather than + relying on MakeMaker routines to do it. MakeMaker changed the way + this happened (not the result, but where the code lived) a few + times. [Suggested by Richard Clamp] + + - The scripts() method has changed to script_files(), and likewise + the 'scripts' parameter has changed to 'script_files'. The old + names can still be used for backward compatibility. + + - Support for the 'scripts' parameter (which is now 'script_files') + was broken in 0.17, now it's fixed. [Richard Clamp] + + - We now recommend ExtUtils::ParseXS 2.02, which will fail to load + with perl 5.005 or earlier (which is proper, because it doesn't + work with those versions). When it fails to load, we still fall + back to using the xsubpp script for XS parsing. [spotted by Dave + Rolsky, fix suggested by Richard Clamp] + + - Now works on VMS - the Build script's shebang-line-equivalent + wasn't being formed correctly there - though just about everything + else worked fine. [Tested & patched by Michael Schwern] + + - Eliminated a warning that occurred if 'perl Build.PL' or the + check_installed_status() method was run with -w. [Spotted by + Michael Schwern] + +0.17 Sat Mar 29 18:06:01 CST 2003 + + - Now works under perl 5.005_03. [Richard Clamp] + + - When building blib/ , .PL files are now processed before doing + anything else. This means .PL files can be used in any of the + other contexts. + + - The locating and processing of .pm, .pod, .xs, .PL files and script + files are now isolated into their own methods. This is aimed + toward providing a stable interface for this stuff, so they can be + overridden, parameterized, etc. They're not quite stable yet, + though. + + - The internal lib_to_blib() method has gone away, because processing + is now done by smaller specialized methods. This method had some + duplicate assumptions about filenames that it's nice to get rid of. + + - .PL files are no longer automatically processed in the c_source + directory, they must be specified manually in a 'PL_files' + parameter. + + - Mention in the docs that it's useful to do "PL_FILES => {}" in a + Makefile.PL if you're using both a Makefile.PL and a + Build.PL. [Dom] + + - Add several options to the 'license' field, so that we're in better + sync with PAUSE and CPAN options. [Andreas Koenig] + + - Created a find_perl_interpreter() method that tries to locate the + currently executing perl interpreter. Following a suggestion from + Nicholas Clark <nick@ccl4.org> for Inline, we prefer an absolute + path in $^X, then an existent path in $Config{perlpath}, then + whatever's in $^X. + + - Use the aforementioned perl to run scripts in run_perl_script(). + This fixes the spurious warning "WARNING: Configuration was + initially created with 'foo', but we are now using 'bar'" that + appeared a lot in version 0.16. + + +0.16 Mon Feb 24 13:06:47 CST 2003 + + - All three C compilers that perl supports on Windows environments + (MSVC, BCC, and GCC) are now supported by Module::Build. We now + reportedly pass all tests on Windows. [Randy W. Sims] + + - The test t/xs.t, which tests building of XS modules, will be + skipped if no C compiler is found. [suggested by Randy W. Sims] + + - The "install" action accepts new "destdir" [motivated by Michael + Schwern and Chip Salzenberg] and "uninst" parameters [by Dave + Rolsky]. The former prepends an arbitrary directory to all + installation paths (useful for package management), and the latter + will tell ExtUtils::Install to remove any differing files that are + "shadowing" the stuff you're installing from a different location, + just like MakeMaker's "make install UNINST=1" command will do. + + - Made changes to the generated Makefile in Module::Build::Compat + that much better support Windows platforms [after suggestions by + James Freeman] + + - Added experimental support for creating distribution SIGNATURE + files via Module::Signature. [Dave Rolsky] + + - Added experimental support for installing via the "only.pm" module, + which allows loading specific versions of modules. Since this + module is so new, the interface may still be changing. [Brian + Ingerson] + + - Added support for installing executable scripts, via the 'scripts' + parameter to new(), and the scripts() accessor method. + + - Fix an infinite loop that occurred when doing 'perl Build.PL + config="foo=bar"' + + - Fix up the formatting of the error message the user gets when + prereqs aren't satisfied. + +0.15 Fri Jan 17 15:00:24 CST 2003 + + - In link_c(), extra object files were mistakenly being treated as + output files, not input files, in the up-to-date check. Fixed. + + - In up_to_date(), don't make an unnecessary copy of the file lists + when they're specified as array references. + + - Split off the C compilation phase into its own method, + compile_support_files(), for easier subclassing. + + - Start a stub of a 'manifypods' action. + + - Compiler optimizations weren't being included in C compilation + statements. Fixed. + + - The 'extra_linker_flags' parameter wasn't being honored. Fixed. + + - The 'ccflags' Config.pm entry wasn't being properly split into + separate arguments. Fixed. + + +0.14 Fri Dec 13 14:06:29 AEST 2002 + + - Added support for MacPerl (Mac OS version 9 and below), which (as + far as I know) was never natively supported by MakeMaker. Still + lacks support for the 'test' action (because Test::Harness + requires forking, which MacPerl won't do) and compiling XS/C files + (because I don't know how to invoke a compiler on MacOS, and one + may not even be available). This change is brought to you by + Michael Schwern and the letter '('. + + - Improved processing of .xs files. Now we use the new + ExtUtils::ParseXS module if it's available, otherwise we use + backticks and write the result to a .c file ourselves. This + avoids the need to do cross-platform shell redirection. + + - Make sure all parts of 'Build test' use the not-yet-installed + version of Module::Build. This only affects the tests for this + module, not any of the module code itself. [Spotted by Schwern] + + - Oopsie - use $Config{ld} instead of $Config{cc} for linking. + + - Added a 'diff' action, which is useful for comparing the details + of what you're about to install with what is already installed on + your system. This uses File::Compare, which is in the core. + + - Fixed a problem on Windows in which the _build/ directory wasn't + getting deleted during the 'realclean' action, because we had a + file open in that directory. [Spotted by Michael Schwern] + + - delete_filetree() now always uses File::Path::rmtree(), regardless + of whether the thing being deleted is a file or a directory. This + helps remove things on obscure platforms with strange locking + rules (or even not so obscure ones like MacOS). It also now + reports the number of files or directories deleted (without + recursing directory contents). + + - rm_previous_build_script() is gone, replaced by calls to + delete_filetree(). + + - 'Build' now chdir()s in a BEGIN block, so the 'use Module::Build' + statement will work correctly. Solves a problem on MacOS, where + the 'Build' script may often be invoked from the wrong working + directory. [Fix by Michael Schwern] + + - Internally we now use the multi-argument form of system() to run + external commands (such as 'diff' or 'cc') whenever possible (and + whenever we can't avoid system() altogether). Note that this + means we have to handle splitting some strings (such as + $Config{ccflags}) into argument lists like the shell would, which + is a drag. However, the alternative would be to handle shell + quoting of all arguments to commands ourselves, which is an even + bigger drag across platforms and involves arbitrary filenames and + so on. + + - To handle the argument splitting mentioned above, a method + split_like_shell() has been created. So far it's just doing naive + processing. In practice, I've yet to actually see a %Config entry + that uses quotes & spaces, so the splitting task is usually not + very error-prone. + + - The 'test' action now takes a 'test_files' parameter, similar to + the (undocumented) ExtUtils::MakeMaker TEST_FILES argument. Handy + during development when fixing bugs. + + - Internally, the rscan_dir() method can now accept a predicate + function that decides whether a file/directory should be matched. + + - We now issue a warning message when the author hasn't specified a + license type. + +0.13 Wed Nov 20 20:07:53 AEST 2002 + + - 'cleanup' file lists are now written immediately, rather than at + program termination. This helps avoid "phantom files" that don't + get handled by the 'realclean' action. The internal + write_cleanup() method (which was never documented) is now gone. + + - The 'blib/' directory is now properly cleaned up in more (all?) + circumstances. Previously it could become a phantom if + create_build_script() was never called. + + - Now scan the 'c_source' directory for .cpp (C++) files as well as + .c files, and compiles them. + + - Use a 'phony' target for 'make manifest' in the pass-through + Makefile, for the same reason as 'make install' (see version 0.12 + notes below). + + - Module::Build::Compat now accepts any known Config.pm key and + passes it through to the Build.PL. Fixes a problem with CPANPLUS, + which was passing INSTALLMAN1DIR. + + - The file 'META.yaml' has been re-named to 'META.yml' in order to + cooperate better with systems that can only handle 3 characters + after the dot. + + - The t/xs.t test should give more informative error messages upon + failure. + +0.12 Thu Nov 14 18:31:47 AEST 2002 + + - The META.yaml file was erroneously looking for 'build_depends' + instead of 'build_requires'. [spotted by Iain Truskett] + + - Add prompt() and y_n() methods for use in Build.PLs + + - Do more to work with all versions of Test::Harness when setting + the TEST_VERBOSE flag and running under the debugger [patch by + Dave Rolsky] + + - Include a test for verbosity handling + + - Make sure the blib/ directory is always cleaned up with the + 'clean' or 'realclean' action. + + - In a pass-through Makefile.PL, inform 'make' that 'install' is a + "fake target", so that it works properly on case-insensitive + filesystems like HFS+ with distributions that contain an INSTALL + file. [patch by Brian Ingerson] + + - In Module::Build::Compat, show an example Makefile.PL that can + install Module::Build and re-invoke itself in one fell swoop [Dave + Rolsky and Autrijus Tang] + + - Improve the formatting of the Module::Build and + Module::Build::Compat documentation. + +0.11 Fri Aug 23 18:50:46 AEST 2002 + + - 'module_version' and 'module_version_from' have been replaced by + 'dist_version' and 'dist_version_from', which is what they really + meant in the first place. 'dist_name' has been added. + + - 'module_name' is now just a way to set 'dist_name' and + 'dist_version_from' in a convenient way. + + - The 'name' in META.yaml is now the distribution name, not the + (incorrect) module name. [spotted by Graham Barr] + + - Added the check_installed_status() and prereq_failures() methods + for checking prerequisite information with the programmatic + interface + + - check_installed_version() now uses check_installed_status() + internally + + - Documented the create_build_script() method, which had escaped + documentation. + + - create_build_script() now writes prerequisite information to the + _build/ directory, for use by Module::Build::Compat. + + - Module::Build::Compat has documentation for a safer way to write a + dummy Makefile.PL. [patch by Autrijus Tang] + +0.10 Wed Aug 7 19:36 2002 + - Recommend YAML 0.35 instead of 0.30. + + - Don't die during 'Build disttest' if YAML isn't installed. This + fixes tests 5-10 in runthrough.t if YAML isn't installed. + + - Die if an unknown license type is used, but still default to + 'unknown' if no license is specified. + + - Use YAML::DumpFile() if we're using a recent YAML, + YAML::StoreFile() otherwise. + + - Show specific error messages in runthrough.t. + + - Add a generated_by entry to the META.yaml file. + + - Skip a few tests if YAML isn't installed. + +0.09 Fri Jun 28 11:07:08 EST 2002 + + - The 'distdir' action wasn't deleting the distribution directory + before building it again. This meant that, say, if you did 'Build + disttest' then 'Build dist', you'd end up with a blib/ directory + in your distribution. I actually had this happen for version + 0.08, and it's not nice to distribute a blib/ on CPAN. + + - We now keep track of the 'base_dir', i.e. the top-level build + directory, so we can change back into it if we change out of it. + This necessitated a cwd() method, which uses the Cwd.pm module. + I'm aware of Cwd's limitations, particularly under taint-mode, but + I don't know a way around using it here. + + - The 'dist_dir' action now changes back into 'base_dir' directory. + + - We now do write_config() inside the create_build_script() method, + not inside the new() method. + + - Simplified the find_version() method, and improved its error + messages. + + - Renamed module_name_to_file() to find_module_by_name(), and added + a parameter specifying the directories to search in. Previously + we searched in 'lib' and @INC, which wasn't correct in all + situations. + + - Patched the docs to change "Build test" to "./Build test" + [Elizabeth Mattijsen] + +0.08 Wed Jun 26 20:30:56 EST 2002 + + - Fixed the 'prereq' alias for the 'requires' parameter + + - Added some tests in t/basic.t to test the dependency checking + + - Added 'artistic' as a licensing option [Arthur Bergman] + + - Fixed some bugs in requires/prereq/recommends/conflicts/build_depends + + - Fixed a typo in the 'distclean' action that prevented its + execution [Arthur Bergman] + + - Separated the linking phase of building XS items into its own + link_c() method. Its interface is still unstable, so it's not + documented yet. [suggested by Arthur Bergman] + +0.07 Jun 9 2002 15:46 + + - We now generate a 'META.yaml' metadata file during 'Build dist'. + This can be very useful for lots of things, none of which are + implemented yet. + + - Added a 'dynamic_config' parameter, defaulting to false. This + lets distribution systems (CPAN.pm, etc.) build, test, and install + "easy" modules without having to execute the Build.PL at runtime. + It's also a guarantee that the list of dependencies is exactly + what is present in the metadata file, and won't be changed during + the build process. + + - Added support for "recommended" and "build-time requirement" + modules, besides those that are absolutely required. Also added a + "conflicts" field. + + - Changed the 'prereq' field to 'requires' (the old name will + continue to work). + + - Added support for checking the installed version of perl as an + explicit dependency. + + - Added a 'license' parameter to specify one of a fixed number of + licenses for the distribution. + + - Fixed a bug in Module::Build::Compat that was preventing arguments + from being processed properly. [patch by Ilya Martynov] + + - Make sure we're in the right directory when we write the cleanup + file, since various ExtUtils::Install errors might leave us in an + unknown directory. [patch by Ilya Martynov] + + - Specified the 'license', 'recommends', and 'dynamic_config' + values in Build.PL, and changed 'prereq' to 'requires'. + +0.06 Apr 2 2002 17:44 + + - Added the Module::Build::Compat module for assisting and + explaining compatibility with ExtUtils::Makemaker and cohorts. + + - State is now saved using Data::Dumper instead of my ad-hoc + mechanism, guaranteeing data integrity. Whitespace values broke + in the former scheme. + + - Added the 'recommended' option, which works like 'prereq' but + isn't insistent. + + - Separated the various parameters into three groups: parameters + that tell Module::Build what to do, Config.pm parameters, and + user-defined parameters for each build (the module author is the + 'user' here). This helps avoid conflicts between names, and it + was silly to have them all together. The three groups of + parameters are subject to the same rules for overriding: values + specified during a Build action take precedence over values + specified at 'perl Build.PL' time, which in turn take precedence + over values specified in the call to new(). + + - Improved support for .PL files. Any .PL file in the lib/ + directory or the directory specified by 'c_source' will now get + properly executed. I also added a 'PL_files' parameter that you + can use in case the .PL doesn't create an obviously-named output + file. + + - If a prerequisite condition is malformed, we now report a prereq + failure and say why. Previously we issued a warning and kept + going. + + +0.05 10-Jan-2002 20:26 + - Added the Module::Build->subclass() method, which makes it easier to + make quick-and-dirty subclasses of Module::Build. + + - Reorganized the docs a bit. + + - Added the 'testdb' action, and the 'debugger=1' argument to the + 'test' action, both of which run tests under the perl + debugger. (idea: Dave Rolsky) + + - Added prerequisite checking (Dave Rolsky) + + - Fixed an unlikely-to-occur bug with misquoted strings in the + 'Build' script (spot: Dave Rolsky) + + - We're more careful about shush-ing warnings that + ExtUtils::Manifest might emit (Dave Rolsky) + + - The 'help' action now auto-generates the list of actions (Dave Rolsky) + + - Added the 'distcheck', 'skipcheck', 'distclean', 'distdir', and + 'disttest' actions (Dave Rolsky) + + - We're a little more aggressive about cleaning up temporary files - + we'll try to clean them up even when we don't have write permission + on them. This isn't as dastardly as it sounds; if we /really/ + don't have permission, we won't be able to remove them no matter + how hard we try. + +0.04 Fri Nov 16 16:55 2001 + - Added a 'manifest' action. It's just like MakeMaker's 'make manifest', it + brings your MANIFEST file up to date with your distribution directory. + + - Reorganized some of the responsibilities of various methods, which + allows modules to be built and tested programmatically. + + - The 'clean' action will now clean up files that were created more + recently than the on-disk cleanup registry was written. + + - Undefined values from Config.pm are handled correctly now. + + - The dispatch() method will now accept explicit dispatch + parameters, for use in a programmatic setting. + + - $ENV{TEST_VERBOSE} will be set in test scripts if the 'verbose=1' + parameter is set. + + - Moved the test.pl script to t/basic.t + + - Created the t/xs.t script, which tests building a module with a + .xs component. + + - Fixed the loading of $^O-specific modules (there were no such + modules before). + + - Added a 'darwin' platform module, which removes -flat_namespace + from $Config{ccflags} while building .xs modules (it's a linker + flag, not a compiler flag). + + - Now uses $^W instead of the 'warnings' pragma, which apparently + provides compatibility with perl 5.005 (I've only tested it with + 5.6.x myself). + + - If a file called C<visual.pl> exists in the top-level directory, + this file will be executed as a Perl script during 'Build test' and + its output will be shown to the user. This is a good place to put + speed tests or other tests that don't use the C<Test::Harness> format + for output. + + - The 'Build install' step will now put .xs-related things in the + correct architecture-dependent libraries. + + - Added the 'autosplit' option, even though I think autosplitting is + a load of hooie. + +0.03 Sun Nov 11 14:58 CDT 2001 + - The 'perl Build.PL' step will now detect whether the current + environment is "unixish", "windowsish", etc., and load the correct + module (i.e. Module::Build::Platform::Unix). More specific + modules may also be written for particular values of $^O. + + - Module::Build will now process any .xs files in the lib/ + directory. Please let me know whether this works or not with your + distribution & platform. I'll be trying out various distributions + on my platform. + + - Corrected some embarassing errors in the POD documentation. Also + added a long documentation section on the various build actions + (test, install, build, etc.) and added some neato ASCII art. + + - Added a 'cleanup' mechanism - any method may call the + $self->add_to_cleanup(@files) method to register files which need + to be cleaned up during 'Build clean'. + + - Added a 'Build help' action that gives a little syntax help, and + lists all the actions available. + + - Fixed a bug in which 'blib/' wasn't properly being added to @INC + when running 'Build test'. + + - For the 'Build dist' action, we'll use the 'tar' and 'gzip' + programs (as specified by Config.pm) on Unix platforms, otherwise + we'll use Archive::Tar and Compress::Zlib. + +0.02 Wed Sep 5 00:53:04 CDT 2001 + - Added POD documentation. + + - Added the 'install', 'fakeinstall', and 'dist' actions. + + - new() will now determine version string based on 'module_version', or + 'module_version_from', or 'module_name', in that order. + + - Module::Build::Base handles its file paths in a platform-independent + way, using the File:: modules + + +0.01 Sun Aug 5 01:23:10 2001 + - original version; created by h2xs 1.1.1.4 with options -XA -n Module::Build + @@ -0,0 +1,24 @@ + Installation instructions for Module::Build + +To install this module, just do: + + perl Build.PL + ./Build + ./Build test + ./Build install (this step may need to be done as the superuser) + +Or, if you're on a platform (like DOS or Windows) that doesn't require +the "./" notation, you can do this: + + perl Build.PL + Build + Build test + Build install + +The important thing is that the "Build" script gets executed and that +you pass it the "test", "install", etc. arguments. + +There's heaps more information in the README and in the documentation +of the various packages in this distribution. + + -Ken @@ -0,0 +1 @@ +FULLTEXT
\ No newline at end of file diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..08cda4d --- /dev/null +++ b/MANIFEST @@ -0,0 +1,97 @@ +bin/config_data +Build.PL +Changes +contrib/bash_completion.module-build +inc/bootstrap.pl +inc/MBVersion.pm +inc/Module/Metadata.pm +inc/Perl/OSType.pm +INSTALL +lib/Module/Build.pm +lib/Module/Build/API.pod +lib/Module/Build/Authoring.pod +lib/Module/Build/Base.pm +lib/Module/Build/Bundling.pod +lib/Module/Build/Compat.pm +lib/Module/Build/Config.pm +lib/Module/Build/Cookbook.pm +lib/Module/Build/Dumper.pm +lib/Module/Build/Notes.pm +lib/Module/Build/Platform/aix.pm +lib/Module/Build/Platform/cygwin.pm +lib/Module/Build/Platform/darwin.pm +lib/Module/Build/Platform/Default.pm +lib/Module/Build/Platform/MacOS.pm +lib/Module/Build/Platform/os2.pm +lib/Module/Build/Platform/Unix.pm +lib/Module/Build/Platform/VMS.pm +lib/Module/Build/Platform/VOS.pm +lib/Module/Build/Platform/Windows.pm +lib/Module/Build/PodParser.pm +lib/Module/Build/PPMMaker.pm +LICENSE +Makefile.PL +MANIFEST +META.json +META.yml +README +t/00-compile.t +t/actions/installdeps.t +t/actions/manifest_skip.t +t/add_property.t +t/add_property_array.t +t/add_property_hash.t +t/basic.t +t/bundle_inc.t +t/bundled/Software/License.pm +t/bundled/Tie/CPHash.pm +t/compat.t +t/compat/exit.t +t/debug.t +t/destinations.t +t/ext.t +t/extend.t +t/files.t +t/help.t +t/install.t +t/install_extra_target.t +t/lib/DistGen.pm +t/lib/MBTest.pm +t/lib/Module/Signature.pm +t/lib/Software/License/VaporWare.pm +t/manifypods.t +t/manifypods_with_utf8.t +t/metadata.t +t/metadata2.t +t/mymeta.t +t/new_from_context.t +t/notes.t +t/par.t +t/parents.t +t/perl_mb_opt.t +t/PL_files.t +t/pod_parser.t +t/ppm.t +t/properties/dist_suffix.t +t/properties/license.t +t/properties/module_name.t +t/properties/needs_compiler.t +t/properties/release_status.t +t/properties/requires.t +t/properties/share_dir.t +t/README.pod +t/resume.t +t/runthrough.t +t/sample.t +t/script_dist.t +t/signature.t +t/test_file_exts.t +t/test_reqs.t +t/test_type.t +t/test_types.t +t/tilde.t +t/unit_run_test_harness.t +t/use_tap_harness.t +t/versions.t +t/write_default_maniskip.t +t/xs.t diff --git a/META.json b/META.json new file mode 100644 index 0000000..a835d0e --- /dev/null +++ b/META.json @@ -0,0 +1,157 @@ +{ + "abstract" : "Build and install Perl modules", + "author" : [ + "Ken Williams <kwilliams@cpan.org>", + "Module-Build mailing list at <module-build@perl.org>." + ], + "dynamic_config" : 1, + "generated_by" : "Module::Build version 0.4214", + "license" : [ + "perl_5" + ], + "meta-spec" : { + "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", + "version" : "2" + }, + "name" : "Module-Build", + "prereqs" : { + "build" : { + "requires" : { + "CPAN::Meta::YAML" : "0.003", + "File::Temp" : "0.15", + "Parse::CPAN::Meta" : "1.4401", + "Test::Harness" : "3.16", + "Test::More" : "0.49" + } + }, + "configure" : { + "requires" : { + "CPAN::Meta" : "2.142060", + "Module::Metadata" : "1.000002", + "Perl::OSType" : "1", + "version" : "0.87" + } + }, + "runtime" : { + "recommends" : { + "ExtUtils::Install" : "0.3", + "ExtUtils::Manifest" : "1.54" + }, + "requires" : { + "CPAN::Meta" : "2.142060", + "Cwd" : "0", + "Data::Dumper" : "0", + "ExtUtils::CBuilder" : "0.27", + "ExtUtils::Install" : "0", + "ExtUtils::Manifest" : "0", + "ExtUtils::Mkbootstrap" : "0", + "ExtUtils::ParseXS" : "2.21", + "File::Basename" : "0", + "File::Compare" : "0", + "File::Copy" : "0", + "File::Find" : "0", + "File::Path" : "0", + "File::Spec" : "0.82", + "Getopt::Long" : "0", + "Module::Metadata" : "1.000002", + "Perl::OSType" : "1", + "Pod::Man" : "2.17", + "Test::Harness" : "0", + "Text::Abbrev" : "0", + "Text::ParseWords" : "0", + "perl" : "5.008000", + "version" : "0.87" + } + } + }, + "provides" : { + "Module::Build" : { + "file" : "lib/Module/Build.pm", + "version" : "0.4214" + }, + "Module::Build::Base" : { + "file" : "lib/Module/Build/Base.pm", + "version" : "0.4214" + }, + "Module::Build::Compat" : { + "file" : "lib/Module/Build/Compat.pm", + "version" : "0.4214" + }, + "Module::Build::Config" : { + "file" : "lib/Module/Build/Config.pm", + "version" : "0.4214" + }, + "Module::Build::Cookbook" : { + "file" : "lib/Module/Build/Cookbook.pm", + "version" : "0.4214" + }, + "Module::Build::Dumper" : { + "file" : "lib/Module/Build/Dumper.pm", + "version" : "0.4214" + }, + "Module::Build::Notes" : { + "file" : "lib/Module/Build/Notes.pm", + "version" : "0.4214" + }, + "Module::Build::PPMMaker" : { + "file" : "lib/Module/Build/PPMMaker.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::Default" : { + "file" : "lib/Module/Build/Platform/Default.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::MacOS" : { + "file" : "lib/Module/Build/Platform/MacOS.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::Unix" : { + "file" : "lib/Module/Build/Platform/Unix.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::VMS" : { + "file" : "lib/Module/Build/Platform/VMS.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::VOS" : { + "file" : "lib/Module/Build/Platform/VOS.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::Windows" : { + "file" : "lib/Module/Build/Platform/Windows.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::aix" : { + "file" : "lib/Module/Build/Platform/aix.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::cygwin" : { + "file" : "lib/Module/Build/Platform/cygwin.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::darwin" : { + "file" : "lib/Module/Build/Platform/darwin.pm", + "version" : "0.4214" + }, + "Module::Build::Platform::os2" : { + "file" : "lib/Module/Build/Platform/os2.pm", + "version" : "0.4214" + }, + "Module::Build::PodParser" : { + "file" : "lib/Module/Build/PodParser.pm", + "version" : "0.4214" + } + }, + "release_status" : "stable", + "resources" : { + "license" : [ + "http://dev.perl.org/licenses/" + ], + "repository" : { + "url" : "https://github.com/Perl-Toolchain-Gang/Module-Build" + }, + "x_IRC" : "irc://irc.perl.org/#toolchain", + "x_MailingList" : "mailto:module-build@perl.org" + }, + "version" : "0.4214" +} diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..10ebce8 --- /dev/null +++ b/META.yml @@ -0,0 +1,114 @@ +--- +abstract: 'Build and install Perl modules' +author: + - 'Ken Williams <kwilliams@cpan.org>' + - 'Module-Build mailing list at <module-build@perl.org>.' +build_requires: + CPAN::Meta::YAML: '0.003' + File::Temp: '0.15' + Parse::CPAN::Meta: '1.4401' + Test::Harness: '3.16' + Test::More: '0.49' +configure_requires: + CPAN::Meta: '2.142060' + Module::Metadata: '1.000002' + Perl::OSType: '1' + version: '0.87' +dynamic_config: 1 +generated_by: 'Module::Build version 0.4214, CPAN::Meta::Converter version 2.143240' +license: perl +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: '1.4' +name: Module-Build +provides: + Module::Build: + file: lib/Module/Build.pm + version: '0.4214' + Module::Build::Base: + file: lib/Module/Build/Base.pm + version: '0.4214' + Module::Build::Compat: + file: lib/Module/Build/Compat.pm + version: '0.4214' + Module::Build::Config: + file: lib/Module/Build/Config.pm + version: '0.4214' + Module::Build::Cookbook: + file: lib/Module/Build/Cookbook.pm + version: '0.4214' + Module::Build::Dumper: + file: lib/Module/Build/Dumper.pm + version: '0.4214' + Module::Build::Notes: + file: lib/Module/Build/Notes.pm + version: '0.4214' + Module::Build::PPMMaker: + file: lib/Module/Build/PPMMaker.pm + version: '0.4214' + Module::Build::Platform::Default: + file: lib/Module/Build/Platform/Default.pm + version: '0.4214' + Module::Build::Platform::MacOS: + file: lib/Module/Build/Platform/MacOS.pm + version: '0.4214' + Module::Build::Platform::Unix: + file: lib/Module/Build/Platform/Unix.pm + version: '0.4214' + Module::Build::Platform::VMS: + file: lib/Module/Build/Platform/VMS.pm + version: '0.4214' + Module::Build::Platform::VOS: + file: lib/Module/Build/Platform/VOS.pm + version: '0.4214' + Module::Build::Platform::Windows: + file: lib/Module/Build/Platform/Windows.pm + version: '0.4214' + Module::Build::Platform::aix: + file: lib/Module/Build/Platform/aix.pm + version: '0.4214' + Module::Build::Platform::cygwin: + file: lib/Module/Build/Platform/cygwin.pm + version: '0.4214' + Module::Build::Platform::darwin: + file: lib/Module/Build/Platform/darwin.pm + version: '0.4214' + Module::Build::Platform::os2: + file: lib/Module/Build/Platform/os2.pm + version: '0.4214' + Module::Build::PodParser: + file: lib/Module/Build/PodParser.pm + version: '0.4214' +recommends: + ExtUtils::Install: '0.3' + ExtUtils::Manifest: '1.54' +requires: + CPAN::Meta: '2.142060' + Cwd: '0' + Data::Dumper: '0' + ExtUtils::CBuilder: '0.27' + ExtUtils::Install: '0' + ExtUtils::Manifest: '0' + ExtUtils::Mkbootstrap: '0' + ExtUtils::ParseXS: '2.21' + File::Basename: '0' + File::Compare: '0' + File::Copy: '0' + File::Find: '0' + File::Path: '0' + File::Spec: '0.82' + Getopt::Long: '0' + Module::Metadata: '1.000002' + Perl::OSType: '1' + Pod::Man: '2.17' + Test::Harness: '0' + Text::Abbrev: '0' + Text::ParseWords: '0' + perl: '5.008000' + version: '0.87' +resources: + IRC: irc://irc.perl.org/#toolchain + MailingList: mailto:module-build@perl.org + license: http://dev.perl.org/licenses/ + repository: https://github.com/Perl-Toolchain-Gang/Module-Build +version: '0.4214' diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..489985d --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,16 @@ +# This Makefile.PL creates a pass-through Makefile that simply calls +# the equivalent Module::Build methods for each make target. See the +# documentation for Module::Build::Compat for more information. + +use 5.006001; + + +use lib qw(lib); + +# bootstrap configure_requires prereqs +BEGIN { do 'inc/bootstrap.pl' or die defined($@) ? $@ : $! } + +use Module::Build::Compat; + +Module::Build::Compat->run_build_pl(args => \@ARGV); +Module::Build::Compat->write_makefile(build_class => 'Module::Build'); @@ -0,0 +1,901 @@ +NAME + Module::Build - Build and install Perl modules + +SYNOPSIS + Standard process for building & installing modules: + + perl Build.PL + ./Build + ./Build test + ./Build install + + Or, if you're on a platform (like DOS or Windows) that doesn't require + the "./" notation, you can do this: + + perl Build.PL + Build + Build test + Build install + +DESCRIPTION + "Module::Build" is a system for building, testing, and installing Perl + modules. It is meant to be an alternative to "ExtUtils::MakeMaker". + Developers may alter the behavior of the module through subclassing in a + much more straightforward way than with "MakeMaker". It also does not + require a "make" on your system - most of the "Module::Build" code is + pure-perl and written in a very cross-platform way. + + See "MOTIVATIONS" for more comparisons between "ExtUtils::MakeMaker" and + "Module::Build". + + To install "Module::Build", and any other module that uses + "Module::Build" for its installation process, do the following: + + perl Build.PL # 'Build.PL' script creates the 'Build' script + ./Build # Need ./ to ensure we're using this "Build" script + ./Build test # and not another one that happens to be in the PATH + ./Build install + + This illustrates initial configuration and the running of three + 'actions'. In this case the actions run are 'build' (the default + action), 'test', and 'install'. Other actions defined so far include: + + <action_list> + + You can run the 'help' action for a complete list of actions. + +GUIDE TO DOCUMENTATION + The documentation for "Module::Build" is broken up into sections: + + General Usage (Module::Build) + This is the document you are currently reading. It describes basic + usage and background information. Its main purpose is to assist the + user who wants to learn how to invoke and control "Module::Build" + scripts at the command line. + + Authoring Reference (Module::Build::Authoring) + This document describes the structure and organization of + "Module::Build", and the relevant concepts needed by authors who are + writing Build.PL scripts for a distribution or controlling + "Module::Build" processes programmatically. + + API Reference (Module::Build::API) + This is a reference to the "Module::Build" API. + + Cookbook (Module::Build::Cookbook) + This document demonstrates how to accomplish many common tasks. It + covers general command line usage and authoring of Build.PL scripts. + Includes working examples. + +ACTIONS + There are some general principles at work here. First, each task when + building a module is called an "action". These actions are listed above; + they correspond to the building, testing, installing, packaging, etc., + tasks. + + Second, arguments are processed in a very systematic way. Arguments are + always key=value pairs. They may be specified at "perl Build.PL" time + (i.e. "perl Build.PL destdir=/my/secret/place"), in which case their + values last for the lifetime of the "Build" script. They may also be + specified when executing a particular action (i.e. "Build test + verbose=1"), in which case their values last only for the lifetime of + that command. Per-action command line parameters take precedence over + parameters specified at "perl Build.PL" time. + + The build process also relies heavily on the "Config.pm" module. If the + user wishes to override any of the values in "Config.pm", she may + specify them like so: + + perl Build.PL --config cc=gcc --config ld=gcc + + The following build actions are provided by default. + + build + [version 0.01] + + If you run the "Build" script without any arguments, it runs the + "build" action, which in turn runs the "code" and "docs" actions. + + This is analogous to the "MakeMaker" *make all* target. + + clean + [version 0.01] + + This action will clean up any files that the build process may have + created, including the "blib/" directory (but not including the + "_build/" directory and the "Build" script itself). + + code + [version 0.20] + + This action builds your code base. + + By default it just creates a "blib/" directory and copies any ".pm" + and ".pod" files from your "lib/" directory into the "blib/" + directory. It also compiles any ".xs" files from "lib/" and places + them in "blib/". Of course, you need a working C compiler (probably + the same one that built perl itself) for the compilation to work + properly. + + The "code" action also runs any ".PL" files in your lib/ directory. + Typically these create other files, named the same but without the + ".PL" ending. For example, a file lib/Foo/Bar.pm.PL could create the + file lib/Foo/Bar.pm. The ".PL" files are processed first, so any + ".pm" files (or other kinds that we deal with) will get copied + correctly. + + config_data + [version 0.26] + + ... + + diff + [version 0.14] + + This action will compare the files about to be installed with their + installed counterparts. For .pm and .pod files, a diff will be shown + (this currently requires a 'diff' program to be in your PATH). For + other files like compiled binary files, we simply report whether + they differ. + + A "flags" parameter may be passed to the action, which will be + passed to the 'diff' program. Consult your 'diff' documentation for + the parameters it will accept - a good one is "-u": + + ./Build diff flags=-u + + dist + [version 0.02] + + This action is helpful for module authors who want to package up + their module for source distribution through a medium like CPAN. It + will create a tarball of the files listed in MANIFEST and compress + the tarball using GZIP compression. + + By default, this action will use the "Archive::Tar" module. However, + you can force it to use binary "tar" and "gzip" executables by + supplying an explicit "tar" (and optional "gzip") parameter: + + ./Build dist --tar C:\path\to\tar.exe --gzip C:\path\to\zip.exe + + distcheck + [version 0.05] + + Reports which files are in the build directory but not in the + MANIFEST file, and vice versa. (See manifest for details.) + + distclean + [version 0.05] + + Performs the 'realclean' action and then the 'distcheck' action. + + distdir + [version 0.05] + + Creates a "distribution directory" named "$dist_name-$dist_version" + (if that directory already exists, it will be removed first), then + copies all the files listed in the MANIFEST file to that directory. + This directory is what the distribution tarball is created from. + + distinstall + [version 0.37] + + Performs the 'distdir' action, then switches into that directory and + runs a "perl Build.PL", followed by the 'build' and 'install' + actions in that directory. Use PERL_MB_OPT or .modulebuildrc to set + options that should be applied during subprocesses + + distmeta + [version 0.21] + + Creates the META.yml file that describes the distribution. + + META.yml is a file containing various bits of *metadata* about the + distribution. The metadata includes the distribution name, version, + abstract, prerequisites, license, and various other data about the + distribution. This file is created as META.yml in a simplified YAML + format. + + META.yml file must also be listed in MANIFEST - if it's not, a + warning will be issued. + + The current version of the META.yml specification can be found on + CPAN as CPAN::Meta::Spec. + + distsign + [version 0.16] + + Uses "Module::Signature" to create a SIGNATURE file for your + distribution, and adds the SIGNATURE file to the distribution's + MANIFEST. + + disttest + [version 0.05] + + Performs the 'distdir' action, then switches into that directory and + runs a "perl Build.PL", followed by the 'build' and 'test' actions + in that directory. Use PERL_MB_OPT or .modulebuildrc to set options + that should be applied during subprocesses + + docs + [version 0.20] + + This will generate documentation (e.g. Unix man pages and HTML + documents) for any installable items under blib/ that contain POD. + If there are no "bindoc" or "libdoc" installation targets defined + (as will be the case on systems that don't support Unix manpages) no + action is taken for manpages. If there are no "binhtml" or "libhtml" + installation targets defined no action is taken for HTML documents. + + fakeinstall + [version 0.02] + + This is just like the "install" action, but it won't actually do + anything, it will just report what it *would* have done if you had + actually run the "install" action. + + help + [version 0.03] + + This action will simply print out a message that is meant to help + you use the build process. It will show you a list of available + build actions too. + + With an optional argument specifying an action name (e.g. "Build + help test"), the 'help' action will show you any POD documentation + it can find for that action. + + html + [version 0.26] + + This will generate HTML documentation for any binary or library + files under blib/ that contain POD. The HTML documentation will only + be installed if the install paths can be determined from values in + "Config.pm". You can also supply or override install paths on the + command line by specifying "install_path" values for the "binhtml" + and/or "libhtml" installation targets. + + With an optional "html_links" argument set to a false value, you can + skip the search for other documentation to link to, because that can + waste a lot of time if there aren't any links to generate anyway: + + ./Build html --html_links 0 + + install + [version 0.01] + + This action will use "ExtUtils::Install" to install the files from + "blib/" into the system. See "INSTALL PATHS" for details about how + Module::Build determines where to install things, and how to + influence this process. + + If you want the installation process to look around in @INC for + other versions of the stuff you're installing and try to delete it, + you can use the "uninst" parameter, which tells "ExtUtils::Install" + to do so: + + ./Build install uninst=1 + + This can be a good idea, as it helps prevent multiple versions of a + module from being present on your system, which can be a confusing + situation indeed. + + installdeps + [version 0.36] + + This action will use the "cpan_client" parameter as a command to + install missing prerequisites. You will be prompted whether to + install optional dependencies. + + The "cpan_client" option defaults to 'cpan' but can be set as an + option or in .modulebuildrc. It must be a shell command that takes a + list of modules to install as arguments (e.g. 'cpanp -i' for + CPANPLUS). If the program part is a relative path (e.g. 'cpan' or + 'cpanp'), it will be located relative to the perl program that + executed Build.PL. + + /opt/perl/5.8.9/bin/perl Build.PL + ./Build installdeps --cpan_client 'cpanp -i' + # installs to 5.8.9 + + manifest + [version 0.05] + + This is an action intended for use by module authors, not people + installing modules. It will bring the MANIFEST up to date with the + files currently present in the distribution. You may use a + MANIFEST.SKIP file to exclude certain files or directories from + inclusion in the MANIFEST. MANIFEST.SKIP should contain a bunch of + regular expressions, one per line. If a file in the distribution + directory matches any of the regular expressions, it won't be + included in the MANIFEST. + + The following is a reasonable MANIFEST.SKIP starting point, you can + add your own stuff to it: + + ^_build + ^Build$ + ^blib + ~$ + \.bak$ + ^MANIFEST\.SKIP$ + CVS + + See the distcheck and skipcheck actions if you want to find out what + the "manifest" action would do, without actually doing anything. + + manifest_skip + [version 0.3608] + + This is an action intended for use by module authors, not people + installing modules. It will generate a boilerplate MANIFEST.SKIP + file if one does not already exist. + + manpages + [version 0.28] + + This will generate man pages for any binary or library files under + blib/ that contain POD. The man pages will only be installed if the + install paths can be determined from values in "Config.pm". You can + also supply or override install paths by specifying there values on + the command line with the "bindoc" and "libdoc" installation + targets. + + pardist + [version 0.2806] + + Generates a PAR binary distribution for use with PAR or PAR::Dist. + + It requires that the PAR::Dist module (version 0.17 and up) is + installed on your system. + + ppd [version 0.20] + + Build a PPD file for your distribution. + + This action takes an optional argument "codebase" which is used in + the generated PPD file to specify the (usually relative) URL of the + distribution. By default, this value is the distribution name + without any path information. + + Example: + + ./Build ppd --codebase "MSWin32-x86-multi-thread/Module-Build-0.21.tar.gz" + + ppmdist + [version 0.23] + + Generates a PPM binary distribution and a PPD description file. This + action also invokes the "ppd" action, so it can accept the same + "codebase" argument described under that action. + + This uses the same mechanism as the "dist" action to tar & zip its + output, so you can supply "tar" and/or "gzip" parameters to affect + the result. + + prereq_data + [version 0.32] + + This action prints out a Perl data structure of all prerequisites + and the versions required. The output can be loaded again using + "eval()". This can be useful for external tools that wish to query a + Build script for prerequisites. + + prereq_report + [version 0.28] + + This action prints out a list of all prerequisites, the versions + required, and the versions actually installed. This can be useful + for reviewing the configuration of your system prior to a build, or + when compiling data to send for a bug report. + + pure_install + [version 0.28] + + This action is identical to the "install" action. In the future, + though, when "install" starts writing to the file + $(INSTALLARCHLIB)/perllocal.pod, "pure_install" won't, and that will + be the only difference between them. + + realclean + [version 0.01] + + This action is just like the "clean" action, but also removes the + "_build" directory and the "Build" script. If you run the + "realclean" action, you are essentially starting over, so you will + have to re-create the "Build" script again. + + retest + [version 0.2806] + + This is just like the "test" action, but doesn't actually build the + distribution first, and doesn't add blib/ to the load path, and + therefore will test against a *previously* installed version of the + distribution. This can be used to verify that a certain installed + distribution still works, or to see whether newer versions of a + distribution still pass the old regression tests, and so on. + + skipcheck + [version 0.05] + + Reports which files are skipped due to the entries in the + MANIFEST.SKIP file (See manifest for details) + + test + [version 0.01] + + This will use "Test::Harness" or "TAP::Harness" to run any + regression tests and report their results. Tests can be defined in + the standard places: a file called "test.pl" in the top-level + directory, or several files ending with ".t" in a "t/" directory. + + If you want tests to be 'verbose', i.e. show details of test + execution rather than just summary information, pass the argument + "verbose=1". + + If you want to run tests under the perl debugger, pass the argument + "debugger=1". + + If you want to have Module::Build find test files with different + file name extensions, pass the "test_file_exts" argument with an + array of extensions, such as "[qw( .t .s .z )]". + + If you want test to be run by "TAP::Harness", rather than + "Test::Harness", pass the argument "tap_harness_args" as an array + reference of arguments to pass to the TAP::Harness constructor. + + In addition, if a file called "visual.pl" exists in the top-level + directory, this file will be executed as a Perl script and its + output will be shown to the user. This is a good place to put speed + tests or other tests that don't use the "Test::Harness" format for + output. + + To override the choice of tests to run, you may pass a "test_files" + argument whose value is a whitespace-separated list of test scripts + to run. This is especially useful in development, when you only want + to run a single test to see whether you've squashed a certain bug + yet: + + ./Build test --test_files t/something_failing.t + + You may also pass several "test_files" arguments separately: + + ./Build test --test_files t/one.t --test_files t/two.t + + or use a "glob()"-style pattern: + + ./Build test --test_files 't/01-*.t' + + testall + [version 0.2807] + + [Note: the 'testall' action and the code snippets below are + currently in alpha stage, see + "/www.nntp.perl.org/group/perl.module.build/2007/03/msg584.html"" in + "http: ] + + Runs the "test" action plus each of the "test$type" actions defined + by the keys of the "test_types" parameter. + + Currently, you need to define the ACTION_test$type method yourself + and enumerate them in the test_types parameter. + + my $mb = Module::Build->subclass( + code => q( + sub ACTION_testspecial { shift->generic_test(type => 'special'); } + sub ACTION_testauthor { shift->generic_test(type => 'author'); } + ) + )->new( + ... + test_types => { + special => '.st', + author => ['.at', '.pt' ], + }, + ... + + testcover + [version 0.26] + + Runs the "test" action using "Devel::Cover", generating a + code-coverage report showing which parts of the code were actually + exercised during the tests. + + To pass options to "Devel::Cover", set the $DEVEL_COVER_OPTIONS + environment variable: + + DEVEL_COVER_OPTIONS=-ignore,Build ./Build testcover + + testdb + [version 0.05] + + This is a synonym for the 'test' action with the "debugger=1" + argument. + + testpod + [version 0.25] + + This checks all the files described in the "docs" action and + produces "Test::Harness"-style output. If you are a module author, + this is useful to run before creating a new release. + + testpodcoverage + [version 0.28] + + This checks the pod coverage of the distribution and produces + "Test::Harness"-style output. If you are a module author, this is + useful to run before creating a new release. + + versioninstall + [version 0.16] + + ** Note: since "only.pm" is so new, and since we just recently added + support for it here too, this feature is to be considered + experimental. ** + + If you have the "only.pm" module installed on your system, you can + use this action to install a module into the version-specific + library trees. This means that you can have several versions of the + same module installed and "use" a specific one like this: + + use only MyModule => 0.55; + + To override the default installation libraries in "only::config", + specify the "versionlib" parameter when you run the "Build.PL" + script: + + perl Build.PL --versionlib /my/version/place/ + + To override which version the module is installed as, specify the + "version" parameter when you run the "Build.PL" script: + + perl Build.PL --version 0.50 + + See the "only.pm" documentation for more information on + version-specific installs. + +OPTIONS + Command Line Options + The following options can be used during any invocation of "Build.PL" or + the Build script, during any action. For information on other options + specific to an action, see the documentation for the respective action. + + NOTE: There is some preliminary support for options to use the more + familiar long option style. Most options can be preceded with the "--" + long option prefix, and the underscores changed to dashes (e.g. + "--use-rcfile"). Additionally, the argument to boolean options is + optional, and boolean options can be negated by prefixing them with "no" + or "no-" (e.g. "--noverbose" or "--no-verbose"). + + quiet + Suppress informative messages on output. + + verbose + Display extra information about the Build on output. "verbose" will + turn off "quiet" + + cpan_client + Sets the "cpan_client" command for use with the "installdeps" + action. See "installdeps" for more details. + + use_rcfile + Load the ~/.modulebuildrc option file. This option can be set to + false to prevent the custom resource file from being loaded. + + allow_mb_mismatch + Suppresses the check upon startup that the version of Module::Build + we're now running under is the same version that was initially + invoked when building the distribution (i.e. when the "Build.PL" + script was first run). As of 0.3601, a mismatch results in a warning + instead of a fatal error, so this option effectively just suppresses + the warning. + + debug + Prints Module::Build debugging information to STDOUT, such as a + trace of executed build actions. + + Default Options File (.modulebuildrc) + [version 0.28] + + When Module::Build starts up, it will look first for a file, + $ENV{HOME}/.modulebuildrc. If it's not found there, it will look in the + .modulebuildrc file in the directories referred to by the environment + variables "HOMEDRIVE" + "HOMEDIR", "USERPROFILE", "APPDATA", "WINDIR", + "SYS$LOGIN". If the file exists, the options specified there will be + used as defaults, as if they were typed on the command line. The + defaults can be overridden by specifying new values on the command line. + + The action name must come at the beginning of the line, followed by any + amount of whitespace and then the options. Options are given the same as + they would be on the command line. They can be separated by any amount + of whitespace, including newlines, as long there is whitespace at the + beginning of each continued line. Anything following a hash mark ("#") + is considered a comment, and is stripped before parsing. If more than + one line begins with the same action name, those lines are merged into + one set of options. + + Besides the regular actions, there are two special pseudo-actions: the + key "*" (asterisk) denotes any global options that should be applied to + all actions, and the key 'Build_PL' specifies options to be applied when + you invoke "perl Build.PL". + + * verbose=1 # global options + diff flags=-u + install --install_base /home/ken + --install_path html=/home/ken/docs/html + installdeps --cpan_client 'cpanp -i' + + If you wish to locate your resource file in a different location, you + can set the environment variable "MODULEBUILDRC" to the complete + absolute path of the file containing your options. + + Environment variables + MODULEBUILDRC + [version 0.28] + + Specifies an alternate location for a default options file as + described above. + + PERL_MB_OPT + [version 0.36] + + Command line options that are applied to Build.PL or any Build + action. The string is split as the shell would (e.g. whitespace) and + the result is prepended to any actual command-line arguments. + +INSTALL PATHS + [version 0.19] + + When you invoke Module::Build's "build" action, it needs to figure out + where to install things. The nutshell version of how this works is that + default installation locations are determined from Config.pm, and they + may be overridden by using the "install_path" parameter. An + "install_base" parameter lets you specify an alternative installation + root like /home/foo, and a "destdir" lets you specify a temporary + installation directory like /tmp/install in case you want to create + bundled-up installable packages. + + Natively, Module::Build provides default installation locations for the + following types of installable items: + + lib Usually pure-Perl module files ending in .pm. + + arch + "Architecture-dependent" module files, usually produced by compiling + XS, Inline, or similar code. + + script + Programs written in pure Perl. In order to improve reuse, try to + make these as small as possible - put the code into modules whenever + possible. + + bin "Architecture-dependent" executable programs, i.e. compiled C code + or something. Pretty rare to see this in a perl distribution, but it + happens. + + bindoc + Documentation for the stuff in "script" and "bin". Usually generated + from the POD in those files. Under Unix, these are manual pages + belonging to the 'man1' category. + + libdoc + Documentation for the stuff in "lib" and "arch". This is usually + generated from the POD in .pm files. Under Unix, these are manual + pages belonging to the 'man3' category. + + binhtml + This is the same as "bindoc" above, but applies to HTML documents. + + libhtml + This is the same as "libdoc" above, but applies to HTML documents. + + Four other parameters let you control various aspects of how + installation paths are determined: + + installdirs + The default destinations for these installable things come from + entries in your system's "Config.pm". You can select from three + different sets of default locations by setting the "installdirs" + parameter as follows: + + 'installdirs' set to: + core site vendor + + uses the following defaults from Config.pm: + + lib => installprivlib installsitelib installvendorlib + arch => installarchlib installsitearch installvendorarch + script => installscript installsitescript installvendorscript + bin => installbin installsitebin installvendorbin + bindoc => installman1dir installsiteman1dir installvendorman1dir + libdoc => installman3dir installsiteman3dir installvendorman3dir + binhtml => installhtml1dir installsitehtml1dir installvendorhtml1dir [*] + libhtml => installhtml3dir installsitehtml3dir installvendorhtml3dir [*] + + * Under some OS (eg. MSWin32) the destination for HTML documents is + determined by the C<Config.pm> entry C<installhtmldir>. + + The default value of "installdirs" is "site". If you're creating + vendor distributions of module packages, you may want to do + something like this: + + perl Build.PL --installdirs vendor + + or + + ./Build install --installdirs vendor + + If you're installing an updated version of a module that was + included with perl itself (i.e. a "core module"), then you may set + "installdirs" to "core" to overwrite the module in its present + location. + + (Note that the 'script' line is different from "MakeMaker" - + unfortunately there's no such thing as "installsitescript" or + "installvendorscript" entry in "Config.pm", so we use the + "installsitebin" and "installvendorbin" entries to at least get the + general location right. In the future, if "Config.pm" adds some more + appropriate entries, we'll start using those.) + + install_path + Once the defaults have been set, you can override them. + + On the command line, that would look like this: + + perl Build.PL --install_path lib=/foo/lib --install_path arch=/foo/lib/arch + + or this: + + ./Build install --install_path lib=/foo/lib --install_path arch=/foo/lib/arch + + install_base + You can also set the whole bunch of installation paths by supplying + the "install_base" parameter to point to a directory on your system. + For instance, if you set "install_base" to "/home/ken" on a Linux + system, you'll install as follows: + + lib => /home/ken/lib/perl5 + arch => /home/ken/lib/perl5/i386-linux + script => /home/ken/bin + bin => /home/ken/bin + bindoc => /home/ken/man/man1 + libdoc => /home/ken/man/man3 + binhtml => /home/ken/html + libhtml => /home/ken/html + + Note that this is *different* from how "MakeMaker"'s "PREFIX" + parameter works. "install_base" just gives you a default layout + under the directory you specify, which may have little to do with + the "installdirs=site" layout. + + The exact layout under the directory you specify may vary by system + - we try to do the "sensible" thing on each platform. + + destdir + If you want to install everything into a temporary directory first + (for instance, if you want to create a directory tree that a package + manager like "rpm" or "dpkg" could create a package from), you can + use the "destdir" parameter: + + perl Build.PL --destdir /tmp/foo + + or + + ./Build install --destdir /tmp/foo + + This will effectively install to "/tmp/foo/$sitelib", + "/tmp/foo/$sitearch", and the like, except that it will use + "File::Spec" to make the pathnames work correctly on whatever + platform you're installing on. + + prefix + Provided for compatibility with "ExtUtils::MakeMaker"'s PREFIX + argument. "prefix" should be used when you want Module::Build to + install your modules, documentation, and scripts in the same place + as "ExtUtils::MakeMaker"'s PREFIX mechanism. + + The following are equivalent. + + perl Build.PL --prefix /tmp/foo + perl Makefile.PL PREFIX=/tmp/foo + + Because of the complex nature of the prefixification logic, the + behavior of PREFIX in "MakeMaker" has changed subtly over time. + Module::Build's --prefix logic is equivalent to the PREFIX logic + found in "ExtUtils::MakeMaker" 6.30. + + The maintainers of "MakeMaker" do understand the troubles with the + PREFIX mechanism, and added INSTALL_BASE support in version 6.31 of + "MakeMaker", which was released in 2006. + + If you don't need to retain compatibility with old versions + (pre-6.31) of "ExtUtils::MakeMaker" or are starting a fresh Perl + installation we recommend you use "install_base" instead (and + "INSTALL_BASE" in "ExtUtils::MakeMaker"). See "Installing in the + same location as ExtUtils::MakeMaker" in Module::Build::Cookbook for + further information. + +MOTIVATIONS + There are several reasons I wanted to start over, and not just fix what + I didn't like about "MakeMaker": + + * I don't like the core idea of "MakeMaker", namely that "make" should + be involved in the build process. Here are my reasons: + + + When a person is installing a Perl module, what can you assume + about their environment? Can you assume they have "make"? No, + but you can assume they have some version of Perl. + + + When a person is writing a Perl module for intended + distribution, can you assume that they know how to build a + Makefile, so they can customize their build process? No, but you + can assume they know Perl, and could customize that way. + + For years, these things have been a barrier to people getting the + build/install process to do what they want. + + * There are several architectural decisions in "MakeMaker" that make + it very difficult to customize its behavior. For instance, when + using "MakeMaker" you do "use ExtUtils::MakeMaker", but the object + created in "WriteMakefile()" is actually blessed into a package name + that's created on the fly, so you can't simply subclass + "ExtUtils::MakeMaker". There is a workaround "MY" package that lets + you override certain "MakeMaker" methods, but only certain + explicitly preselected (by "MakeMaker") methods can be overridden. + Also, the method of customization is very crude: you have to modify + a string containing the Makefile text for the particular target. + Since these strings aren't documented, and *can't* be documented + (they take on different values depending on the platform, version of + perl, version of "MakeMaker", etc.), you have no guarantee that your + modifications will work on someone else's machine or after an + upgrade of "MakeMaker" or perl. + + * It is risky to make major changes to "MakeMaker", since it does so + many things, is so important, and generally works. "Module::Build" + is an entirely separate package so that I can work on it all I want, + without worrying about backward compatibility with "MakeMaker". + + * Finally, Perl is said to be a language for system administration. + Could it really be the case that Perl isn't up to the task of + building and installing software? Even if that software is a bunch + of ".pm" files that just need to be copied from one place to + another? My sense was that we could design a system to accomplish + this in a flexible, extensible, and friendly manner. Or die trying. + +TO DO + The current method of relying on time stamps to determine whether a + derived file is out of date isn't likely to scale well, since it + requires tracing all dependencies backward, it runs into problems on + NFS, and it's just generally flimsy. It would be better to use an MD5 + signature or the like, if available. See "cons" for an example. + + - append to perllocal.pod + - add a 'plugin' functionality + +AUTHOR + Ken Williams <kwilliams@cpan.org> + + Development questions, bug reports, and patches should be sent to the + Module-Build mailing list at <module-build@perl.org>. + + Bug reports are also welcome at + <http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Build>. + + The latest development version is available from the Git repository at + <https://github.com/Perl-Toolchain-Gang/Module-Build> + +COPYRIGHT + Copyright (c) 2001-2006 Ken Williams. All rights reserved. + + This library is free software; you can redistribute it and/or modify it + under the same terms as Perl itself. + +SEE ALSO + perl(1), Module::Build::Cookbook, Module::Build::Authoring, + Module::Build::API, ExtUtils::MakeMaker + + META.yml Specification: CPAN::Meta::Spec + + <http://www.dsmit.com/cons/> + + <http://search.cpan.org/dist/PerlBuildSystem/> + diff --git a/bin/config_data b/bin/config_data new file mode 100644 index 0000000..fcd5c4d --- /dev/null +++ b/bin/config_data @@ -0,0 +1,249 @@ +#!/usr/bin/perl + +use strict; +use Module::Build 0.25; +use Getopt::Long; + +my %opt_defs = ( + module => {type => '=s', + desc => 'The name of the module to configure (required)'}, + feature => {type => ':s', + desc => 'Print the value of a feature or all features'}, + config => {type => ':s', + desc => 'Print the value of a config option'}, + set_feature => {type => '=s%', + desc => "Set a feature to 'true' or 'false'"}, + set_config => {type => '=s%', + desc => 'Set a config option to the given value'}, + eval => {type => '', + desc => 'eval() config values before setting'}, + help => {type => '', + desc => 'Print a help message and exit'}, + ); + +my %opts; +GetOptions( \%opts, map "$_$opt_defs{$_}{type}", keys %opt_defs ) or die usage(%opt_defs); +print usage(%opt_defs) and exit(0) + if $opts{help}; + +my @exclusive = qw(feature config set_feature set_config); +die "Exactly one of the options '" . join("', '", @exclusive) . "' must be specified\n" . usage(%opt_defs) + unless grep(exists $opts{$_}, @exclusive) == 1; + +die "Option --module is required\n" . usage(%opt_defs) + unless $opts{module}; + +my $cf = load_config($opts{module}); + +if (exists $opts{feature}) { + + if (length $opts{feature}) { + print $cf->feature($opts{feature}); + } else { + my %auto; + # note: need to support older ConfigData.pm's + @auto{$cf->auto_feature_names} = () if $cf->can("auto_feature_names"); + + print " Features defined in $cf:\n"; + foreach my $name (sort $cf->feature_names) { + print " $name => ", $cf->feature($name), (exists $auto{$name} ? " (dynamic)" : ""), "\n"; + } + } + +} elsif (exists $opts{config}) { + + require Data::Dumper; + local $Data::Dumper::Terse = 1; + + if (length $opts{config}) { + print Data::Dumper::Dumper($cf->config($opts{config})), "\n"; + } else { + print " Configuration defined in $cf:\n"; + foreach my $name (sort $cf->config_names) { + print " $name => ", Data::Dumper::Dumper($cf->config($name)), "\n"; + } + } + +} elsif (exists $opts{set_feature}) { + my %to_set = %{$opts{set_feature}}; + while (my ($k, $v) = each %to_set) { + die "Feature value must be 0 or 1\n" unless $v =~ /^[01]$/; + $cf->set_feature($k, 0+$v); # Cast to a number, not a string + } + $cf->write; + print "Feature" . 's'x(keys(%to_set)>1) . " saved\n"; + +} elsif (exists $opts{set_config}) { + + my %to_set = %{$opts{set_config}}; + while (my ($k, $v) = each %to_set) { + if ($opts{eval}) { + $v = eval($v); + die $@ if $@; + } + $cf->set_config($k, $v); + } + $cf->write; + print "Config value" . 's'x(keys(%to_set)>1) . " saved\n"; +} + +sub load_config { + my $mod = shift; + + $mod =~ /^([\w:]+)$/ + or die "Invalid module name '$mod'"; + + my $cf = $mod . "::ConfigData"; + eval "require $cf"; + die $@ if $@; + + return $cf; +} + +sub usage { + my %defs = @_; + + my $out = "\nUsage: $0 [options]\n\n Options include:\n"; + + foreach my $name (sort keys %defs) { + $out .= " --$name"; + + for ($defs{$name}{type}) { + /^=s$/ and $out .= " <string>"; + /^=s%$/ and $out .= " <string>=<value>"; + } + + pad_line($out, 35); + $out .= "$defs{$name}{desc}\n"; + } + + $out .= <<EOF; + + Examples: + $0 --module Foo::Bar --feature bazzable + $0 --module Foo::Bar --config magic_number + $0 --module Foo::Bar --set_feature bazzable=1 + $0 --module Foo::Bar --set_config magic_number=42 + +EOF + + return $out; +} + +sub pad_line { $_[0] .= ' ' x ($_[1] - length($_[0]) + rindex($_[0], "\n")) } + + +__END__ + +=head1 NAME + +config_data - Query or change configuration of Perl modules + +=head1 SYNOPSIS + + # Get config/feature values + config_data --module Foo::Bar --feature bazzable + config_data --module Foo::Bar --config magic_number + + # Set config/feature values + config_data --module Foo::Bar --set_feature bazzable=1 + config_data --module Foo::Bar --set_config magic_number=42 + + # Print a usage message + config_data --help + +=head1 DESCRIPTION + +The C<config_data> tool provides a command-line interface to the +configuration of Perl modules. By "configuration", we mean something +akin to "user preferences" or "local settings". This is a +formalization and abstraction of the systems that people like Andreas +Koenig (C<CPAN::Config>), Jon Swartz (C<HTML::Mason::Config>), Andy +Wardley (C<Template::Config>), and Larry Wall (perl's own Config.pm) +have developed independently. + +The configuration system employed here was developed in the context of +C<Module::Build>. Under this system, configuration information for a +module C<Foo>, for example, is stored in a module called +C<Foo::ConfigData>) (I would have called it C<Foo::Config>, but that +was taken by all those other systems mentioned in the previous +paragraph...). These C<...::ConfigData> modules contain the +configuration data, as well as publicly accessible methods for +querying and setting (yes, actually re-writing) the configuration +data. The C<config_data> script (whose docs you are currently +reading) is merely a front-end for those methods. If you wish, you +may create alternate front-ends. + +The two types of data that may be stored are called C<config> values +and C<feature> values. A C<config> value may be any perl scalar, +including references to complex data structures. It must, however, be +serializable using C<Data::Dumper>. A C<feature> is a boolean (1 or +0) value. + +=head1 USAGE + +This script functions as a basic getter/setter wrapper around the +configuration of a single module. On the command line, specify which +module's configuration you're interested in, and pass options to get +or set C<config> or C<feature> values. The following options are +supported: + +=over 4 + +=item module + +Specifies the name of the module to configure (required). + +=item feature + +When passed the name of a C<feature>, shows its value. The value will +be 1 if the feature is enabled, 0 if the feature is not enabled, or +empty if the feature is unknown. When no feature name is supplied, +the names and values of all known features will be shown. + +=item config + +When passed the name of a C<config> entry, shows its value. The value +will be displayed using C<Data::Dumper> (or similar) as perl code. +When no config name is supplied, the names and values of all known +config entries will be shown. + +=item set_feature + +Sets the given C<feature> to the given boolean value. Specify the value +as either 1 or 0. + +=item set_config + +Sets the given C<config> entry to the given value. + +=item eval + +If the C<--eval> option is used, the values in C<set_config> will be +evaluated as perl code before being stored. This allows moderately +complicated data structures to be stored. For really complicated +structures, you probably shouldn't use this command-line interface, +just use the Perl API instead. + +=item help + +Prints a help message, including a few examples, and exits. + +=back + +=head1 AUTHOR + +Ken Williams, kwilliams@cpan.org + +=head1 COPYRIGHT + +Copyright (c) 1999, Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=head1 SEE ALSO + +Module::Build(3), perl(1). + +=cut diff --git a/contrib/bash_completion.module-build b/contrib/bash_completion.module-build new file mode 100644 index 0000000..ac95177 --- /dev/null +++ b/contrib/bash_completion.module-build @@ -0,0 +1,39 @@ +# Module::Build Bash completion function +# Contributed by Julian Mehnle <julian@mehnle.net> +# $Id$ +# vim:syn=sh + +if + actions=$( + perl -M'Module::Build' -le 'print foreach Module::Build->known_actions' 2>/dev/null + ) && + properties=$( + perl -M'Module::Build' -le 'print foreach sort Module::Build->valid_properties' 2>/dev/null + ) +then + eval "_Build_actions () { echo '$actions'; }" + eval "_Build_properties () { echo '$properties'; }" + unset -v actions properties + + _Build () { + local word=${COMP_WORDS[COMP_CWORD]} + #local prev_word=${COMP_WORDS[COMP_CWORD-1]} + #local action=${COMP_WORDS[1]} + + if (( $COMP_CWORD == 1 )); then + # Complete actions: + local IFS_org="$IFS" + IFS=$'\x1F\t\n' + # Avoid space (\x20) as a word separator to make the following -S ' ' work. + COMPREPLY=($( compgen -W "$(_Build_actions)" -S ' ' -- "$word" )) + IFS="$IFS_org" + else + # Complete properties: + COMPREPLY=($( compgen -W "$(_Build_properties)" -S = -- "$word" )) + fi + + return 0 + } + + complete -o nospace -F _Build Build +fi diff --git a/inc/MBVersion.pm b/inc/MBVersion.pm new file mode 100644 index 0000000..558a9ff --- /dev/null +++ b/inc/MBVersion.pm @@ -0,0 +1,1187 @@ +# Bootstrap pure-perl version +package MB::Version; +use strict; + +use vars qw($VERSION); +$VERSION = 0.86; + +eval "use version $VERSION"; +if ($@) { # can't locate new enough version files, use our own + # We might be here because version.pm was present but there was + # an error, so make we want to be sure users see what's happening + # We also need to clear %INC entries, as the "undef" for a broken + # version.pm can't be directly overwritten later. + if ( exists $INC{'version.pm'} && ! defined $INC{'version.pm'} ) { + warn "Error loading version.pm: $@\n"; + warn "Using Module::Build::Version bundled version code instead.\n"; + delete $INC{'version.pm'}; + delete $INC{'version/vpp.pm'}; + } + + # Avoid redefined warnings if an old version.pm was available + delete $version::{$_} foreach keys %version::; + + # first we get the stub version module + my $version; + while (<DATA>) { + s/(\$VERSION)\s=\s\d+/\$VERSION = 0/; + $version .= $_ if $_; + last if /^1;$/; + } + + # and now get the current version::vpp code + my $vpp; + while (<DATA>) { + s/(\$VERSION)\s=\s\d+/\$VERSION = 0/; + $vpp .= $_ if $_; + last if /^1;$/; + } + + # but we eval them in reverse order since version depends on + # version::vpp to already exist + eval $vpp; die $@ if $@; + $INC{'version/vpp.pm'} = 'inside Module::Build::Version'; + eval $version; die $@ if $@; + $INC{'version.pm'} = 'inside Module::Build::Version'; +} + +1; +__DATA__ +# XXX replace everything from here to the next XXX with the +# contents of version.pm from CPAN and then edit to ensure +# the XS clause is not invoked and comment out the line about +# C<< eval "use version::vpp $VERSION"; >> since we provide +# our own copy + +package version; + +use 5.005_04; +use strict; + +use vars qw(@ISA $VERSION $CLASS $STRICT $LAX *declare *qv); + +$VERSION = 0.87; + +$CLASS = 'version'; + +#--------------------------------------------------------------------------# +# Version regexp components +#--------------------------------------------------------------------------# + +# Fraction part of a decimal version number. This is a common part of +# both strict and lax decimal versions + +my $FRACTION_PART = qr/\.[0-9]+/; + +# First part of either decimal or dotted-decimal strict version number. +# Unsigned integer with no leading zeroes (except for zero itself) to +# avoid confusion with octal. + +my $STRICT_INTEGER_PART = qr/0|[1-9][0-9]*/; + +# First part of either decimal or dotted-decimal lax version number. +# Unsigned integer, but allowing leading zeros. Always interpreted +# as decimal. However, some forms of the resulting syntax give odd +# results if used as ordinary Perl expressions, due to how perl treats +# octals. E.g. +# version->new("010" ) == 10 +# version->new( 010 ) == 8 +# version->new( 010.2) == 82 # "8" . "2" + +my $LAX_INTEGER_PART = qr/[0-9]+/; + +# Second and subsequent part of a strict dotted-decimal version number. +# Leading zeroes are permitted, and the number is always decimal. +# Limited to three digits to avoid overflow when converting to decimal +# form and also avoid problematic style with excessive leading zeroes. + +my $STRICT_DOTTED_DECIMAL_PART = qr/\.[0-9]{1,3}/; + +# Second and subsequent part of a lax dotted-decimal version number. +# Leading zeroes are permitted, and the number is always decimal. No +# limit on the numerical value or number of digits, so there is the +# possibility of overflow when converting to decimal form. + +my $LAX_DOTTED_DECIMAL_PART = qr/\.[0-9]+/; + +# Alpha suffix part of lax version number syntax. Acts like a +# dotted-decimal part. + +my $LAX_ALPHA_PART = qr/_[0-9]+/; + +#--------------------------------------------------------------------------# +# Strict version regexp definitions +#--------------------------------------------------------------------------# + +# Strict decimal version number. + +my $STRICT_DECIMAL_VERSION = + qr/ $STRICT_INTEGER_PART $FRACTION_PART? /x; + +# Strict dotted-decimal version number. Must have both leading "v" and +# at least three parts, to avoid confusion with decimal syntax. + +my $STRICT_DOTTED_DECIMAL_VERSION = + qr/ v $STRICT_INTEGER_PART $STRICT_DOTTED_DECIMAL_PART{2,} /x; + +# Complete strict version number syntax -- should generally be used +# anchored: qr/ \A $STRICT \z /x + +$STRICT = + qr/ $STRICT_DECIMAL_VERSION | $STRICT_DOTTED_DECIMAL_VERSION /x; + +#--------------------------------------------------------------------------# +# Lax version regexp definitions +#--------------------------------------------------------------------------# + +# Lax decimal version number. Just like the strict one except for +# allowing an alpha suffix or allowing a leading or trailing +# decimal-point + +my $LAX_DECIMAL_VERSION = + qr/ $LAX_INTEGER_PART (?: \. | $FRACTION_PART $LAX_ALPHA_PART? )? + | + $FRACTION_PART $LAX_ALPHA_PART? + /x; + +# Lax dotted-decimal version number. Distinguished by having either +# leading "v" or at least three non-alpha parts. Alpha part is only +# permitted if there are at least two non-alpha parts. Strangely +# enough, without the leading "v", Perl takes .1.2 to mean v0.1.2, +# so when there is no "v", the leading part is optional + +my $LAX_DOTTED_DECIMAL_VERSION = + qr/ + v $LAX_INTEGER_PART (?: $LAX_DOTTED_DECIMAL_PART+ $LAX_ALPHA_PART? )? + | + $LAX_INTEGER_PART? $LAX_DOTTED_DECIMAL_PART{2,} $LAX_ALPHA_PART? + /x; + +# Complete lax version number syntax -- should generally be used +# anchored: qr/ \A $LAX \z /x +# +# The string 'undef' is a special case to make for easier handling +# of return values from ExtUtils::MM->parse_version + +$LAX = + qr/ undef | $LAX_DECIMAL_VERSION | $LAX_DOTTED_DECIMAL_VERSION /x; + +#--------------------------------------------------------------------------# + +#eval "use version::vxs $VERSION"; XXX DONT TRY XS +if ( 1 ) { # XXX FORCE PURE PERL +# eval "use version::vpp $VERSION"; # don't tempt fate +# die "$@" if ( $@ ); + push @ISA, "version::vpp"; + local $^W; + *version::qv = \&version::vpp::qv; + *version::declare = \&version::vpp::declare; + *version::_VERSION = \&version::vpp::_VERSION; + if ($] >= 5.009000 && $] < 5.011004) { + no strict 'refs'; + *version::stringify = \&version::vpp::stringify; + *{'version::(""'} = \&version::vpp::stringify; + *version::new = \&version::vpp::new; + *version::parse = \&version::vpp::parse; + } +} +else { # use XS module +# XXX NO XS FOR US -- WE DELETED IT +} + +# Preloaded methods go here. +sub import { + no strict 'refs'; + my ($class) = shift; + + # Set up any derived class + unless ($class eq 'version') { + local $^W; + *{$class.'::declare'} = \&version::declare; + *{$class.'::qv'} = \&version::qv; + } + + my %args; + if (@_) { # any remaining terms are arguments + map { $args{$_} = 1 } @_ + } + else { # no parameters at all on use line + %args = + ( + qv => 1, + 'UNIVERSAL::VERSION' => 1, + ); + } + + my $callpkg = caller(); + + if (exists($args{declare})) { + *{$callpkg.'::declare'} = + sub {return $class->declare(shift) } + unless defined(&{$callpkg.'::declare'}); + } + + if (exists($args{qv})) { + *{$callpkg.'::qv'} = + sub {return $class->qv(shift) } + unless defined(&{$callpkg.'::qv'}); + } + + if (exists($args{'UNIVERSAL::VERSION'})) { + local $^W; + *UNIVERSAL::VERSION + = \&version::_VERSION; + } + + if (exists($args{'VERSION'})) { + *{$callpkg.'::VERSION'} = \&version::_VERSION; + } + + if (exists($args{'is_strict'})) { + *{$callpkg.'::is_strict'} = \&version::is_strict + unless defined(&{$callpkg.'::is_strict'}); + } + + if (exists($args{'is_lax'})) { + *{$callpkg.'::is_lax'} = \&version::is_lax + unless defined(&{$callpkg.'::is_lax'}); + } +} + +sub is_strict { defined $_[0] && $_[0] =~ qr/ \A $STRICT \z /x } +sub is_lax { defined $_[0] && $_[0] =~ qr/ \A $LAX \z /x } + +1; + +# XXX replace everything from here to the end with the current version/vpp.pm + +package charstar; +# a little helper class to emulate C char* semantics in Perl +# so that prescan_version can use the same code as in C + +use overload ( + '""' => \&thischar, + '0+' => \&thischar, + '++' => \&increment, + '--' => \&decrement, + '+' => \&plus, + '-' => \&minus, + '*' => \&multiply, + 'cmp' => \&cmp, + '<=>' => \&spaceship, + 'bool' => \&thischar, + '=' => \&clone, +); + +sub new { + my ($self, $string) = @_; + my $class = ref($self) || $self; + + my $obj = { + string => [split(//,$string)], + current => 0, + }; + return bless $obj, $class; +} + +sub thischar { + my ($self) = @_; + my $last = $#{$self->{string}}; + my $curr = $self->{current}; + if ($curr >= 0 && $curr <= $last) { + return $self->{string}->[$curr]; + } + else { + return ''; + } +} + +sub increment { + my ($self) = @_; + $self->{current}++; +} + +sub decrement { + my ($self) = @_; + $self->{current}--; +} + +sub plus { + my ($self, $offset) = @_; + my $rself = $self->clone; + $rself->{current} += $offset; + return $rself; +} + +sub minus { + my ($self, $offset) = @_; + my $rself = $self->clone; + $rself->{current} -= $offset; + return $rself; +} + +sub multiply { + my ($left, $right, $swapped) = @_; + my $char = $left->thischar(); + return $char * $right; +} + +sub spaceship { + my ($left, $right, $swapped) = @_; + unless (ref($right)) { # not an object already + $right = $left->new($right); + } + return $left->{current} <=> $right->{current}; +} + +sub cmp { + my ($left, $right, $swapped) = @_; + unless (ref($right)) { # not an object already + if (length($right) == 1) { # comparing single character only + return $left->thischar cmp $right; + } + $right = $left->new($right); + } + return $left->currstr cmp $right->currstr; +} + +sub bool { + my ($self) = @_; + my $char = $self->thischar; + return ($char ne ''); +} + +sub clone { + my ($left, $right, $swapped) = @_; + $right = { + string => [@{$left->{string}}], + current => $left->{current}, + }; + return bless $right, ref($left); +} + +sub currstr { + my ($self, $s) = @_; + my $curr = $self->{current}; + my $last = $#{$self->{string}}; + if (defined($s) && $s->{current} < $last) { + $last = $s->{current}; + } + + my $string = join('', @{$self->{string}}[$curr..$last]); + return $string; +} + +package version::vpp; +use strict; + +use POSIX qw/locale_h/; +use locale; +use vars qw ($VERSION @ISA @REGEXS); +$VERSION = 0.87; + +use overload ( + '""' => \&stringify, + '0+' => \&numify, + 'cmp' => \&vcmp, + '<=>' => \&vcmp, + 'bool' => \&vbool, + 'nomethod' => \&vnoop, +); + +eval "use warnings"; +if ($@) { + eval ' + package warnings; + sub enabled {return $^W;} + 1; + '; +} + +my $VERSION_MAX = 0x7FFFFFFF; + +# implement prescan_version as closely to the C version as possible +use constant TRUE => 1; +use constant FALSE => 0; + +sub isDIGIT { + my ($char) = shift->thischar(); + return ($char =~ /\d/); +} + +sub isALPHA { + my ($char) = shift->thischar(); + return ($char =~ /[a-zA-Z]/); +} + +sub isSPACE { + my ($char) = shift->thischar(); + return ($char =~ /\s/); +} + +sub BADVERSION { + my ($s, $errstr, $error) = @_; + if ($errstr) { + $$errstr = $error; + } + return $s; +} + +sub prescan_version { + my ($s, $strict, $errstr, $sqv, $ssaw_decimal, $swidth, $salpha) = @_; + my $qv = defined $sqv ? $$sqv : FALSE; + my $saw_decimal = defined $ssaw_decimal ? $$ssaw_decimal : 0; + my $width = defined $swidth ? $$swidth : 3; + my $alpha = defined $salpha ? $$salpha : FALSE; + + my $d = $s; + + if ($qv && isDIGIT($d)) { + goto dotted_decimal_version; + } + + if ($d eq 'v') { # explicit v-string + $d++; + if (isDIGIT($d)) { + $qv = TRUE; + } + else { # degenerate v-string + # requires v1.2.3 + return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); + } + +dotted_decimal_version: + if ($strict && $d eq '0' && isDIGIT($d+1)) { + # no leading zeros allowed + return BADVERSION($s,$errstr,"Invalid version format (no leading zeros)"); + } + + while (isDIGIT($d)) { # integer part + $d++; + } + + if ($d eq '.') + { + $saw_decimal++; + $d++; # decimal point + } + else + { + if ($strict) { + # require v1.2.3 + return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); + } + else { + goto version_prescan_finish; + } + } + + { + my $i = 0; + my $j = 0; + while (isDIGIT($d)) { # just keep reading + $i++; + while (isDIGIT($d)) { + $d++; $j++; + # maximum 3 digits between decimal + if ($strict && $j > 3) { + return BADVERSION($s,$errstr,"Invalid version format (maximum 3 digits between decimals)"); + } + } + if ($d eq '_') { + if ($strict) { + return BADVERSION($s,$errstr,"Invalid version format (no underscores)"); + } + if ( $alpha ) { + return BADVERSION($s,$errstr,"Invalid version format (multiple underscores)"); + } + $d++; + $alpha = TRUE; + } + elsif ($d eq '.') { + if ($alpha) { + return BADVERSION($s,$errstr,"Invalid version format (underscores before decimal)"); + } + $saw_decimal++; + $d++; + } + elsif (!isDIGIT($d)) { + last; + } + $j = 0; + } + + if ($strict && $i < 2) { + # requires v1.2.3 + return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions require at least three parts)"); + } + } + } # end if dotted-decimal + else + { # decimal versions + # special $strict case for leading '.' or '0' + if ($strict) { + if ($d eq '.') { + return BADVERSION($s,$errstr,"Invalid version format (0 before decimal required)"); + } + if ($d eq '0' && isDIGIT($d+1)) { + return BADVERSION($s,$errstr,"Invalid version format (no leading zeros)"); + } + } + + # consume all of the integer part + while (isDIGIT($d)) { + $d++; + } + + # look for a fractional part + if ($d eq '.') { + # we found it, so consume it + $saw_decimal++; + $d++; + } + elsif (!$d || $d eq ';' || isSPACE($d) || $d eq '}') { + if ( $d == $s ) { + # found nothing + return BADVERSION($s,$errstr,"Invalid version format (version required)"); + } + # found just an integer + goto version_prescan_finish; + } + elsif ( $d == $s ) { + # didn't find either integer or period + return BADVERSION($s,$errstr,"Invalid version format (non-numeric data)"); + } + elsif ($d eq '_') { + # underscore can't come after integer part + if ($strict) { + return BADVERSION($s,$errstr,"Invalid version format (no underscores)"); + } + elsif (isDIGIT($d+1)) { + return BADVERSION($s,$errstr,"Invalid version format (alpha without decimal)"); + } + else { + return BADVERSION($s,$errstr,"Invalid version format (misplaced underscore)"); + } + } + elsif ($d) { + # anything else after integer part is just invalid data + return BADVERSION($s,$errstr,"Invalid version format (non-numeric data)"); + } + + # scan the fractional part after the decimal point + if ($d && !isDIGIT($d) && ($strict || ! ($d eq ';' || isSPACE($d) || $d eq '}') )) { + # $strict or lax-but-not-the-end + return BADVERSION($s,$errstr,"Invalid version format (fractional part required)"); + } + + while (isDIGIT($d)) { + $d++; + if ($d eq '.' && isDIGIT($d-1)) { + if ($alpha) { + return BADVERSION($s,$errstr,"Invalid version format (underscores before decimal)"); + } + if ($strict) { + return BADVERSION($s,$errstr,"Invalid version format (dotted-decimal versions must begin with 'v')"); + } + $d = $s; # start all over again + $qv = TRUE; + goto dotted_decimal_version; + } + if ($d eq '_') { + if ($strict) { + return BADVERSION($s,$errstr,"Invalid version format (no underscores)"); + } + if ( $alpha ) { + return BADVERSION($s,$errstr,"Invalid version format (multiple underscores)"); + } + if ( ! isDIGIT($d+1) ) { + return BADVERSION($s,$errstr,"Invalid version format (misplaced underscore)"); + } + $d++; + $alpha = TRUE; + } + } + } + +version_prescan_finish: + while (isSPACE($d)) { + $d++; + } + + if ($d && !isDIGIT($d) && (! ($d eq ';' || $d eq '}') )) { + # trailing non-numeric data + return BADVERSION($s,$errstr,"Invalid version format (non-numeric data)"); + } + + if (defined $sqv) { + $$sqv = $qv; + } + if (defined $swidth) { + $$swidth = $width; + } + if (defined $ssaw_decimal) { + $$ssaw_decimal = $saw_decimal; + } + if (defined $salpha) { + $$salpha = $alpha; + } + return $d; +} + +sub scan_version { + my ($s, $rv, $qv) = @_; + my $start; + my $pos; + my $last; + my $errstr; + my $saw_decimal = 0; + my $width = 3; + my $alpha = FALSE; + my $vinf = FALSE; + my @av; + + $s = new charstar $s; + + while (isSPACE($s)) { # leading whitespace is OK + $s++; + } + + $last = prescan_version($s, FALSE, \$errstr, \$qv, \$saw_decimal, + \$width, \$alpha); + + if ($errstr) { + # 'undef' is a special case and not an error + if ( $s ne 'undef') { + use Carp; + Carp::croak($errstr); + } + } + + $start = $s; + if ($s eq 'v') { + $s++; + } + $pos = $s; + + if ( $qv ) { + $$rv->{qv} = $qv; + } + if ( $alpha ) { + $$rv->{alpha} = $alpha; + } + if ( !$qv && $width < 3 ) { + $$rv->{width} = $width; + } + + while (isDIGIT($pos)) { + $pos++; + } + if (!isALPHA($pos)) { + my $rev; + + for (;;) { + $rev = 0; + { + # this is atoi() that delimits on underscores + my $end = $pos; + my $mult = 1; + my $orev; + + # the following if() will only be true after the decimal + # point of a version originally created with a bare + # floating point number, i.e. not quoted in any way + # + if ( !$qv && $s > $start && $saw_decimal == 1 ) { + $mult *= 100; + while ( $s < $end ) { + $orev = $rev; + $rev += $s * $mult; + $mult /= 10; + if ( (abs($orev) > abs($rev)) + || (abs($rev) > $VERSION_MAX )) { + warn("Integer overflow in version %d", + $VERSION_MAX); + $s = $end - 1; + $rev = $VERSION_MAX; + $vinf = 1; + } + $s++; + if ( $s eq '_' ) { + $s++; + } + } + } + else { + while (--$end >= $s) { + $orev = $rev; + $rev += $end * $mult; + $mult *= 10; + if ( (abs($orev) > abs($rev)) + || (abs($rev) > $VERSION_MAX )) { + warn("Integer overflow in version"); + $end = $s - 1; + $rev = $VERSION_MAX; + $vinf = 1; + } + } + } + } + + # Append revision + push @av, $rev; + if ( $vinf ) { + $s = $last; + last; + } + elsif ( $pos eq '.' ) { + $s = ++$pos; + } + elsif ( $pos eq '_' && isDIGIT($pos+1) ) { + $s = ++$pos; + } + elsif ( $pos eq ',' && isDIGIT($pos+1) ) { + $s = ++$pos; + } + elsif ( isDIGIT($pos) ) { + $s = $pos; + } + else { + $s = $pos; + last; + } + if ( $qv ) { + while ( isDIGIT($pos) ) { + $pos++; + } + } + else { + my $digits = 0; + while ( ( isDIGIT($pos) || $pos eq '_' ) && $digits < 3 ) { + if ( $pos ne '_' ) { + $digits++; + } + $pos++; + } + } + } + } + if ( $qv ) { # quoted versions always get at least three terms + my $len = $#av; + # This for loop appears to trigger a compiler bug on OS X, as it + # loops infinitely. Yes, len is negative. No, it makes no sense. + # Compiler in question is: + # gcc version 3.3 20030304 (Apple Computer, Inc. build 1640) + # for ( len = 2 - len; len > 0; len-- ) + # av_push(MUTABLE_AV(sv), newSViv(0)); + # + $len = 2 - $len; + while ($len-- > 0) { + push @av, 0; + } + } + + # need to save off the current version string for later + if ( $vinf ) { + $$rv->{original} = "v.Inf"; + $$rv->{vinf} = 1; + } + elsif ( $s > $start ) { + $$rv->{original} = $start->currstr($s); + if ( $qv && $saw_decimal == 1 && $start ne 'v' ) { + # need to insert a v to be consistent + $$rv->{original} = 'v' . $$rv->{original}; + } + } + else { + $$rv->{original} = '0'; + push(@av, 0); + } + + # And finally, store the AV in the hash + $$rv->{version} = \@av; + + # fix RT#19517 - special case 'undef' as string + if ($s eq 'undef') { + $s += 5; + } + + return $s; +} + +sub new +{ + my ($class, $value) = @_; + my $self = bless ({}, ref ($class) || $class); + my $qv = FALSE; + + if ( ref($value) && eval('$value->isa("version")') ) { + # Can copy the elements directly + $self->{version} = [ @{$value->{version} } ]; + $self->{qv} = 1 if $value->{qv}; + $self->{alpha} = 1 if $value->{alpha}; + $self->{original} = ''.$value->{original}; + return $self; + } + + my $currlocale = setlocale(LC_ALL); + + # if the current locale uses commas for decimal points, we + # just replace commas with decimal places, rather than changing + # locales + if ( localeconv()->{decimal_point} eq ',' ) { + $value =~ tr/,/./; + } + + if ( not defined $value or $value =~ /^undef$/ ) { + # RT #19517 - special case for undef comparison + # or someone forgot to pass a value + push @{$self->{version}}, 0; + $self->{original} = "0"; + return ($self); + } + + if ( $#_ == 2 ) { # must be CVS-style + $value = $_[2]; + $qv = TRUE; + } + + $value = _un_vstring($value); + + # exponential notation + if ( $value =~ /\d+.?\d*e[-+]?\d+/ ) { + $value = sprintf("%.9f",$value); + $value =~ s/(0+)$//; # trim trailing zeros + } + + my $s = scan_version($value, \$self, $qv); + + if ($s) { # must be something left over + warn("Version string '%s' contains invalid data; " + ."ignoring: '%s'", $value, $s); + } + + return ($self); +} + +*parse = \&new; + +sub numify +{ + my ($self) = @_; + unless (_verify($self)) { + require Carp; + Carp::croak("Invalid version object"); + } + my $width = $self->{width} || 3; + my $alpha = $self->{alpha} || ""; + my $len = $#{$self->{version}}; + my $digit = $self->{version}[0]; + my $string = sprintf("%d.", $digit ); + + for ( my $i = 1 ; $i < $len ; $i++ ) { + $digit = $self->{version}[$i]; + if ( $width < 3 ) { + my $denom = 10**(3-$width); + my $quot = int($digit/$denom); + my $rem = $digit - ($quot * $denom); + $string .= sprintf("%0".$width."d_%d", $quot, $rem); + } + else { + $string .= sprintf("%03d", $digit); + } + } + + if ( $len > 0 ) { + $digit = $self->{version}[$len]; + if ( $alpha && $width == 3 ) { + $string .= "_"; + } + $string .= sprintf("%0".$width."d", $digit); + } + else # $len = 0 + { + $string .= sprintf("000"); + } + + return $string; +} + +sub normal +{ + my ($self) = @_; + unless (_verify($self)) { + require Carp; + Carp::croak("Invalid version object"); + } + my $alpha = $self->{alpha} || ""; + my $len = $#{$self->{version}}; + my $digit = $self->{version}[0]; + my $string = sprintf("v%d", $digit ); + + for ( my $i = 1 ; $i < $len ; $i++ ) { + $digit = $self->{version}[$i]; + $string .= sprintf(".%d", $digit); + } + + if ( $len > 0 ) { + $digit = $self->{version}[$len]; + if ( $alpha ) { + $string .= sprintf("_%0d", $digit); + } + else { + $string .= sprintf(".%0d", $digit); + } + } + + if ( $len <= 2 ) { + for ( $len = 2 - $len; $len != 0; $len-- ) { + $string .= sprintf(".%0d", 0); + } + } + + return $string; +} + +sub stringify +{ + my ($self) = @_; + unless (_verify($self)) { + require Carp; + Carp::croak("Invalid version object"); + } + return exists $self->{original} + ? $self->{original} + : exists $self->{qv} + ? $self->normal + : $self->numify; +} + +sub vcmp +{ + my ($left,$right,$swap) = @_; + my $class = ref($left); + unless ( eval { $right->isa($class) } ) { + $right = $class->new($right); + } + + if ( $swap ) { + ($left, $right) = ($right, $left); + } + unless (_verify($left)) { + require Carp; + Carp::croak("Invalid version object"); + } + unless (_verify($right)) { + require Carp; + Carp::croak("Invalid version object"); + } + my $l = $#{$left->{version}}; + my $r = $#{$right->{version}}; + my $m = $l < $r ? $l : $r; + my $lalpha = $left->is_alpha; + my $ralpha = $right->is_alpha; + my $retval = 0; + my $i = 0; + while ( $i <= $m && $retval == 0 ) { + $retval = $left->{version}[$i] <=> $right->{version}[$i]; + $i++; + } + + # tiebreaker for alpha with identical terms + if ( $retval == 0 + && $l == $r + && $left->{version}[$m] == $right->{version}[$m] + && ( $lalpha || $ralpha ) ) { + + if ( $lalpha && !$ralpha ) { + $retval = -1; + } + elsif ( $ralpha && !$lalpha) { + $retval = +1; + } + } + + # possible match except for trailing 0's + if ( $retval == 0 && $l != $r ) { + if ( $l < $r ) { + while ( $i <= $r && $retval == 0 ) { + if ( $right->{version}[$i] != 0 ) { + $retval = -1; # not a match after all + } + $i++; + } + } + else { + while ( $i <= $l && $retval == 0 ) { + if ( $left->{version}[$i] != 0 ) { + $retval = +1; # not a match after all + } + $i++; + } + } + } + + return $retval; +} + +sub vbool { + my ($self) = @_; + return vcmp($self,$self->new("0"),1); +} + +sub vnoop { + require Carp; + Carp::croak("operation not supported with version object"); +} + +sub is_alpha { + my ($self) = @_; + return (exists $self->{alpha}); +} + +sub qv { + my $value = shift; + my $class = 'version'; + if (@_) { + $class = ref($value) || $value; + $value = shift; + } + + $value = _un_vstring($value); + $value = 'v'.$value unless $value =~ /(^v|\d+\.\d+\.\d)/; + my $version = $class->new($value); + return $version; +} + +*declare = \&qv; + +sub is_qv { + my ($self) = @_; + return (exists $self->{qv}); +} + + +sub _verify { + my ($self) = @_; + if ( ref($self) + && eval { exists $self->{version} } + && ref($self->{version}) eq 'ARRAY' + ) { + return 1; + } + else { + return 0; + } +} + +sub _is_non_alphanumeric { + my $s = shift; + $s = new charstar $s; + while ($s) { + return 0 if isSPACE($s); # early out + return 1 unless (isALPHA($s) || isDIGIT($s) || $s =~ /[.-]/); + $s++; + } + return 0; +} + +sub _un_vstring { + my $value = shift; + # may be a v-string + if ( length($value) >= 3 && $value !~ /[._]/ + && _is_non_alphanumeric($value)) { + my $tvalue; + if ( $] ge 5.008_001 ) { + $tvalue = _find_magic_vstring($value); + $value = $tvalue if length $tvalue; + } + elsif ( $] ge 5.006_000 ) { + $tvalue = sprintf("v%vd",$value); + if ( $tvalue =~ /^v\d+(\.\d+){2,}$/ ) { + # must be a v-string + $value = $tvalue; + } + } + } + return $value; +} + +sub _find_magic_vstring { + my $value = shift; + my $tvalue = ''; + require B; + my $sv = B::svref_2object(\$value); + my $magic = ref($sv) eq 'B::PVMG' ? $sv->MAGIC : undef; + while ( $magic ) { + if ( $magic->TYPE eq 'V' ) { + $tvalue = $magic->PTR; + $tvalue =~ s/^v?(.+)$/v$1/; + last; + } + else { + $magic = $magic->MOREMAGIC; + } + } + return $tvalue; +} + +sub _VERSION { + my ($obj, $req) = @_; + my $class = ref($obj) || $obj; + + no strict 'refs'; + if ( exists $INC{"$class.pm"} and not %{"$class\::"} and $] >= 5.008) { + # file but no package + require Carp; + Carp::croak( "$class defines neither package nor VERSION" + ."--version check failed"); + } + + my $version = eval "\$$class\::VERSION"; + if ( defined $version ) { + local $^W if $] <= 5.008; + $version = version::vpp->new($version); + } + + if ( defined $req ) { + unless ( defined $version ) { + require Carp; + my $msg = $] < 5.006 + ? "$class version $req required--this is only version " + : "$class does not define \$$class\::VERSION" + ."--version check failed"; + + if ( $ENV{VERSION_DEBUG} ) { + Carp::confess($msg); + } + else { + Carp::croak($msg); + } + } + + $req = version::vpp->new($req); + + if ( $req > $version ) { + require Carp; + if ( $req->is_qv ) { + Carp::croak( + sprintf ("%s version %s required--". + "this is only version %s", $class, + $req->normal, $version->normal) + ); + } + else { + Carp::croak( + sprintf ("%s version %s required--". + "this is only version %s", $class, + $req->stringify, $version->stringify) + ); + } + } + } + + return defined $version ? $version->stringify : undef; +} + +1; #this line is important and will help the module return a true value diff --git a/inc/Module/Metadata.pm b/inc/Module/Metadata.pm new file mode 100644 index 0000000..5d8b5c0 --- /dev/null +++ b/inc/Module/Metadata.pm @@ -0,0 +1,759 @@ +# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- +# vim:ts=8:sw=2:et:sta:sts=2 +package Module::Metadata; + +# stolen from Module::Build::Version and ::Base - this is perl licensed code, +# copyright them. + +# This module provides routines to gather information about +# perl modules (assuming this may be expanded in the distant +# parrot future to look at other types of modules). + +use strict; +use vars qw($VERSION); +$VERSION = '1.000002'; +$VERSION = eval $VERSION; + +use File::Spec; +use version 0.87; +BEGIN { + if ($INC{'Log/Contextual.pm'}) { + Log::Contextual->import('log_info'); + } else { + *log_info = sub (&) { warn $_[0]->() }; + } +} +use File::Find qw(find); + +my $V_NUM_REGEXP = qr{v?[0-9._]+}; # crudely, a v-string or decimal + +my $PKG_REGEXP = qr{ # match a package declaration + ^[\s\{;]* # intro chars on a line + package # the word 'package' + \s+ # whitespace + ([\w:]+) # a package name + \s* # optional whitespace + ($V_NUM_REGEXP)? # optional version number + \s* # optional whitesapce + ; # semicolon line terminator +}x; + +my $VARNAME_REGEXP = qr{ # match fully-qualified VERSION name + ([\$*]) # sigil - $ or * + ( + ( # optional leading package name + (?:::|\')? # possibly starting like just :: (Ì la $::VERSION) + (?:\w+(?:::|\'))* # Foo::Bar:: ... + )? + VERSION + )\b +}x; + +my $VERS_REGEXP = qr{ # match a VERSION definition + (?: + \(\s*$VARNAME_REGEXP\s*\) # with parens + | + $VARNAME_REGEXP # without parens + ) + \s* + =[^=~] # = but not ==, nor =~ +}x; + + +sub new_from_file { + my $class = shift; + my $filename = File::Spec->rel2abs( shift ); + + return undef unless defined( $filename ) && -f $filename; + return $class->_init(undef, $filename, @_); +} + +sub new_from_module { + my $class = shift; + my $module = shift; + my %props = @_; + + $props{inc} ||= \@INC; + my $filename = $class->find_module_by_name( $module, $props{inc} ); + return undef unless defined( $filename ) && -f $filename; + return $class->_init($module, $filename, %props); +} + +{ + + my $compare_versions = sub { + my ($v1, $op, $v2) = @_; + $v1 = version->new($v1) + unless eval { $v1->isa('version') }; + + my $eval_str = "\$v1 $op \$v2"; + my $result = eval $eval_str; + log_info { "error comparing versions: '$eval_str' $@" } if $@; + + return $result; + }; + + my $normalize_version = sub { + my ($version) = @_; + if ( $version =~ /[=<>!,]/ ) { # logic, not just version + # take as is without modification + } + elsif ( ref $version eq 'version' ) { # version objects + $version = $version->is_qv ? $version->normal : $version->stringify; + } + elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots + # normalize string tuples without "v": "1.2.3" -> "v1.2.3" + $version = "v$version"; + } + else { + # leave alone + } + return $version; + }; + + # separate out some of the conflict resolution logic + + my $resolve_module_versions = sub { + my $packages = shift; + + my( $file, $version ); + my $err = ''; + foreach my $p ( @$packages ) { + if ( defined( $p->{version} ) ) { + if ( defined( $version ) ) { + if ( $compare_versions->( $version, '!=', $p->{version} ) ) { + $err .= " $p->{file} ($p->{version})\n"; + } else { + # same version declared multiple times, ignore + } + } else { + $file = $p->{file}; + $version = $p->{version}; + } + } + $file ||= $p->{file} if defined( $p->{file} ); + } + + if ( $err ) { + $err = " $file ($version)\n" . $err; + } + + my %result = ( + file => $file, + version => $version, + err => $err + ); + + return \%result; + }; + + sub package_versions_from_directory { + my ( $class, $dir, $files ) = @_; + + my @files; + + if ( $files ) { + @files = @$files; + } else { + find( { + wanted => sub { + push @files, $_ if -f $_ && /\.pm$/; + }, + no_chdir => 1, + }, $dir ); + } + + # First, we enumerate all packages & versions, + # separating into primary & alternative candidates + my( %prime, %alt ); + foreach my $file (@files) { + my $mapped_filename = File::Spec->abs2rel( $file, $dir ); + my @path = split( /\//, $mapped_filename ); + (my $prime_package = join( '::', @path )) =~ s/\.pm$//; + + my $pm_info = $class->new_from_file( $file ); + + foreach my $package ( $pm_info->packages_inside ) { + next if $package eq 'main'; # main can appear numerous times, ignore + next if $package eq 'DB'; # special debugging package, ignore + next if grep /^_/, split( /::/, $package ); # private package, ignore + + my $version = $pm_info->version( $package ); + + if ( $package eq $prime_package ) { + if ( exists( $prime{$package} ) ) { + # M::B::ModuleInfo will handle this conflict + die "Unexpected conflict in '$package'; multiple versions found.\n"; + } else { + $prime{$package}{file} = $mapped_filename; + $prime{$package}{version} = $version if defined( $version ); + } + } else { + push( @{$alt{$package}}, { + file => $mapped_filename, + version => $version, + } ); + } + } + } + + # Then we iterate over all the packages found above, identifying conflicts + # and selecting the "best" candidate for recording the file & version + # for each package. + foreach my $package ( keys( %alt ) ) { + my $result = $resolve_module_versions->( $alt{$package} ); + + if ( exists( $prime{$package} ) ) { # primary package selected + + if ( $result->{err} ) { + # Use the selected primary package, but there are conflicting + # errors among multiple alternative packages that need to be + # reported + log_info { + "Found conflicting versions for package '$package'\n" . + " $prime{$package}{file} ($prime{$package}{version})\n" . + $result->{err} + }; + + } elsif ( defined( $result->{version} ) ) { + # There is a primary package selected, and exactly one + # alternative package + + if ( exists( $prime{$package}{version} ) && + defined( $prime{$package}{version} ) ) { + # Unless the version of the primary package agrees with the + # version of the alternative package, report a conflict + if ( $compare_versions->( + $prime{$package}{version}, '!=', $result->{version} + ) + ) { + + log_info { + "Found conflicting versions for package '$package'\n" . + " $prime{$package}{file} ($prime{$package}{version})\n" . + " $result->{file} ($result->{version})\n" + }; + } + + } else { + # The prime package selected has no version so, we choose to + # use any alternative package that does have a version + $prime{$package}{file} = $result->{file}; + $prime{$package}{version} = $result->{version}; + } + + } else { + # no alt package found with a version, but we have a prime + # package so we use it whether it has a version or not + } + + } else { # No primary package was selected, use the best alternative + + if ( $result->{err} ) { + log_info { + "Found conflicting versions for package '$package'\n" . + $result->{err} + }; + } + + # Despite possible conflicting versions, we choose to record + # something rather than nothing + $prime{$package}{file} = $result->{file}; + $prime{$package}{version} = $result->{version} + if defined( $result->{version} ); + } + } + + # Normalize versions. Can't use exists() here because of bug in YAML::Node. + # XXX "bug in YAML::Node" comment seems irrelvant -- dagolden, 2009-05-18 + for (grep defined $_->{version}, values %prime) { + $_->{version} = $normalize_version->( $_->{version} ); + } + + return \%prime; + } +} + + +sub _init { + my $class = shift; + my $module = shift; + my $filename = shift; + my %props = @_; + + my( %valid_props, @valid_props ); + @valid_props = qw( collect_pod inc ); + @valid_props{@valid_props} = delete( @props{@valid_props} ); + warn "Unknown properties: @{[keys %props]}\n" if scalar( %props ); + + my %data = ( + module => $module, + filename => $filename, + version => undef, + packages => [], + versions => {}, + pod => {}, + pod_headings => [], + collect_pod => 0, + + %valid_props, + ); + + my $self = bless(\%data, $class); + + $self->_parse_file(); + + unless($self->{module} and length($self->{module})) { + my ($v, $d, $f) = File::Spec->splitpath($self->{filename}); + if($f =~ /\.pm$/) { + $f =~ s/\..+$//; + my @candidates = grep /$f$/, @{$self->{packages}}; + $self->{module} = shift(@candidates); # punt + } + else { + if(grep /main/, @{$self->{packages}}) { + $self->{module} = 'main'; + } + else { + $self->{module} = $self->{packages}[0] || ''; + } + } + } + + $self->{version} = $self->{versions}{$self->{module}} + if defined( $self->{module} ); + + return $self; +} + +# class method +sub _do_find_module { + my $class = shift; + my $module = shift || die 'find_module_by_name() requires a package name'; + my $dirs = shift || \@INC; + + my $file = File::Spec->catfile(split( /::/, $module)); + foreach my $dir ( @$dirs ) { + my $testfile = File::Spec->catfile($dir, $file); + return [ File::Spec->rel2abs( $testfile ), $dir ] + if -e $testfile and !-d _; # For stuff like ExtUtils::xsubpp + return [ File::Spec->rel2abs( "$testfile.pm" ), $dir ] + if -e "$testfile.pm"; + } + return; +} + +# class method +sub find_module_by_name { + my $found = shift()->_do_find_module(@_) or return; + return $found->[0]; +} + +# class method +sub find_module_dir_by_name { + my $found = shift()->_do_find_module(@_) or return; + return $found->[1]; +} + + +# given a line of perl code, attempt to parse it if it looks like a +# $VERSION assignment, returning sigil, full name, & package name +sub _parse_version_expression { + my $self = shift; + my $line = shift; + + my( $sig, $var, $pkg ); + if ( $line =~ $VERS_REGEXP ) { + ( $sig, $var, $pkg ) = $2 ? ( $1, $2, $3 ) : ( $4, $5, $6 ); + if ( $pkg ) { + $pkg = ($pkg eq '::') ? 'main' : $pkg; + $pkg =~ s/::$//; + } + } + + return ( $sig, $var, $pkg ); +} + +sub _parse_file { + my $self = shift; + + my $filename = $self->{filename}; + open( my $fh, '<', $filename ) + or die( "Can't open '$filename': $!" ); + + $self->_parse_fh($fh); +} + +sub _parse_fh { + my ($self, $fh) = @_; + + my( $in_pod, $seen_end, $need_vers ) = ( 0, 0, 0 ); + my( @pkgs, %vers, %pod, @pod ); + my $pkg = 'main'; + my $pod_sect = ''; + my $pod_data = ''; + + while (defined( my $line = <$fh> )) { + my $line_num = $.; + + chomp( $line ); + next if $line =~ /^\s*#/; + + $in_pod = ($line =~ /^=(?!cut)/) ? 1 : ($line =~ /^=cut/) ? 0 : $in_pod; + + # Would be nice if we could also check $in_string or something too + last if !$in_pod && $line =~ /^__(?:DATA|END)__$/; + + if ( $in_pod || $line =~ /^=cut/ ) { + + if ( $line =~ /^=head\d\s+(.+)\s*$/ ) { + push( @pod, $1 ); + if ( $self->{collect_pod} && length( $pod_data ) ) { + $pod{$pod_sect} = $pod_data; + $pod_data = ''; + } + $pod_sect = $1; + + + } elsif ( $self->{collect_pod} ) { + $pod_data .= "$line\n"; + + } + + } else { + + $pod_sect = ''; + $pod_data = ''; + + # parse $line to see if it's a $VERSION declaration + my( $vers_sig, $vers_fullname, $vers_pkg ) = + $self->_parse_version_expression( $line ); + + if ( $line =~ $PKG_REGEXP ) { + $pkg = $1; + push( @pkgs, $pkg ) unless grep( $pkg eq $_, @pkgs ); + $vers{$pkg} = (defined $2 ? $2 : undef) unless exists( $vers{$pkg} ); + $need_vers = defined $2 ? 0 : 1; + + # VERSION defined with full package spec, i.e. $Module::VERSION + } elsif ( $vers_fullname && $vers_pkg ) { + push( @pkgs, $vers_pkg ) unless grep( $vers_pkg eq $_, @pkgs ); + $need_vers = 0 if $vers_pkg eq $pkg; + + unless ( defined $vers{$vers_pkg} && length $vers{$vers_pkg} ) { + $vers{$vers_pkg} = + $self->_evaluate_version_line( $vers_sig, $vers_fullname, $line ); + } else { + # Warn unless the user is using the "$VERSION = eval + # $VERSION" idiom (though there are probably other idioms + # that we should watch out for...) + warn <<"EOM" unless $line =~ /=\s*eval/; +Package '$vers_pkg' already declared with version '$vers{$vers_pkg}', +ignoring subsequent declaration on line $line_num. +EOM + } + + # first non-comment line in undeclared package main is VERSION + } elsif ( !exists($vers{main}) && $pkg eq 'main' && $vers_fullname ) { + $need_vers = 0; + my $v = + $self->_evaluate_version_line( $vers_sig, $vers_fullname, $line ); + $vers{$pkg} = $v; + push( @pkgs, 'main' ); + + # first non-comment line in undeclared package defines package main + } elsif ( !exists($vers{main}) && $pkg eq 'main' && $line =~ /\w+/ ) { + $need_vers = 1; + $vers{main} = ''; + push( @pkgs, 'main' ); + + # only keep if this is the first $VERSION seen + } elsif ( $vers_fullname && $need_vers ) { + $need_vers = 0; + my $v = + $self->_evaluate_version_line( $vers_sig, $vers_fullname, $line ); + + + unless ( defined $vers{$pkg} && length $vers{$pkg} ) { + $vers{$pkg} = $v; + } else { + warn <<"EOM"; +Package '$pkg' already declared with version '$vers{$pkg}' +ignoring new version '$v' on line $line_num. +EOM + } + + } + + } + + } + + if ( $self->{collect_pod} && length($pod_data) ) { + $pod{$pod_sect} = $pod_data; + } + + $self->{versions} = \%vers; + $self->{packages} = \@pkgs; + $self->{pod} = \%pod; + $self->{pod_headings} = \@pod; +} + +{ +my $pn = 0; +sub _evaluate_version_line { + my $self = shift; + my( $sigil, $var, $line ) = @_; + + # Some of this code came from the ExtUtils:: hierarchy. + + # We compile into $vsub because 'use version' would cause + # compiletime/runtime issues with local() + my $vsub; + $pn++; # everybody gets their own package + my $eval = qq{BEGIN { q# Hide from _packages_inside() + #; package Module::Metadata::_version::p$pn; + use version; + no strict; + + local $sigil$var; + \$$var=undef; + \$vsub = sub { + $line; + \$$var + }; + }}; + + local $^W; + # Try to get the $VERSION + eval $eval; + # some modules say $VERSION = $Foo::Bar::VERSION, but Foo::Bar isn't + # installed, so we need to hunt in ./lib for it + if ( $@ =~ /Can't locate/ && -d 'lib' ) { + local @INC = ('lib',@INC); + eval $eval; + } + warn "Error evaling version line '$eval' in $self->{filename}: $@\n" + if $@; + (ref($vsub) eq 'CODE') or + die "failed to build version sub for $self->{filename}"; + my $result = eval { $vsub->() }; + die "Could not get version from $self->{filename} by executing:\n$eval\n\nThe fatal error was: $@\n" + if $@; + + # Upgrade it into a version object + my $version = eval { _dwim_version($result) }; + + die "Version '$result' from $self->{filename} does not appear to be valid:\n$eval\n\nThe fatal error was: $@\n" + unless defined $version; # "0" is OK! + + return $version; +} +} + +# Try to DWIM when things fail the lax version test in obvious ways +{ + my @version_prep = ( + # Best case, it just works + sub { return shift }, + + # If we still don't have a version, try stripping any + # trailing junk that is prohibited by lax rules + sub { + my $v = shift; + $v =~ s{([0-9])[a-z-].*$}{$1}i; # 1.23-alpha or 1.23b + return $v; + }, + + # Activestate apparently creates custom versions like '1.23_45_01', which + # cause version.pm to think it's an invalid alpha. So check for that + # and strip them + sub { + my $v = shift; + my $num_dots = () = $v =~ m{(\.)}g; + my $num_unders = () = $v =~ m{(_)}g; + my $leading_v = substr($v,0,1) eq 'v'; + if ( ! $leading_v && $num_dots < 2 && $num_unders > 1 ) { + $v =~ s{_}{}g; + $num_unders = () = $v =~ m{(_)}g; + } + return $v; + }, + + # Worst case, try numifying it like we would have before version objects + sub { + my $v = shift; + no warnings 'numeric'; + return 0 + $v; + }, + + ); + + sub _dwim_version { + my ($result) = shift; + + return $result if ref($result) eq 'version'; + + my ($version, $error); + for my $f (@version_prep) { + $result = $f->($result); + $version = eval { version->new($result) }; + $error ||= $@ if $@; # capture first failure + last if defined $version; + } + + die $error unless defined $version; + + return $version; + } +} + +############################################################ + +# accessors +sub name { $_[0]->{module} } + +sub filename { $_[0]->{filename} } +sub packages_inside { @{$_[0]->{packages}} } +sub pod_inside { @{$_[0]->{pod_headings}} } +sub contains_pod { $#{$_[0]->{pod_headings}} } + +sub version { + my $self = shift; + my $mod = shift || $self->{module}; + my $vers; + if ( defined( $mod ) && length( $mod ) && + exists( $self->{versions}{$mod} ) ) { + return $self->{versions}{$mod}; + } else { + return undef; + } +} + +sub pod { + my $self = shift; + my $sect = shift; + if ( defined( $sect ) && length( $sect ) && + exists( $self->{pod}{$sect} ) ) { + return $self->{pod}{$sect}; + } else { + return undef; + } +} + +1; + +=head1 NAME + +Module::Metadata - Gather package and POD information from perl module files + +=head1 DESCRIPTION + +=over 4 + +=item new_from_file($filename, collect_pod => 1) + +Construct a C<ModuleInfo> object given the path to a file. Takes an optional +argument C<collect_pod> which is a boolean that determines whether +POD data is collected and stored for reference. POD data is not +collected by default. POD headings are always collected. + +=item new_from_module($module, collect_pod => 1, inc => \@dirs) + +Construct a C<ModuleInfo> object given a module or package name. In addition +to accepting the C<collect_pod> argument as described above, this +method accepts a C<inc> argument which is a reference to an array of +of directories to search for the module. If none are given, the +default is @INC. + +=item name() + +Returns the name of the package represented by this module. If there +are more than one packages, it makes a best guess based on the +filename. If it's a script (i.e. not a *.pm) the package name is +'main'. + +=item version($package) + +Returns the version as defined by the $VERSION variable for the +package as returned by the C<name> method if no arguments are +given. If given the name of a package it will attempt to return the +version of that package if it is specified in the file. + +=item filename() + +Returns the absolute path to the file. + +=item packages_inside() + +Returns a list of packages. + +=item pod_inside() + +Returns a list of POD sections. + +=item contains_pod() + +Returns true if there is any POD in the file. + +=item pod($section) + +Returns the POD data in the given section. + +=item find_module_by_name($module, \@dirs) + +Returns the path to a module given the module or package name. A list +of directories can be passed in as an optional parameter, otherwise +@INC is searched. + +Can be called as either an object or a class method. + +=item find_module_dir_by_name($module, \@dirs) + +Returns the entry in C<@dirs> (or C<@INC> by default) that contains +the module C<$module>. A list of directories can be passed in as an +optional parameter, otherwise @INC is searched. + +Can be called as either an object or a class method. + +=item package_versions_from_directory($dir, \@files?) + +Scans C<$dir> for .pm files (unless C<@files> is given, in which case looks +for those files in C<$dir> - and reads each file for packages and versions, +returning a hashref of the form: + + { + 'Package::Name' => { + version => '0.123', + file => 'Package/Name.pm' + }, + 'OtherPackage::Name' => ... + } + +=item log_info (internal) + +Used internally to perform logging; imported from Log::Contextual if +Log::Contextual has already been loaded, otherwise simply calls warn. + +=back + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org>, Randy W. Sims <RandyS@ThePierianSpring.org> + +Released as Module::Metadata by Matt S Trout (mst) <mst@shadowcat.co.uk> with +assistance from David Golden (xdg) <dagolden@cpan.org> + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + +=head1 SEE ALSO + +perl(1), L<Module::Build::ModuleInfo>(3) + +=cut + diff --git a/inc/Perl/OSType.pm b/inc/Perl/OSType.pm new file mode 100644 index 0000000..6c2cf12 --- /dev/null +++ b/inc/Perl/OSType.pm @@ -0,0 +1,174 @@ +# +# This file is part of Perl-OSType +# +# This software is copyright (c) 2010 by David Golden. +# +# This is free software; you can redistribute it and/or modify it under +# the same terms as the Perl 5 programming language system itself. +# +use strict; +use warnings; +package Perl::OSType; +BEGIN { + $Perl::OSType::VERSION = '1.002'; +} +# ABSTRACT: Map Perl operating system names to generic types + +require Exporter; +our @ISA = qw(Exporter); + +our %EXPORT_TAGS = ( + all => [ qw( os_type is_os_type ) ] +); + +our @EXPORT_OK = @{ $EXPORT_TAGS{all} }; + +# originally taken from Module::Build by Ken Williams et al. +my %OSTYPES = qw( + aix Unix + bsdos Unix + beos Unix + dgux Unix + dragonfly Unix + dynixptx Unix + freebsd Unix + linux Unix + haiku Unix + hpux Unix + iphoneos Unix + irix Unix + darwin Unix + machten Unix + midnightbsd Unix + mirbsd Unix + next Unix + openbsd Unix + netbsd Unix + dec_osf Unix + nto Unix + svr4 Unix + svr5 Unix + sco_sv Unix + unicos Unix + unicosmk Unix + solaris Unix + sunos Unix + cygwin Unix + os2 Unix + interix Unix + gnu Unix + gnukfreebsd Unix + nto Unix + qnx Unix + + dos Windows + MSWin32 Windows + + os390 EBCDIC + os400 EBCDIC + posix-bc EBCDIC + vmesa EBCDIC + + MacOS MacOS + VMS VMS + VOS VOS + riscos RiscOS + amigaos Amiga + mpeix MPEiX +); + +sub os_type { + my ($os) = @_; + $os = $^O unless defined $os; + return $OSTYPES{ $os } || q{}; +} + +sub is_os_type { + my ($type, $os) = @_; + return unless $type; + $os = $^O unless defined $os; + return os_type($os) eq $type; +} + +1; + + +=pod + +=head1 NAME + +Perl::OSType - Map Perl operating system names to generic types + +=head1 VERSION + +version 1.002 + +=head1 SYNOPSIS + + use Perl::OSType ':all'; + + $current_type = os_type(); + $other_type = os_type('dragonfly'); # gives 'Unix' + +=head1 DESCRIPTION + +Modules that provide OS-specific behaviors often need to know if +the current operating system matches a more generic type of +operating systems. For example, 'linux' is a type of 'Unix' operating system +and so is 'freebsd'. + +This module provides a mapping between an operating system name as given by +C<$^O> and a more generic type. The initial version is based on the OS type +mappings provided in L<Module::Build> and L<ExtUtils::CBuilder>. (Thus, +Microsoft operating systems are given the type 'Windows' rather than 'Win32'.) + +=head1 USAGE + +No functions are exported by default. The export tag ":all" will export +all functions listed below. + +=head2 os_type() + + $os_type = os_type(); + $os_type = os_type('MSWin32'); + +Returns a single, generic OS type for a given operating system name. With no +arguments, returns the OS type for the current value of C<$^O>. If the +operating system is not recognized, the function will return the empty string. + +=head2 is_os_type() + + $is_windows = is_os_type('Windows'); + $is_unix = is_os_type('Unix', 'dragonfly'); + +Given an OS type and OS name, returns true or false if the OS name is of the +given type. As with C<os_type>, it will use the current operating system as a +default if no OS name is provided. + +=head1 SEE ALSO + +=over 4 + +=item * + +L<Devel::CheckOS> + +=back + +=head1 AUTHOR + +David Golden <dagolden@cpan.org> + +=head1 COPYRIGHT AND LICENSE + +This software is copyright (c) 2010 by David Golden. + +This is free software; you can redistribute it and/or modify it under +the same terms as the Perl 5 programming language system itself. + +=cut + + +__END__ + + diff --git a/inc/bootstrap.pl b/inc/bootstrap.pl new file mode 100644 index 0000000..2011fc7 --- /dev/null +++ b/inc/bootstrap.pl @@ -0,0 +1,47 @@ +# bootstrap.pl +# bootstrap modules in inc/ for use during configuration with +# either Build.PL or Makefile.PL + +my @exit_warn; + +END { + warn "\nThese additional prerequisites must be installed:\n requires:\n" + if @exit_warn; + while( my $h = shift @exit_warn ) { + my ($mod, $min) = @$h; + warn " ! $mod (we need version $min)\n"; + } +} + +BEGIN { + if ( ! eval "use Perl::OSType 1 (); 1" ) { + print "*** BOOTSTRAPPING Perl::OSType ***\n"; + push @exit_warn, [ 'Perl::OSType', '1.00' ]; + delete $INC{'Perl/OSType.pm'}; + local @INC = @INC; + push @INC, 'inc'; + eval "require Perl::OSType; 1" + or die "BOOSTRAP FAIL: $@"; + } + if ( ! eval "use version 0.87 (); 1" ) { + print "*** BOOTSTRAPPING version ***\n"; + push @exit_warn, [ 'version', '0.87' ]; + delete $INC{'version.pm'}; + local @INC = @INC; + push @INC, 'inc'; + eval "require MBVersion; 1" + or die "BOOSTRAP FAIL: $@"; + } + if ( ! eval "use Module::Metadata 1.000002 (); 1" ) { + print "*** BOOTSTRAPPING Module::Metadata ***\n"; + push @exit_warn, [ 'Module::Metadata', '1.000002' ]; + delete $INC{'Module/Metadata.pm'}; + local @INC = @INC; + push @INC, 'inc'; + eval "require Module::Metadata; 1" + or die "BOOSTRAP FAIL: $@"; + } +} + +1; + diff --git a/lib/Module/Build.pm b/lib/Module/Build.pm new file mode 100644 index 0000000..5bb815a --- /dev/null +++ b/lib/Module/Build.pm @@ -0,0 +1,1118 @@ +package Module::Build; + +use if $] >= 5.019, 'deprecate'; + +# This module doesn't do much of anything itself, it inherits from the +# modules that do the real work. The only real thing it has to do is +# figure out which OS-specific module to pull in. Many of the +# OS-specific modules don't do anything either - most of the work is +# done in Module::Build::Base. + +use 5.006; +use strict; +use warnings; +use File::Spec (); +use File::Path (); +use File::Basename (); +use Perl::OSType (); + +use Module::Build::Base; + +our @ISA = qw(Module::Build::Base); +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; + +# Inserts the given module into the @ISA hierarchy between +# Module::Build and its immediate parent +sub _interpose_module { + my ($self, $mod) = @_; + eval "use $mod"; + die $@ if $@; + + no strict 'refs'; + my $top_class = $mod; + while (@{"${top_class}::ISA"}) { + last if ${"${top_class}::ISA"}[0] eq $ISA[0]; + $top_class = ${"${top_class}::ISA"}[0]; + } + + @{"${top_class}::ISA"} = @ISA; + @ISA = ($mod); +} + +if (grep {-e File::Spec->catfile($_, qw(Module Build Platform), $^O) . '.pm'} @INC) { + __PACKAGE__->_interpose_module("Module::Build::Platform::$^O"); + +} elsif ( my $ostype = os_type() ) { + __PACKAGE__->_interpose_module("Module::Build::Platform::$ostype"); + +} else { + warn "Unknown OS type '$^O' - using default settings\n"; +} + +sub os_type { return Perl::OSType::os_type() } + +sub is_vmsish { return Perl::OSType::is_os_type('VMS') } +sub is_windowsish { return Perl::OSType::is_os_type('Windows') } +sub is_unixish { return Perl::OSType::is_os_type('Unix') } + +1; + +__END__ + +=for :stopwords +bindoc binhtml destdir distcheck distclean distdir distmeta distsign disttest +fakeinstall html installdirs installsitebin installsitescript installvendorbin +installvendorscript libdoc libhtml pardist ppd ppmdist realclean skipcheck +testall testcover testdb testpod testpodcoverage versioninstall + +=head1 NAME + +Module::Build - Build and install Perl modules + +=head1 SYNOPSIS + +Standard process for building & installing modules: + + perl Build.PL + ./Build + ./Build test + ./Build install + +Or, if you're on a platform (like DOS or Windows) that doesn't require +the "./" notation, you can do this: + + perl Build.PL + Build + Build test + Build install + + +=head1 DESCRIPTION + +C<Module::Build> is a system for building, testing, and installing +Perl modules. It is meant to be an alternative to +C<ExtUtils::MakeMaker>. Developers may alter the behavior of the +module through subclassing in a much more straightforward way than +with C<MakeMaker>. It also does not require a C<make> on your system +- most of the C<Module::Build> code is pure-perl and written in a very +cross-platform way. + +See L<"MOTIVATIONS"> for more comparisons between C<ExtUtils::MakeMaker> +and C<Module::Build>. + +To install C<Module::Build>, and any other module that uses +C<Module::Build> for its installation process, do the following: + + perl Build.PL # 'Build.PL' script creates the 'Build' script + ./Build # Need ./ to ensure we're using this "Build" script + ./Build test # and not another one that happens to be in the PATH + ./Build install + +This illustrates initial configuration and the running of three +'actions'. In this case the actions run are 'build' (the default +action), 'test', and 'install'. Other actions defined so far include: + + build manifest + clean manifest_skip + code manpages + config_data pardist + diff ppd + dist ppmdist + distcheck prereq_data + distclean prereq_report + distdir pure_install + distinstall realclean + distmeta retest + distsign skipcheck + disttest test + docs testall + fakeinstall testcover + help testdb + html testpod + install testpodcoverage + installdeps versioninstall + +You can run the 'help' action for a complete list of actions. + + +=head1 GUIDE TO DOCUMENTATION + +The documentation for C<Module::Build> is broken up into sections: + +=over + +=item General Usage (L<Module::Build>) + +This is the document you are currently reading. It describes basic +usage and background information. Its main purpose is to assist the +user who wants to learn how to invoke and control C<Module::Build> +scripts at the command line. + +=item Authoring Reference (L<Module::Build::Authoring>) + +This document describes the structure and organization of +C<Module::Build>, and the relevant concepts needed by authors who are +writing F<Build.PL> scripts for a distribution or controlling +C<Module::Build> processes programmatically. + +=item API Reference (L<Module::Build::API>) + +This is a reference to the C<Module::Build> API. + +=item Cookbook (L<Module::Build::Cookbook>) + +This document demonstrates how to accomplish many common tasks. It +covers general command line usage and authoring of F<Build.PL> +scripts. Includes working examples. + +=back + + +=head1 ACTIONS + +There are some general principles at work here. First, each task when +building a module is called an "action". These actions are listed +above; they correspond to the building, testing, installing, +packaging, etc., tasks. + +Second, arguments are processed in a very systematic way. Arguments +are always key=value pairs. They may be specified at C<perl Build.PL> +time (i.e. C<perl Build.PL destdir=/my/secret/place>), in which case +their values last for the lifetime of the C<Build> script. They may +also be specified when executing a particular action (i.e. +C<Build test verbose=1>), in which case their values last only for the +lifetime of that command. Per-action command line parameters take +precedence over parameters specified at C<perl Build.PL> time. + +The build process also relies heavily on the C<Config.pm> module. +If the user wishes to override any of the +values in C<Config.pm>, she may specify them like so: + + perl Build.PL --config cc=gcc --config ld=gcc + +The following build actions are provided by default. + +=over 4 + +=item build + +[version 0.01] + +If you run the C<Build> script without any arguments, it runs the +C<build> action, which in turn runs the C<code> and C<docs> actions. + +This is analogous to the C<MakeMaker> I<make all> target. + +=item clean + +[version 0.01] + +This action will clean up any files that the build process may have +created, including the C<blib/> directory (but not including the +C<_build/> directory and the C<Build> script itself). + +=item code + +[version 0.20] + +This action builds your code base. + +By default it just creates a C<blib/> directory and copies any C<.pm> +and C<.pod> files from your C<lib/> directory into the C<blib/> +directory. It also compiles any C<.xs> files from C<lib/> and places +them in C<blib/>. Of course, you need a working C compiler (probably +the same one that built perl itself) for the compilation to work +properly. + +The C<code> action also runs any C<.PL> files in your F<lib/> +directory. Typically these create other files, named the same but +without the C<.PL> ending. For example, a file F<lib/Foo/Bar.pm.PL> +could create the file F<lib/Foo/Bar.pm>. The C<.PL> files are +processed first, so any C<.pm> files (or other kinds that we deal +with) will get copied correctly. + +=item config_data + +[version 0.26] + +... + +=item diff + +[version 0.14] + +This action will compare the files about to be installed with their +installed counterparts. For .pm and .pod files, a diff will be shown +(this currently requires a 'diff' program to be in your PATH). For +other files like compiled binary files, we simply report whether they +differ. + +A C<flags> parameter may be passed to the action, which will be passed +to the 'diff' program. Consult your 'diff' documentation for the +parameters it will accept - a good one is C<-u>: + + ./Build diff flags=-u + +=item dist + +[version 0.02] + +This action is helpful for module authors who want to package up their +module for source distribution through a medium like CPAN. It will create a +tarball of the files listed in F<MANIFEST> and compress the tarball using +GZIP compression. + +By default, this action will use the C<Archive::Tar> module. However, you can +force it to use binary "tar" and "gzip" executables by supplying an explicit +C<tar> (and optional C<gzip>) parameter: + + ./Build dist --tar C:\path\to\tar.exe --gzip C:\path\to\zip.exe + +=item distcheck + +[version 0.05] + +Reports which files are in the build directory but not in the +F<MANIFEST> file, and vice versa. (See L<manifest> for details.) + +=item distclean + +[version 0.05] + +Performs the 'realclean' action and then the 'distcheck' action. + +=item distdir + +[version 0.05] + +Creates a "distribution directory" named C<$dist_name-$dist_version> +(if that directory already exists, it will be removed first), then +copies all the files listed in the F<MANIFEST> file to that directory. +This directory is what the distribution tarball is created from. + +=item distinstall + +[version 0.37] + +Performs the 'distdir' action, then switches into that directory and runs a +C<perl Build.PL>, followed by the 'build' and 'install' actions in that +directory. Use PERL_MB_OPT or F<.modulebuildrc> to set options that should be +applied during subprocesses + +=item distmeta + +[version 0.21] + +Creates the F<META.yml> file that describes the distribution. + +F<META.yml> is a file containing various bits of I<metadata> about the +distribution. The metadata includes the distribution name, version, +abstract, prerequisites, license, and various other data about the +distribution. This file is created as F<META.yml> in a simplified YAML format. + +F<META.yml> file must also be listed in F<MANIFEST> - if it's not, a +warning will be issued. + +The current version of the F<META.yml> specification can be found +on CPAN as L<CPAN::Meta::Spec>. + +=item distsign + +[version 0.16] + +Uses C<Module::Signature> to create a SIGNATURE file for your +distribution, and adds the SIGNATURE file to the distribution's +MANIFEST. + +=item disttest + +[version 0.05] + +Performs the 'distdir' action, then switches into that directory and runs a +C<perl Build.PL>, followed by the 'build' and 'test' actions in that directory. +Use PERL_MB_OPT or F<.modulebuildrc> to set options that should be applied +during subprocesses + + +=item docs + +[version 0.20] + +This will generate documentation (e.g. Unix man pages and HTML +documents) for any installable items under B<blib/> that +contain POD. If there are no C<bindoc> or C<libdoc> installation +targets defined (as will be the case on systems that don't support +Unix manpages) no action is taken for manpages. If there are no +C<binhtml> or C<libhtml> installation targets defined no action is +taken for HTML documents. + +=item fakeinstall + +[version 0.02] + +This is just like the C<install> action, but it won't actually do +anything, it will just report what it I<would> have done if you had +actually run the C<install> action. + +=item help + +[version 0.03] + +This action will simply print out a message that is meant to help you +use the build process. It will show you a list of available build +actions too. + +With an optional argument specifying an action name (e.g. C<Build help +test>), the 'help' action will show you any POD documentation it can +find for that action. + +=item html + +[version 0.26] + +This will generate HTML documentation for any binary or library files +under B<blib/> that contain POD. The HTML documentation will only be +installed if the install paths can be determined from values in +C<Config.pm>. You can also supply or override install paths on the +command line by specifying C<install_path> values for the C<binhtml> +and/or C<libhtml> installation targets. + +With an optional C<html_links> argument set to a false value, you can +skip the search for other documentation to link to, because that can +waste a lot of time if there aren't any links to generate anyway: + + ./Build html --html_links 0 + +=item install + +[version 0.01] + +This action will use C<ExtUtils::Install> to install the files from +C<blib/> into the system. See L<"INSTALL PATHS"> +for details about how Module::Build determines where to install +things, and how to influence this process. + +If you want the installation process to look around in C<@INC> for +other versions of the stuff you're installing and try to delete it, +you can use the C<uninst> parameter, which tells C<ExtUtils::Install> to +do so: + + ./Build install uninst=1 + +This can be a good idea, as it helps prevent multiple versions of a +module from being present on your system, which can be a confusing +situation indeed. + +=item installdeps + +[version 0.36] + +This action will use the C<cpan_client> parameter as a command to install +missing prerequisites. You will be prompted whether to install +optional dependencies. + +The C<cpan_client> option defaults to 'cpan' but can be set as an option or in +F<.modulebuildrc>. It must be a shell command that takes a list of modules to +install as arguments (e.g. 'cpanp -i' for CPANPLUS). If the program part is a +relative path (e.g. 'cpan' or 'cpanp'), it will be located relative to the perl +program that executed Build.PL. + + /opt/perl/5.8.9/bin/perl Build.PL + ./Build installdeps --cpan_client 'cpanp -i' + # installs to 5.8.9 + +=item manifest + +[version 0.05] + +This is an action intended for use by module authors, not people +installing modules. It will bring the F<MANIFEST> up to date with the +files currently present in the distribution. You may use a +F<MANIFEST.SKIP> file to exclude certain files or directories from +inclusion in the F<MANIFEST>. F<MANIFEST.SKIP> should contain a bunch +of regular expressions, one per line. If a file in the distribution +directory matches any of the regular expressions, it won't be included +in the F<MANIFEST>. + +The following is a reasonable F<MANIFEST.SKIP> starting point, you can +add your own stuff to it: + + ^_build + ^Build$ + ^blib + ~$ + \.bak$ + ^MANIFEST\.SKIP$ + CVS + +See the L<distcheck> and L<skipcheck> actions if you want to find out +what the C<manifest> action would do, without actually doing anything. + +=item manifest_skip + +[version 0.3608] + +This is an action intended for use by module authors, not people +installing modules. It will generate a boilerplate MANIFEST.SKIP file +if one does not already exist. + +=item manpages + +[version 0.28] + +This will generate man pages for any binary or library files under +B<blib/> that contain POD. The man pages will only be installed if the +install paths can be determined from values in C<Config.pm>. You can +also supply or override install paths by specifying there values on +the command line with the C<bindoc> and C<libdoc> installation +targets. + +=item pardist + +[version 0.2806] + +Generates a PAR binary distribution for use with L<PAR> or L<PAR::Dist>. + +It requires that the PAR::Dist module (version 0.17 and up) is +installed on your system. + +=item ppd + +[version 0.20] + +Build a PPD file for your distribution. + +This action takes an optional argument C<codebase> which is used in +the generated PPD file to specify the (usually relative) URL of the +distribution. By default, this value is the distribution name without +any path information. + +Example: + + ./Build ppd --codebase "MSWin32-x86-multi-thread/Module-Build-0.21.tar.gz" + +=item ppmdist + +[version 0.23] + +Generates a PPM binary distribution and a PPD description file. This +action also invokes the C<ppd> action, so it can accept the same +C<codebase> argument described under that action. + +This uses the same mechanism as the C<dist> action to tar & zip its +output, so you can supply C<tar> and/or C<gzip> parameters to affect +the result. + +=item prereq_data + +[version 0.32] + +This action prints out a Perl data structure of all prerequisites and the versions +required. The output can be loaded again using C<eval()>. This can be useful for +external tools that wish to query a Build script for prerequisites. + +=item prereq_report + +[version 0.28] + +This action prints out a list of all prerequisites, the versions required, and +the versions actually installed. This can be useful for reviewing the +configuration of your system prior to a build, or when compiling data to send +for a bug report. + +=item pure_install + +[version 0.28] + +This action is identical to the C<install> action. In the future, +though, when C<install> starts writing to the file +F<$(INSTALLARCHLIB)/perllocal.pod>, C<pure_install> won't, and that +will be the only difference between them. + +=item realclean + +[version 0.01] + +This action is just like the C<clean> action, but also removes the +C<_build> directory and the C<Build> script. If you run the +C<realclean> action, you are essentially starting over, so you will +have to re-create the C<Build> script again. + +=item retest + +[version 0.2806] + +This is just like the C<test> action, but doesn't actually build the +distribution first, and doesn't add F<blib/> to the load path, and +therefore will test against a I<previously> installed version of the +distribution. This can be used to verify that a certain installed +distribution still works, or to see whether newer versions of a +distribution still pass the old regression tests, and so on. + +=item skipcheck + +[version 0.05] + +Reports which files are skipped due to the entries in the +F<MANIFEST.SKIP> file (See L<manifest> for details) + +=item test + +[version 0.01] + +This will use C<Test::Harness> or C<TAP::Harness> to run any regression +tests and report their results. Tests can be defined in the standard +places: a file called C<test.pl> in the top-level directory, or several +files ending with C<.t> in a C<t/> directory. + +If you want tests to be 'verbose', i.e. show details of test execution +rather than just summary information, pass the argument C<verbose=1>. + +If you want to run tests under the perl debugger, pass the argument +C<debugger=1>. + +If you want to have Module::Build find test files with different file +name extensions, pass the C<test_file_exts> argument with an array +of extensions, such as C<[qw( .t .s .z )]>. + +If you want test to be run by C<TAP::Harness>, rather than C<Test::Harness>, +pass the argument C<tap_harness_args> as an array reference of arguments to +pass to the TAP::Harness constructor. + +In addition, if a file called C<visual.pl> exists in the top-level +directory, this file will be executed as a Perl script and its output +will be shown to the user. This is a good place to put speed tests or +other tests that don't use the C<Test::Harness> format for output. + +To override the choice of tests to run, you may pass a C<test_files> +argument whose value is a whitespace-separated list of test scripts to +run. This is especially useful in development, when you only want to +run a single test to see whether you've squashed a certain bug yet: + + ./Build test --test_files t/something_failing.t + +You may also pass several C<test_files> arguments separately: + + ./Build test --test_files t/one.t --test_files t/two.t + +or use a C<glob()>-style pattern: + + ./Build test --test_files 't/01-*.t' + +=item testall + +[version 0.2807] + +[Note: the 'testall' action and the code snippets below are currently +in alpha stage, see +L<"http://www.nntp.perl.org/group/perl.module.build/2007/03/msg584.html"> ] + +Runs the C<test> action plus each of the C<test$type> actions defined by +the keys of the C<test_types> parameter. + +Currently, you need to define the ACTION_test$type method yourself and +enumerate them in the test_types parameter. + + my $mb = Module::Build->subclass( + code => q( + sub ACTION_testspecial { shift->generic_test(type => 'special'); } + sub ACTION_testauthor { shift->generic_test(type => 'author'); } + ) + )->new( + ... + test_types => { + special => '.st', + author => ['.at', '.pt' ], + }, + ... + +=item testcover + +[version 0.26] + +Runs the C<test> action using C<Devel::Cover>, generating a +code-coverage report showing which parts of the code were actually +exercised during the tests. + +To pass options to C<Devel::Cover>, set the C<$DEVEL_COVER_OPTIONS> +environment variable: + + DEVEL_COVER_OPTIONS=-ignore,Build ./Build testcover + +=item testdb + +[version 0.05] + +This is a synonym for the 'test' action with the C<debugger=1> +argument. + +=item testpod + +[version 0.25] + +This checks all the files described in the C<docs> action and +produces C<Test::Harness>-style output. If you are a module author, +this is useful to run before creating a new release. + +=item testpodcoverage + +[version 0.28] + +This checks the pod coverage of the distribution and +produces C<Test::Harness>-style output. If you are a module author, +this is useful to run before creating a new release. + +=item versioninstall + +[version 0.16] + +** Note: since C<only.pm> is so new, and since we just recently added +support for it here too, this feature is to be considered +experimental. ** + +If you have the C<only.pm> module installed on your system, you can +use this action to install a module into the version-specific library +trees. This means that you can have several versions of the same +module installed and C<use> a specific one like this: + + use only MyModule => 0.55; + +To override the default installation libraries in C<only::config>, +specify the C<versionlib> parameter when you run the C<Build.PL> script: + + perl Build.PL --versionlib /my/version/place/ + +To override which version the module is installed as, specify the +C<version> parameter when you run the C<Build.PL> script: + + perl Build.PL --version 0.50 + +See the C<only.pm> documentation for more information on +version-specific installs. + +=back + + +=head1 OPTIONS + +=head2 Command Line Options + +The following options can be used during any invocation of C<Build.PL> +or the Build script, during any action. For information on other +options specific to an action, see the documentation for the +respective action. + +NOTE: There is some preliminary support for options to use the more +familiar long option style. Most options can be preceded with the +C<--> long option prefix, and the underscores changed to dashes +(e.g. C<--use-rcfile>). Additionally, the argument to boolean options is +optional, and boolean options can be negated by prefixing them with +C<no> or C<no-> (e.g. C<--noverbose> or C<--no-verbose>). + +=over 4 + +=item quiet + +Suppress informative messages on output. + +=item verbose + +Display extra information about the Build on output. C<verbose> will +turn off C<quiet> + +=item cpan_client + +Sets the C<cpan_client> command for use with the C<installdeps> action. +See C<installdeps> for more details. + +=item use_rcfile + +Load the F<~/.modulebuildrc> option file. This option can be set to +false to prevent the custom resource file from being loaded. + +=item allow_mb_mismatch + +Suppresses the check upon startup that the version of Module::Build +we're now running under is the same version that was initially invoked +when building the distribution (i.e. when the C<Build.PL> script was +first run). As of 0.3601, a mismatch results in a warning instead of +a fatal error, so this option effectively just suppresses the warning. + +=item debug + +Prints Module::Build debugging information to STDOUT, such as a trace of +executed build actions. + +=back + +=head2 Default Options File (F<.modulebuildrc>) + +[version 0.28] + +When Module::Build starts up, it will look first for a file, +F<$ENV{HOME}/.modulebuildrc>. If it's not found there, it will look +in the F<.modulebuildrc> file in the directories referred to by +the environment variables C<HOMEDRIVE> + C<HOMEDIR>, C<USERPROFILE>, +C<APPDATA>, C<WINDIR>, C<SYS$LOGIN>. If the file exists, the options +specified there will be used as defaults, as if they were typed on the +command line. The defaults can be overridden by specifying new values +on the command line. + +The action name must come at the beginning of the line, followed by any +amount of whitespace and then the options. Options are given the same +as they would be on the command line. They can be separated by any +amount of whitespace, including newlines, as long there is whitespace at +the beginning of each continued line. Anything following a hash mark (C<#>) +is considered a comment, and is stripped before parsing. If more than +one line begins with the same action name, those lines are merged into +one set of options. + +Besides the regular actions, there are two special pseudo-actions: the +key C<*> (asterisk) denotes any global options that should be applied +to all actions, and the key 'Build_PL' specifies options to be applied +when you invoke C<perl Build.PL>. + + * verbose=1 # global options + diff flags=-u + install --install_base /home/ken + --install_path html=/home/ken/docs/html + installdeps --cpan_client 'cpanp -i' + +If you wish to locate your resource file in a different location, you +can set the environment variable C<MODULEBUILDRC> to the complete +absolute path of the file containing your options. + +=head2 Environment variables + +=over + +=item MODULEBUILDRC + +[version 0.28] + +Specifies an alternate location for a default options file as described above. + +=item PERL_MB_OPT + +[version 0.36] + +Command line options that are applied to Build.PL or any Build action. The +string is split as the shell would (e.g. whitespace) and the result is +prepended to any actual command-line arguments. + +=back + +=head1 INSTALL PATHS + +[version 0.19] + +When you invoke Module::Build's C<build> action, it needs to figure +out where to install things. The nutshell version of how this works +is that default installation locations are determined from +F<Config.pm>, and they may be overridden by using the C<install_path> +parameter. An C<install_base> parameter lets you specify an +alternative installation root like F</home/foo>, and a C<destdir> lets +you specify a temporary installation directory like F</tmp/install> in +case you want to create bundled-up installable packages. + +Natively, Module::Build provides default installation locations for +the following types of installable items: + +=over 4 + +=item lib + +Usually pure-Perl module files ending in F<.pm>. + +=item arch + +"Architecture-dependent" module files, usually produced by compiling +XS, L<Inline>, or similar code. + +=item script + +Programs written in pure Perl. In order to improve reuse, try to make +these as small as possible - put the code into modules whenever +possible. + +=item bin + +"Architecture-dependent" executable programs, i.e. compiled C code or +something. Pretty rare to see this in a perl distribution, but it +happens. + +=item bindoc + +Documentation for the stuff in C<script> and C<bin>. Usually +generated from the POD in those files. Under Unix, these are manual +pages belonging to the 'man1' category. + +=item libdoc + +Documentation for the stuff in C<lib> and C<arch>. This is usually +generated from the POD in F<.pm> files. Under Unix, these are manual +pages belonging to the 'man3' category. + +=item binhtml + +This is the same as C<bindoc> above, but applies to HTML documents. + +=item libhtml + +This is the same as C<libdoc> above, but applies to HTML documents. + +=back + +Four other parameters let you control various aspects of how +installation paths are determined: + +=over 4 + +=item installdirs + +The default destinations for these installable things come from +entries in your system's C<Config.pm>. You can select from three +different sets of default locations by setting the C<installdirs> +parameter as follows: + + 'installdirs' set to: + core site vendor + + uses the following defaults from Config.pm: + + lib => installprivlib installsitelib installvendorlib + arch => installarchlib installsitearch installvendorarch + script => installscript installsitescript installvendorscript + bin => installbin installsitebin installvendorbin + bindoc => installman1dir installsiteman1dir installvendorman1dir + libdoc => installman3dir installsiteman3dir installvendorman3dir + binhtml => installhtml1dir installsitehtml1dir installvendorhtml1dir [*] + libhtml => installhtml3dir installsitehtml3dir installvendorhtml3dir [*] + + * Under some OS (eg. MSWin32) the destination for HTML documents is + determined by the C<Config.pm> entry C<installhtmldir>. + +The default value of C<installdirs> is "site". If you're creating +vendor distributions of module packages, you may want to do something +like this: + + perl Build.PL --installdirs vendor + +or + + ./Build install --installdirs vendor + +If you're installing an updated version of a module that was included +with perl itself (i.e. a "core module"), then you may set +C<installdirs> to "core" to overwrite the module in its present +location. + +(Note that the 'script' line is different from C<MakeMaker> - +unfortunately there's no such thing as "installsitescript" or +"installvendorscript" entry in C<Config.pm>, so we use the +"installsitebin" and "installvendorbin" entries to at least get the +general location right. In the future, if C<Config.pm> adds some more +appropriate entries, we'll start using those.) + +=item install_path + +Once the defaults have been set, you can override them. + +On the command line, that would look like this: + + perl Build.PL --install_path lib=/foo/lib --install_path arch=/foo/lib/arch + +or this: + + ./Build install --install_path lib=/foo/lib --install_path arch=/foo/lib/arch + +=item install_base + +You can also set the whole bunch of installation paths by supplying the +C<install_base> parameter to point to a directory on your system. For +instance, if you set C<install_base> to "/home/ken" on a Linux +system, you'll install as follows: + + lib => /home/ken/lib/perl5 + arch => /home/ken/lib/perl5/i386-linux + script => /home/ken/bin + bin => /home/ken/bin + bindoc => /home/ken/man/man1 + libdoc => /home/ken/man/man3 + binhtml => /home/ken/html + libhtml => /home/ken/html + +Note that this is I<different> from how C<MakeMaker>'s C<PREFIX> +parameter works. C<install_base> just gives you a default layout under the +directory you specify, which may have little to do with the +C<installdirs=site> layout. + +The exact layout under the directory you specify may vary by system - +we try to do the "sensible" thing on each platform. + +=item destdir + +If you want to install everything into a temporary directory first +(for instance, if you want to create a directory tree that a package +manager like C<rpm> or C<dpkg> could create a package from), you can +use the C<destdir> parameter: + + perl Build.PL --destdir /tmp/foo + +or + + ./Build install --destdir /tmp/foo + +This will effectively install to "/tmp/foo/$sitelib", +"/tmp/foo/$sitearch", and the like, except that it will use +C<File::Spec> to make the pathnames work correctly on whatever +platform you're installing on. + +=item prefix + +Provided for compatibility with C<ExtUtils::MakeMaker>'s PREFIX argument. +C<prefix> should be used when you want Module::Build to install your +modules, documentation, and scripts in the same place as +C<ExtUtils::MakeMaker>'s PREFIX mechanism. + +The following are equivalent. + + perl Build.PL --prefix /tmp/foo + perl Makefile.PL PREFIX=/tmp/foo + +Because of the complex nature of the prefixification logic, the +behavior of PREFIX in C<MakeMaker> has changed subtly over time. +Module::Build's --prefix logic is equivalent to the PREFIX logic found +in C<ExtUtils::MakeMaker> 6.30. + +The maintainers of C<MakeMaker> do understand the troubles with the +PREFIX mechanism, and added INSTALL_BASE support in version 6.31 of +C<MakeMaker>, which was released in 2006. + +If you don't need to retain compatibility with old versions (pre-6.31) of C<ExtUtils::MakeMaker> or +are starting a fresh Perl installation we recommend you use +C<install_base> instead (and C<INSTALL_BASE> in C<ExtUtils::MakeMaker>). +See L<Module::Build::Cookbook/Installing in the same location as +ExtUtils::MakeMaker> for further information. + + +=back + + +=head1 MOTIVATIONS + +There are several reasons I wanted to start over, and not just fix +what I didn't like about C<MakeMaker>: + +=over 4 + +=item * + +I don't like the core idea of C<MakeMaker>, namely that C<make> should be +involved in the build process. Here are my reasons: + +=over 4 + +=item + + +When a person is installing a Perl module, what can you assume about +their environment? Can you assume they have C<make>? No, but you can +assume they have some version of Perl. + +=item + + +When a person is writing a Perl module for intended distribution, can +you assume that they know how to build a Makefile, so they can +customize their build process? No, but you can assume they know Perl, +and could customize that way. + +=back + +For years, these things have been a barrier to people getting the +build/install process to do what they want. + +=item * + +There are several architectural decisions in C<MakeMaker> that make it +very difficult to customize its behavior. For instance, when using +C<MakeMaker> you do C<use ExtUtils::MakeMaker>, but the object created in +C<WriteMakefile()> is actually blessed into a package name that's +created on the fly, so you can't simply subclass +C<ExtUtils::MakeMaker>. There is a workaround C<MY> package that lets +you override certain C<MakeMaker> methods, but only certain explicitly +preselected (by C<MakeMaker>) methods can be overridden. Also, the method +of customization is very crude: you have to modify a string containing +the Makefile text for the particular target. Since these strings +aren't documented, and I<can't> be documented (they take on different +values depending on the platform, version of perl, version of +C<MakeMaker>, etc.), you have no guarantee that your modifications will +work on someone else's machine or after an upgrade of C<MakeMaker> or +perl. + +=item * + +It is risky to make major changes to C<MakeMaker>, since it does so many +things, is so important, and generally works. C<Module::Build> is an +entirely separate package so that I can work on it all I want, without +worrying about backward compatibility with C<MakeMaker>. + +=item * + +Finally, Perl is said to be a language for system administration. +Could it really be the case that Perl isn't up to the task of building +and installing software? Even if that software is a bunch of +C<.pm> files that just need to be copied from one place to +another? My sense was that we could design a system to accomplish +this in a flexible, extensible, and friendly manner. Or die trying. + +=back + + +=head1 TO DO + +The current method of relying on time stamps to determine whether a +derived file is out of date isn't likely to scale well, since it +requires tracing all dependencies backward, it runs into problems on +NFS, and it's just generally flimsy. It would be better to use an MD5 +signature or the like, if available. See C<cons> for an example. + + - append to perllocal.pod + - add a 'plugin' functionality + + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +Development questions, bug reports, and patches should be sent to the +Module-Build mailing list at <module-build@perl.org>. + +Bug reports are also welcome at +<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Build>. + +The latest development version is available from the Git +repository at <https://github.com/Perl-Toolchain-Gang/Module-Build> + + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + + +=head1 SEE ALSO + +perl(1), L<Module::Build::Cookbook>, L<Module::Build::Authoring>, +L<Module::Build::API>, L<ExtUtils::MakeMaker> + +F<META.yml> Specification: +L<CPAN::Meta::Spec> + +L<http://www.dsmit.com/cons/> + +L<http://search.cpan.org/dist/PerlBuildSystem/> + +=cut diff --git a/lib/Module/Build/API.pod b/lib/Module/Build/API.pod new file mode 100644 index 0000000..1a2697e --- /dev/null +++ b/lib/Module/Build/API.pod @@ -0,0 +1,2124 @@ +=head1 NAME + +Module::Build::API - API Reference for Module Authors + +=for :stopwords apache bsd distdir distsign gpl installdirs lgpl mit mozilla packlists + +=head1 DESCRIPTION + +I list here some of the most important methods in C<Module::Build>. +Normally you won't need to deal with these methods unless you want to +subclass C<Module::Build>. But since one of the reasons I created +this module in the first place was so that subclassing is possible +(and easy), I will certainly write more docs as the interface +stabilizes. + + +=head2 CONSTRUCTORS + +=over 4 + +=item current() + +[version 0.20] + +This method returns a reasonable facsimile of the currently-executing +C<Module::Build> object representing the current build. You can use +this object to query its L</notes()> method, inquire about installed +modules, and so on. This is a great way to share information between +different parts of your build process. For instance, you can ask +the user a question during C<perl Build.PL>, then use their answer +during a regression test: + + # In Build.PL: + my $color = $build->prompt("What is your favorite color?"); + $build->notes(color => $color); + + # In t/colortest.t: + use Module::Build; + my $build = Module::Build->current; + my $color = $build->notes('color'); + ... + +The way the C<current()> method is currently implemented, there may be +slight differences between the C<$build> object in Build.PL and the +one in C<t/colortest.t>. It is our goal to minimize these differences +in future releases of Module::Build, so please report any anomalies +you find. + +One important caveat: in its current implementation, C<current()> will +B<NOT> work correctly if you have changed out of the directory that +C<Module::Build> was invoked from. + +=item new() + +[version 0.03] + +Creates a new Module::Build object. Arguments to the new() method are +listed below. Most arguments are optional, but you must provide +either the L</module_name> argument, or L</dist_name> and one of +L</dist_version> or L</dist_version_from>. In other words, you must +provide enough information to determine both a distribution name and +version. + + +=over 4 + +=item add_to_cleanup + +[version 0.19] + +An array reference of files to be cleaned up when the C<clean> action +is performed. See also the L<add_to_cleanup()|/"add_to_cleanup(@files)"> +method. + +=item allow_pureperl + +[version 0.4005] + +A bool indicating the module is still functional without its xs parts. +When an XS module is build with --pureperl_only, it will otherwise fail. + +=item auto_configure_requires + +[version 0.34] + +This parameter determines whether Module::Build will add itself +automatically to configure_requires (and build_requires) if Module::Build +is not already there. The required version will be the last 'major' release, +as defined by the decimal version truncated to two decimal places (e.g. 0.34, +instead of 0.3402). The default value is true. + +=item auto_features + +[version 0.26] + +This parameter supports the setting of features (see +L</feature($name)>) automatically based on a set of prerequisites. For +instance, for a module that could optionally use either MySQL or +PostgreSQL databases, you might use C<auto_features> like this: + + my $build = Module::Build->new + ( + ...other stuff here... + auto_features => { + pg_support => { + description => "Interface with Postgres databases", + requires => { 'DBD::Pg' => 23.3, + 'DateTime::Format::Pg' => 0 }, + }, + mysql_support => { + description => "Interface with MySQL databases", + requires => { 'DBD::mysql' => 17.9, + 'DateTime::Format::MySQL' => 0 }, + }, + } + ); + +For each feature named, the required prerequisites will be checked, and +if there are no failures, the feature will be enabled (set to C<1>). +Otherwise the failures will be displayed to the user and the feature +will be disabled (set to C<0>). + +See the documentation for L</requires> for the details of how +requirements can be specified. + +=item autosplit + +[version 0.04] + +An optional C<autosplit> argument specifies a file which should be run +through the L<AutoSplit::autosplit()|AutoSplit/autosplit> function. +If multiple files should be split, the argument may be given as an +array of the files to split. + +In general I don't consider autosplitting a great idea, because it's +not always clear that autosplitting achieves its intended performance +benefits. It may even harm performance in environments like mod_perl, +where as much as possible of a module's code should be loaded during +startup. + +=item build_class + +[version 0.28] + +The Module::Build class or subclass to use in the build script. +Defaults to "Module::Build" or the class name passed to or created by +a call to L</subclass()>. This property is useful if you're +writing a custom Module::Build subclass and have a bootstrapping +problem--that is, your subclass requires modules that may not be +installed when C<perl Build.PL> is executed, but you've listed in +L</build_requires> so that they should be available when C<./Build> is +executed. + +=item build_requires + +[version 0.07] + +Modules listed in this section are necessary to build and install the +given module, but are not necessary for regular usage of it. This is +actually an important distinction - it allows for tighter control over +the body of installed modules, and facilitates correct dependency +checking on binary/packaged distributions of the module. + +See the documentation for L<Module::Build::Authoring/"PREREQUISITES"> +for the details of how requirements can be specified. + +=item configure_requires + +[version 0.30] + +Modules listed in this section must be installed I<before> configuring +this distribution (i.e. before running the F<Build.PL> script). +This might be a specific minimum version of C<Module::Build> or any +other module the F<Build.PL> needs in order to do its stuff. Clients +like C<CPAN.pm> or C<CPANPLUS> will be expected to pick +C<configure_requires> out of the F<META.yml> file and install these +items before running the C<Build.PL>. + +Module::Build may automatically add itself to configure_requires. +See L</auto_configure_requires> for details. + +See the documentation for L<Module::Build::Authoring/"PREREQUISITES"> +for the details of how requirements can be specified. + +=item test_requires + +[version 0.4004] + +Modules listed in this section must be installed before testing the distribution. + +See the documentation for L<Module::Build::Authoring/"PREREQUISITES"> +for the details of how requirements can be specified. + +=item create_packlist + +[version 0.28] + +If true, this parameter tells Module::Build to create a F<.packlist> +file during the C<install> action, just like C<ExtUtils::MakeMaker> does. +The file is created in a subdirectory of the C<arch> installation +location. It is used by some other tools (CPAN, CPANPLUS, etc.) for +determining what files are part of an install. + +The default value is true. This parameter was introduced in +Module::Build version 0.2609; previously no packlists were ever +created by Module::Build. + +=item c_source + +[version 0.04] + +An optional C<c_source> argument specifies a directory which contains +C source files that the rest of the build may depend on. Any C<.c> +files in the directory will be compiled to object files. The +directory will be added to the search path during the compilation and +linking phases of any C or XS files. + +[version 0.3604] + +A list of directories can be supplied using an anonymous array +reference of strings. + +=item conflicts + +[version 0.07] + +Modules listed in this section conflict in some serious way with the +given module. C<Module::Build> (or some higher-level tool) will +refuse to install the given module if the given module/version is also +installed. + +See the documentation for L<Module::Build::Authoring/"PREREQUISITES"> +for the details of how requirements can be specified. + +=item create_license + +[version 0.31] + +This parameter tells Module::Build to automatically create a +F<LICENSE> file at the top level of your distribution, containing the +full text of the author's chosen license. This requires +C<Software::License> on the author's machine, and further requires +that the C<license> parameter specifies a license that it knows about. + +=item create_makefile_pl + +[version 0.19] + +This parameter lets you use C<Module::Build::Compat> during the +C<distdir> (or C<dist>) action to automatically create a Makefile.PL +for compatibility with C<ExtUtils::MakeMaker>. The parameter's value +should be one of the styles named in the L<Module::Build::Compat> +documentation. + +=item create_readme + +[version 0.22] + +This parameter tells Module::Build to automatically create a F<README> +file at the top level of your distribution. Currently it will simply +use C<Pod::Text> (or C<Pod::Readme> if it's installed) on the file +indicated by C<dist_version_from> and put the result in the F<README> +file. This is by no means the only recommended style for writing a +F<README>, but it seems to be one common one used on the CPAN. + +If you generate a F<README> in this way, it's probably a good idea to +create a separate F<INSTALL> file if that information isn't in the +generated F<README>. + +=item dist_abstract + +[version 0.20] + +This should be a short description of the distribution. This is used when +generating metadata for F<META.yml> and PPD files. If it is not given +then C<Module::Build> looks in the POD of the module from which it gets +the distribution's version. If it finds a POD section marked "=head1 +NAME", then it looks for the first line matching C<\s+-\s+(.+)>, +and uses the captured text as the abstract. + +=item dist_author + +[version 0.20] + +This should be something like "John Doe <jdoe@example.com>", or if +there are multiple authors, an anonymous array of strings may be +specified. This is used when generating metadata for F<META.yml> and +PPD files. If this is not specified, then C<Module::Build> looks at +the module from which it gets the distribution's version. If it finds +a POD section marked "=head1 AUTHOR", then it uses the contents of +this section. + +=item dist_name + +[version 0.11] + +Specifies the name for this distribution. Most authors won't need to +set this directly, they can use C<module_name> to set C<dist_name> to +a reasonable default. However, some agglomerative distributions like +C<libwww-perl> or C<bioperl> have names that don't correspond directly +to a module name, so C<dist_name> can be set independently. + +=item dist_suffix + +[version 0.37] + +Specifies an optional suffix to include after the version number +in the distribution directory (and tarball) name. The only suffix +currently recognized by PAUSE is 'TRIAL', which indicates that the +distribution should not be indexed. For example: + + Foo-Bar-1.23-TRIAL.tar.gz + +This will automatically do the "right thing" depending on C<dist_version> and +C<release_status>. When C<dist_version> does not have an underscore and +C<release_status> is not 'stable', then C<dist_suffix> will default to 'TRIAL'. +Otherwise it will default to the empty string, disabling the suffix. + +In general, authors should only set this if they B<must> override the default +behavior for some particular purpose. + +=item dist_version + +[version 0.11] + +Specifies a version number for the distribution. See L</module_name> +or L</dist_version_from> for ways to have this set automatically from a +C<$VERSION> variable in a module. One way or another, a version +number needs to be set. + +=item dist_version_from + +[version 0.11] + +Specifies a file to look for the distribution version in. Most +authors won't need to set this directly, they can use L</module_name> +to set it to a reasonable default. + +The version is extracted from the specified file according to the same +rules as L<ExtUtils::MakeMaker> and C<CPAN.pm>. It involves finding +the first line that matches the regular expression + + /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ + +eval()-ing that line, then checking the value of the C<$VERSION> +variable. Quite ugly, really, but all the modules on CPAN depend on +this process, so there's no real opportunity to change to something +better. + +If the target file of L</dist_version_from> contains more than one package +declaration, the version returned will be the one matching the configured +L</module_name>. + +=item dynamic_config + +[version 0.07] + +A boolean flag indicating whether the F<Build.PL> file must be +executed, or whether this module can be built, tested and installed +solely from consulting its metadata file. The main reason to set this +to a true value is that your module performs some dynamic +configuration as part of its build/install process. If the flag is +omitted, the F<META.yml> spec says that installation tools should +treat it as 1 (true), because this is a safer way to behave. + +Currently C<Module::Build> doesn't actually do anything with this flag +- it's up to higher-level tools like C<CPAN.pm> to do something useful +with it. It can potentially bring lots of security, packaging, and +convenience improvements. + +=item extra_compiler_flags + +=item extra_linker_flags + +[version 0.19] + +These parameters can contain array references (or strings, in which +case they will be split into arrays) to pass through to the compiler +and linker phases when compiling/linking C code. For example, to tell +the compiler that your code is C++, you might do: + + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + extra_compiler_flags => ['-x', 'c++'], + ); + +To link your XS code against glib you might write something like: + + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + dynamic_config => 1, + extra_compiler_flags => scalar `glib-config --cflags`, + extra_linker_flags => scalar `glib-config --libs`, + ); + +=item extra_manify_args + +[version 0.4006] + +Any extra arguments to pass to C<< Pod::Man->new() >> when building +man pages. One common choice might be C<< utf8 => 1 >> to get Unicode +support. + +=item get_options + +[version 0.26] + +You can pass arbitrary command line options to F<Build.PL> or +F<Build>, and they will be stored in the Module::Build object and can +be accessed via the L</args()> method. However, sometimes you want +more flexibility out of your argument processing than this allows. In +such cases, use the C<get_options> parameter to pass in a hash +reference of argument specifications, and the list of arguments to +F<Build.PL> or F<Build> will be processed according to those +specifications before they're passed on to C<Module::Build>'s own +argument processing. + +The supported option specification hash keys are: + + +=over 4 + +=item type + +The type of option. The types are those supported by Getopt::Long; consult +its documentation for a complete list. Typical types are C<=s> for strings, +C<+> for additive options, and C<!> for negatable options. If the +type is not specified, it will be considered a boolean, i.e. no +argument is taken and a value of 1 will be assigned when the option is +encountered. + +=item store + +A reference to a scalar in which to store the value passed to the option. +If not specified, the value will be stored under the option name in the +hash returned by the C<args()> method. + +=item default + +A default value for the option. If no default value is specified and no option +is passed, then the option key will not exist in the hash returned by +C<args()>. + +=back + + +You can combine references to your own variables or subroutines with +unreferenced specifications, for which the result will also be stored in the +hash returned by C<args()>. For example: + + my $loud = 0; + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + get_options => { + Loud => { store => \$loud }, + Dbd => { type => '=s' }, + Quantity => { type => '+' }, + } + ); + + print STDERR "HEY, ARE YOU LISTENING??\n" if $loud; + print "We'll use the ", $build->args('Dbd'), " DBI driver\n"; + print "Are you sure you want that many?\n" + if $build->args('Quantity') > 2; + +The arguments for such a specification can be called like so: + + perl Build.PL --Loud --Dbd=DBD::pg --Quantity --Quantity --Quantity + +B<WARNING:> Any option specifications that conflict with Module::Build's own +options (defined by its properties) will throw an exception. Use capitalized +option names to avoid unintended conflicts with future Module::Build options. + +Consult the Getopt::Long documentation for details on its usage. + +=item include_dirs + +[version 0.24] + +Specifies any additional directories in which to search for C header +files. May be given as a string indicating a single directory, or as +a list reference indicating multiple directories. + +=item install_path + +[version 0.19] + +You can set paths for individual installable elements by using the +C<install_path> parameter: + + my $build = Module::Build->new + ( + ...other stuff here... + install_path => { + lib => '/foo/lib', + arch => '/foo/lib/arch', + } + ); + +=item installdirs + +[version 0.19] + +Determines where files are installed within the normal perl hierarchy +as determined by F<Config.pm>. Valid values are: C<core>, C<site>, +C<vendor>. The default is C<site>. See +L<Module::Build/"INSTALL PATHS"> + +=item license + +[version 0.07] + +Specifies the licensing terms of your distribution. + +As of Module::Build version 0.36_14, you may use a L<Software::License> +subclass name (e.g. 'Apache_2_0') instead of one of the keys below. + +The legacy list of valid license values include: + +=over 4 + +=item apache + +The distribution is licensed under the Apache License, Version 2.0 +(L<http://apache.org/licenses/LICENSE-2.0>). + +=item apache_1_1 + +The distribution is licensed under the Apache Software License, Version 1.1 +(L<http://apache.org/licenses/LICENSE-1.1>). + +=item artistic + +The distribution is licensed under the Artistic License, as specified +by the F<Artistic> file in the standard Perl distribution. + +=item artistic_2 + +The distribution is licensed under the Artistic 2.0 License +(L<http://opensource.org/licenses/artistic-license-2.0.php>.) + +=item bsd + +The distribution is licensed under the BSD License +(L<http://www.opensource.org/licenses/bsd-license.php>). + +=item gpl + +The distribution is licensed under the terms of the GNU General +Public License (L<http://www.opensource.org/licenses/gpl-license.php>). + +=item lgpl + +The distribution is licensed under the terms of the GNU Lesser +General Public License +(L<http://www.opensource.org/licenses/lgpl-license.php>). + +=item mit + +The distribution is licensed under the MIT License +(L<http://opensource.org/licenses/mit-license.php>). + +=item mozilla + +The distribution is licensed under the Mozilla Public +License. (L<http://opensource.org/licenses/mozilla1.0.php> or +L<http://opensource.org/licenses/mozilla1.1.php>) + +=item open_source + +The distribution is licensed under some other Open Source +Initiative-approved license listed at +L<http://www.opensource.org/licenses/>. + +=item perl + +The distribution may be copied and redistributed under the same terms +as Perl itself (this is by far the most common licensing option for +modules on CPAN). This is a dual license, in which the user may +choose between either the GPL or the Artistic license. + +=item restrictive + +The distribution may not be redistributed without special permission +from the author and/or copyright holder. + +=item unrestricted + +The distribution is licensed under a license that is B<not> approved +by www.opensource.org but that allows distribution without +restrictions. + +=back + +Note that you must still include the terms of your license in your +code and documentation - this field only sets the information that is included +in distribution metadata to let automated tools figure out your +licensing restrictions. Humans still need something to read. If you +choose to provide this field, you should make sure that you keep it in +sync with your written documentation if you ever change your licensing +terms. + +You may also use a license type of C<unknown> if you don't wish to +specify your terms in the metadata. + +Also see the C<create_license> parameter. + +=item meta_add + +[version 0.28] + +A hash of key/value pairs that should be added to the F<META.yml> file +during the C<distmeta> action. Any existing entries with the same +names will be overridden. + +See the L</"MODULE METADATA"> section for details. + +=item meta_merge + +[version 0.28] + +A hash of key/value pairs that should be merged into the F<META.yml> +file during the C<distmeta> action. Any existing entries with the +same names will be overridden. + +The only difference between C<meta_add> and C<meta_merge> is their +behavior on hash-valued and array-valued entries: C<meta_add> will +completely blow away the existing hash or array value, but +C<meta_merge> will merge the supplied data into the existing hash or +array value. + +See the L</"MODULE METADATA"> section for details. + +=item module_name + +[version 0.03] + +The C<module_name> is a shortcut for setting default values of +C<dist_name> and C<dist_version_from>, reflecting the fact that the +majority of CPAN distributions are centered around one "main" module. +For instance, if you set C<module_name> to C<Foo::Bar>, then +C<dist_name> will default to C<Foo-Bar> and C<dist_version_from> will +default to C<lib/Foo/Bar.pm>. C<dist_version_from> will in turn be +used to set C<dist_version>. + +Setting C<module_name> won't override a C<dist_*> parameter you +specify explicitly. + +=item needs_compiler + +[version 0.36] + +The C<needs_compiler> parameter indicates whether a compiler is required to +build the distribution. The default is false, unless XS files are found or +the C<c_source> parameter is set, in which case it is true. If true, +L<ExtUtils::CBuilder> is automatically added to C<build_requires> if needed. + +For a distribution where a compiler is I<optional>, e.g. a dual XS/pure-Perl +distribution, C<needs_compiler> should explicitly be set to a false value. + +=item PL_files + +[version 0.06] + +An optional parameter specifying a set of C<.PL> files in your +distribution. These will be run as Perl scripts prior to processing +the rest of the files in your distribution with the name of the file +they're generating as an argument. They are usually used as templates +for creating other files dynamically, so that a file like +C<lib/Foo/Bar.pm.PL> might create the file C<lib/Foo/Bar.pm>. + +The files are specified with the C<.PL> files as hash keys, and the +file(s) they generate as hash values, like so: + + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + ... + PL_files => { 'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm' }, + ); + +Note that the path specifications are I<always> given in Unix-like +format, not in the style of the local system. + +If your C<.PL> scripts don't create any files, or if they create files +with unexpected names, or even if they create multiple files, you can +indicate that so that Module::Build can properly handle these created +files: + + PL_files => { + 'lib/Foo/Bar.pm.PL' => 'lib/Foo/Bar.pm', + 'lib/something.PL' => ['/lib/something', '/lib/else'], + 'lib/funny.PL' => [], + } + +Here's an example of a simple PL file. + + my $output_file = shift; + open my $fh, ">", $output_file or die "Can't open $output_file: $!"; + + print $fh <<'END'; + #!/usr/bin/perl + + print "Hello, world!\n"; + END + +PL files are not installed by default, so its safe to put them in +F<lib/> and F<bin/>. + + +=item pm_files + +[version 0.19] + +An optional parameter specifying the set of C<.pm> files in this +distribution, specified as a hash reference whose keys are the files' +locations in the distributions, and whose values are their logical +locations based on their package name, i.e. where they would be found +in a "normal" Module::Build-style distribution. This parameter is +mainly intended to support alternative layouts of files. + +For instance, if you have an old-style C<MakeMaker> distribution for a +module called C<Foo::Bar> and a F<Bar.pm> file at the top level of the +distribution, you could specify your layout in your C<Build.PL> like +this: + + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + ... + pm_files => { 'Bar.pm' => 'lib/Foo/Bar.pm' }, + ); + +Note that the values should include C<lib/>, because this is where +they would be found in a "normal" Module::Build-style distribution. + +Note also that the path specifications are I<always> given in +Unix-like format, not in the style of the local system. + +=item pod_files + +[version 0.19] + +Just like C<pm_files>, but used for specifying the set of C<.pod> +files in your distribution. + +=item recommends + +[version 0.08] + +This is just like the L</requires> argument, except that modules listed +in this section aren't essential, just a good idea. We'll just print +a friendly warning if one of these modules aren't found, but we'll +continue running. + +If a module is recommended but not required, all tests should still +pass if the module isn't installed. This may mean that some tests +may be skipped if recommended dependencies aren't present. + +Automated tools like CPAN.pm should inform the user when recommended +modules aren't installed, and it should offer to install them if it +wants to be helpful. + +See the documentation for L<Module::Build::Authoring/"PREREQUISITES"> +for the details of how requirements can be specified. + +=item recursive_test_files + +[version 0.28] + +Normally, C<Module::Build> does not search subdirectories when looking +for tests to run. When this options is set it will search recursively +in all subdirectories of the standard 't' test directory. + +=item release_status + +[version 0.37] + +The CPAN Meta Spec version 2 adds C<release_status> to allow authors +to specify how a distribution should be indexed. Consistent with the +spec, this parameter can only have one three values: 'stable', +'testing' or 'unstable'. + +Unless explicitly set by the author, C<release_status> will default +to 'stable' unless C<dist_version> contains an underscore, in which +case it will default to 'testing'. + +It is an error to specify a C<release_status> of 'stable' when +C<dist_version> contains an underscore character. + +=item requires + +[version 0.07] + +An optional C<requires> argument specifies any module prerequisites +that the current module depends on. + +One note: currently C<Module::Build> doesn't actually I<require> the +user to have dependencies installed, it just strongly urges. In the +future we may require it. There's also a L</recommends> section for +things that aren't absolutely required. + +Automated tools like CPAN.pm should refuse to install a module if one +of its dependencies isn't satisfied, unless a "force" command is given +by the user. If the tools are helpful, they should also offer to +install the dependencies. + +A synonym for C<requires> is C<prereq>, to help succour people +transitioning from C<ExtUtils::MakeMaker>. The C<requires> term is +preferred, but the C<prereq> term will remain valid in future +distributions. + +See the documentation for L<Module::Build::Authoring/"PREREQUISITES"> +for the details of how requirements can be specified. + +=item script_files + +[version 0.18] + +An optional parameter specifying a set of files that should be +installed as executable Perl scripts when the module is installed. +May be given as an array reference of the files, as a hash reference +whose keys are the files (and whose values will currently be ignored), +as a string giving the name of a directory in which to find scripts, +or as a string giving the name of a single script file. + +The default is to install any scripts found in a F<bin> directory at +the top level of the distribution, minus any keys of L<PL_files>. + +For backward compatibility, you may use the parameter C<scripts> +instead of C<script_files>. Please consider this usage deprecated, +though it will continue to exist for several version releases. + +=item share_dir + +[version 0.36] + +An optional parameter specifying directories of static data files to +be installed as read-only files for use with L<File::ShareDir>. The +C<share_dir> property supports both distribution-level and +module-level share files. + +The simplest use of C<share_dir> is to set it to a directory name or an +arrayref of directory names containing files to be installed in the +distribution-level share directory. + + share_dir => 'share' + +Alternatively, if C<share_dir> is a hashref, it may have C<dist> or +C<module> keys providing full flexibility in defining how share +directories should be installed. + + share_dir => { + dist => [ 'examples', 'more_examples' ], + module => { + Foo::Templates => ['share/html', 'share/text'], + Foo::Config => 'share/config', + } + } + +If C<share_dir> is set, then File::ShareDir will automatically be added +to the C<requires> hash. + +=item sign + +[version 0.16] + +If a true value is specified for this parameter, L<Module::Signature> +will be used (via the 'distsign' action) to create a SIGNATURE file +for your distribution during the 'distdir' action, and to add the +SIGNATURE file to the MANIFEST (therefore, don't add it yourself). + +The default value is false. In the future, the default may change to +true if you have C<Module::Signature> installed on your system. + +=item tap_harness_args + +[version 0.2808_03] + +An optional parameter specifying parameters to be passed to TAP::Harness when +running tests. Must be given as a hash reference of parameters; see the +L<TAP::Harness|TAP::Harness> documentation for details. Note that specifying +this parameter will implicitly set C<use_tap_harness> to a true value. You +must therefore be sure to add TAP::Harness as a requirement for your module in +L</build_requires>. + +=item test_files + +[version 0.23] + +An optional parameter specifying a set of files that should be used as +C<Test::Harness>-style regression tests to be run during the C<test> +action. May be given as an array reference of the files, or as a hash +reference whose keys are the files (and whose values will currently be +ignored). If the argument is given as a single string (not in an +array reference), that string will be treated as a C<glob()> pattern +specifying the files to use. + +The default is to look for a F<test.pl> script in the top-level +directory of the distribution, and any files matching the glob pattern +C<*.t> in the F<t/> subdirectory. If the C<recursive_test_files> +property is true, then the C<t/> directory will be scanned recursively +for C<*.t> files. + +=item use_tap_harness + +[version 0.2808_03] + +An optional parameter indicating whether or not to use TAP::Harness for +testing rather than Test::Harness. Defaults to false. If set to true, you must +therefore be sure to add TAP::Harness as a requirement for your module in +L</build_requires>. Implicitly set to a true value if C<tap_harness_args> is +specified. + +=item xs_files + +[version 0.19] + +Just like C<pm_files>, but used for specifying the set of C<.xs> +files in your distribution. + +=back + + +=item new_from_context(%args) + +[version 0.28] + +When called from a directory containing a F<Build.PL> script (in other words, +the base directory of a distribution), this method will run the F<Build.PL> and +call C<resume()> to return the resulting C<Module::Build> object to the caller. +Any key-value arguments given to C<new_from_context()> are essentially like +command line arguments given to the F<Build.PL> script, so for example you +could pass C<< verbose => 1 >> to this method to turn on verbosity. + +=item resume() + +[version 0.03] + +You'll probably never call this method directly, it's only called from the +auto-generated C<Build> script (and the C<new_from_context> method). The +C<new()> method is only called once, when the user runs C<perl Build.PL>. +Thereafter, when the user runs C<Build test> or another action, the +C<Module::Build> object is created using the C<resume()> method to +re-instantiate with the settings given earlier to C<new()>. + +=item subclass() + +[version 0.06] + +This creates a new C<Module::Build> subclass on the fly, as described +in the L<Module::Build::Authoring/"SUBCLASSING"> section. The caller +must provide either a C<class> or C<code> parameter, or both. The +C<class> parameter indicates the name to use for the new subclass, and +defaults to C<MyModuleBuilder>. The C<code> parameter specifies Perl +code to use as the body of the subclass. + +=item add_property + +[version 0.31] + + package 'My::Build'; + use base 'Module::Build'; + __PACKAGE__->add_property( 'pedantic' ); + __PACKAGE__->add_property( answer => 42 ); + __PACKAGE__->add_property( + 'epoch', + default => sub { time }, + check => sub { + return 1 if /^\d+$/; + shift->property_error( "'$_' is not an epoch time" ); + return 0; + }, + ); + +Adds a property to a Module::Build class. Properties are those attributes of a +Module::Build object which can be passed to the constructor and which have +accessors to get and set them. All of the core properties, such as +C<module_name> and C<license>, are defined using this class method. + +The first argument to C<add_property()> is always the name of the property. +The second argument can be either a default value for the property, or a list +of key/value pairs. The supported keys are: + +=over + +=item C<default> + +The default value. May optionally be specified as a code reference, in which +case the return value from the execution of the code reference will be used. +If you need the default to be a code reference, just use a code reference to +return it, e.g.: + + default => sub { sub { ... } }, + +=item C<check> + +A code reference that checks that a value specified for the property is valid. +During the execution of the code reference, the new value will be included in +the C<$_> variable. If the value is correct, the C<check> code reference +should return true. If the value is not correct, it sends an error message to +C<property_error()> and returns false. + +=back + +When this method is called, a new property will be installed in the +Module::Build class, and an accessor will be built to allow the property to be +get or set on the build object. + + print $build->pedantic, $/; + $build->pedantic(0); + +If the default value is a hash reference, this generates a special-case +accessor method, wherein individual key/value pairs may be set or fetched: + + print "stuff{foo} is: ", $build->stuff( 'foo' ), $/; + $build->stuff( foo => 'bar' ); + print $build->stuff( 'foo' ), $/; # Outputs "bar" + +Of course, you can still set the entire hash reference at once, as well: + + $build->stuff( { foo => 'bar', baz => 'yo' } ); + +In either case, if a C<check> has been specified for the property, it will be +applied to the entire hash. So the check code reference should look something +like: + + check => sub { + return 1 if defined $_ && exists $_->{foo}; + shift->property_error(qq{Property "stuff" needs "foo"}); + return 0; + }, + +=item property_error + +[version 0.31] + +=back + + +=head2 METHODS + +=over 4 + +=item add_build_element($type) + +[version 0.26] + +Adds a new type of entry to the build process. Accepts a single +string specifying its type-name. There must also be a method defined +to process things of that type, e.g. if you add a build element called +C<'foo'>, then you must also define a method called +C<process_foo_files()>. + +See also +L<Module::Build::Cookbook/"Adding new file types to the build process">. + +=item add_to_cleanup(@files) + +[version 0.03] + +You may call C<< $self->add_to_cleanup(@patterns) >> to tell +C<Module::Build> that certain files should be removed when the user +performs the C<Build clean> action. The arguments to the method are +patterns suitable for passing to Perl's C<glob()> function, specified +in either Unix format or the current machine's native format. It's +usually convenient to use Unix format when you hard-code the filenames +(e.g. in F<Build.PL>) and the native format when the names are +programmatically generated (e.g. in a testing script). + +I decided to provide a dynamic method of the C<$build> object, rather +than just use a static list of files named in the F<Build.PL>, because +these static lists can get difficult to manage. I usually prefer to +keep the responsibility for registering temporary files close to the +code that creates them. + +=item args() + +[version 0.26] + + my $args_href = $build->args; + my %args = $build->args; + my $arg_value = $build->args($key); + $build->args($key, $value); + +This method is the preferred interface for retrieving the arguments passed via +command line options to F<Build.PL> or F<Build>, minus the Module-Build +specific options. + +When called in a scalar context with no arguments, this method returns a +reference to the hash storing all of the arguments; in an array context, it +returns the hash itself. When passed a single argument, it returns the value +stored in the args hash for that option key. When called with two arguments, +the second argument is assigned to the args hash under the key passed as the +first argument. + +=item autosplit_file($from, $to) + +[version 0.28] + +Invokes the L<AutoSplit> module on the C<$from> file, sending the +output to the C<lib/auto> directory inside C<$to>. C<$to> is +typically the C<blib/> directory. + +=item base_dir() + +[version 0.14] + +Returns a string containing the root-level directory of this build, +i.e. where the C<Build.PL> script and the C<lib> directory can be +found. This is usually the same as the current working directory, +because the C<Build> script will C<chdir()> into this directory as +soon as it begins execution. + +=item build_requires() + +[version 0.21] + +Returns a hash reference indicating the C<build_requires> +prerequisites that were passed to the C<new()> method. + +=item can_action( $action ) + +Returns a reference to the method that defines C<$action>, or false +otherwise. This is handy for actions defined (or maybe not!) in subclasses. + +[version 0.32_xx] + +=item cbuilder() + +[version 0.2809] + +Returns the internal ExtUtils::CBuilder object that can be used for +compiling & linking C code. If no such object is available (e.g. if +the system has no compiler installed) an exception will be thrown. + +=item check_installed_status($module, $version) + +[version 0.11] + +This method returns a hash reference indicating whether a version +dependency on a certain module is satisfied. The C<$module> argument +is given as a string like C<"Data::Dumper"> or C<"perl">, and the +C<$version> argument can take any of the forms described in L</requires> +above. This allows very fine-grained version checking. + +The returned hash reference has the following structure: + + { + ok => $whether_the_dependency_is_satisfied, + have => $version_already_installed, + need => $version_requested, # Same as incoming $version argument + message => $informative_error_message, + } + +If no version of C<$module> is currently installed, the C<have> value +will be the string C<< "<none>" >>. Otherwise the C<have> value will +simply be the version of the installed module. Note that this means +that if C<$module> is installed but doesn't define a version number, +the C<have> value will be C<undef> - this is why we don't use C<undef> +for the case when C<$module> isn't installed at all. + +This method may be called either as an object method +(C<< $build->check_installed_status($module, $version) >>) +or as a class method +(C<< Module::Build->check_installed_status($module, $version) >>). + +=item check_installed_version($module, $version) + +[version 0.05] + +Like L<check_installed_status()|/"check_installed_status($module, $version)">, +but simply returns true or false depending on whether module +C<$module> satisfies the dependency C<$version>. + +If the check succeeds, the return value is the actual version of +C<$module> installed on the system. This allows you to do the +following: + + my $installed = $build->check_installed_version('DBI', '1.15'); + if ($installed) { + print "Congratulations, version $installed of DBI is installed.\n"; + } else { + die "Sorry, you must install DBI.\n"; + } + +If the check fails, we return false and set C<$@> to an informative +error message. + +If C<$version> is any non-true value (notably zero) and any version of +C<$module> is installed, we return true. In this case, if C<$module> +doesn't define a version, or if its version is zero, we return the +special value "0 but true", which is numerically zero, but logically +true. + +In general you might prefer to use C<check_installed_status> if you +need detailed information, or this method if you just need a yes/no +answer. + +=item compare_versions($v1, $op, $v2) + +[version 0.28] + +Compares two module versions C<$v1> and C<$v2> using the operator +C<$op>, which should be one of Perl's numeric operators like C<!=> or +C<< >= >> or the like. We do at least a halfway-decent job of +handling versions that aren't strictly numeric, like C<0.27_02>, but +exotic stuff will likely cause problems. + +In the future, the guts of this method might be replaced with a call +out to C<version.pm>. + +=item config($key) + +=item config($key, $value) + +=item config() [deprecated] + +[version 0.22] + +With a single argument C<$key>, returns the value associated with that +key in the C<Config.pm> hash, including any changes the author or user +has specified. + +With C<$key> and C<$value> arguments, sets the value for future +callers of C<config($key)>. + +With no arguments, returns a hash reference containing all such +key-value pairs. This usage is deprecated, though, because it's a +resource hog and violates encapsulation. + +=item config_data($name) + +=item config_data($name => $value) + +[version 0.26] + +With a single argument, returns the value of the configuration +variable C<$name>. With two arguments, sets the given configuration +variable to the given value. The value may be any Perl scalar that's +serializable with C<Data::Dumper>. For instance, if you write a +module that can use a MySQL or PostgreSQL back-end, you might create +configuration variables called C<mysql_connect> and +C<postgres_connect>, and set each to an array of connection parameters +for C<< DBI->connect() >>. + +Configuration values set in this way using the Module::Build object +will be available for querying during the build/test process and after +installation via the generated C<...::ConfigData> module, as +C<< ...::ConfigData->config($name) >>. + +The L<feature()|/"feature($name)"> and C<config_data()> methods represent +Module::Build's main support for configuration of installed modules. +See also L<Module::Build::Authoring/"SAVING CONFIGURATION INFORMATION">. + +=item conflicts() + +[version 0.21] + +Returns a hash reference indicating the C<conflicts> prerequisites +that were passed to the C<new()> method. + +=item contains_pod($file) [deprecated] + +[version 0.20] + +[Deprecated] Please see L<Module::Metadata> instead. + +Returns true if the given file appears to contain POD documentation. +Currently this checks whether the file has a line beginning with +'=pod', '=head', or '=item', but the exact semantics may change in the +future. + +=item copy_if_modified(%parameters) + +[version 0.19] + +Takes the file in the C<from> parameter and copies it to the file in +the C<to> parameter, or the directory in the C<to_dir> parameter, if +the file has changed since it was last copied (or if it doesn't exist +in the new location). By default the entire directory structure of +C<from> will be copied into C<to_dir>; an optional C<flatten> +parameter will copy into C<to_dir> without doing so. + +Returns the path to the destination file, or C<undef> if nothing +needed to be copied. + +Any directories that need to be created in order to perform the +copying will be automatically created. + +The destination file is set to read-only. If the source file has the +executable bit set, then the destination file will be made executable. + +=item create_build_script() + +[version 0.05] + +Creates an executable script called C<Build> in the current directory +that will be used to execute further user actions. This script is +roughly analogous (in function, not in form) to the Makefile created +by C<ExtUtils::MakeMaker>. This method also creates some temporary +data in a directory called C<_build/>. Both of these will be removed +when the C<realclean> action is performed. + +Among the files created in C<_build/> is a F<_build/prereqs> file +containing the set of prerequisites for this distribution, as a hash +of hashes. This file may be C<eval()>-ed to obtain the authoritative +set of prerequisites, which might be different from the contents of +F<META.yml> (because F<Build.PL> might have set them dynamically). +But fancy developers take heed: do not put any fancy custom runtime +code in the F<_build/prereqs> file, leave it as a static declaration +containing only strings and numbers. Similarly, do not alter the +structure of the internal C<< $self->{properties}{requires} >> (etc.) +data members, because that's where this data comes from. + +=item current_action() + +[version 0.28] + +Returns the name of the currently-running action, such as "build" or +"test". This action is not necessarily the action that was originally +invoked by the user. For example, if the user invoked the "test" +action, current_action() would initially return "test". However, +action "test" depends on action "code", so current_action() will +return "code" while that dependency is being executed. Once that +action has completed, current_action() will again return "test". + +If you need to know the name of the original action invoked by the +user, see L</invoked_action()> below. + +=item depends_on(@actions) + +[version 0.28] + +Invokes the named action or list of actions in sequence. Using this +method is preferred to calling the action explicitly because it +performs some internal record-keeping, and it ensures that the same +action is not invoked multiple times (note: in future versions of +Module::Build it's conceivable that this run-only-once mechanism will +be changed to something more intelligent). + +Note that the name of this method is something of a misnomer; it +should really be called something like +C<invoke_actions_unless_already_invoked()> or something, but for +better or worse (perhaps better!) we were still thinking in +C<make>-like dependency terms when we created this method. + +See also L<dispatch()|/"dispatch($action, %args)">. The main +distinction between the two is that C<depends_on()> is meant to call +an action from inside another action, whereas C<dispatch()> is meant +to set the very top action in motion. + +=item dir_contains($first_dir, $second_dir) + +[version 0.28] + +Returns true if the first directory logically contains the second +directory. This is just a convenience function because C<File::Spec> +doesn't really provide an easy way to figure this out (but +C<Path::Class> does...). + +=item dispatch($action, %args) + +[version 0.03] + +Invokes the build action C<$action>. Optionally, a list of options +and their values can be passed in. This is equivalent to invoking an +action at the command line, passing in a list of options. + +Custom options that have not been registered must be passed in as a +hash reference in a key named "args": + + $build->dispatch('foo', verbose => 1, args => { my_option => 'value' }); + +This method is intended to be used to programmatically invoke build +actions, e.g. by applications controlling Module::Build-based builds +rather than by subclasses. + +See also L<depends_on()|/"depends_on(@actions)">. The main +distinction between the two is that C<depends_on()> is meant to call +an action from inside another action, whereas C<dispatch()> is meant +to set the very top action in motion. + +=item dist_dir() + +[version 0.28] + +Returns the name of the directory that will be created during the +C<dist> action. The name is derived from the C<dist_name> and +C<dist_version> properties. + +=item dist_name() + +[version 0.21] + +Returns the name of the current distribution, as passed to the +C<new()> method in a C<dist_name> or modified C<module_name> +parameter. + +=item dist_version() + +[version 0.21] + +Returns the version of the current distribution, as determined by the +C<new()> method from a C<dist_version>, C<dist_version_from>, or +C<module_name> parameter. + +=item do_system($cmd, @args) + +[version 0.21] + +This is a fairly simple wrapper around Perl's C<system()> built-in +command. Given a command and an array of optional arguments, this +method will print the command to C<STDOUT>, and then execute it using +Perl's C<system()>. It returns true or false to indicate success or +failure (the opposite of how C<system()> works, but more intuitive). + +Note that if you supply a single argument to C<do_system()>, it +will/may be processed by the system's shell, and any special +characters will do their special things. If you supply multiple +arguments, no shell will get involved and the command will be executed +directly. + +=item extra_compiler_flags() + +=item extra_compiler_flags(@flags) + +[version 0.25] + +Set or retrieve the extra compiler flags. Returns an arrayref of flags. + +=item extra_linker_flags() + +=item extra_linker_flags(@flags) + +[version 0.25] + +Set or retrieve the extra linker flags. Returns an arrayref of flags. + +=item feature($name) + +=item feature($name => $value) + +[version 0.26] + +With a single argument, returns true if the given feature is set. +With two arguments, sets the given feature to the given boolean value. +In this context, a "feature" is any optional functionality of an +installed module. For instance, if you write a module that could +optionally support a MySQL or PostgreSQL backend, you might create +features called C<mysql_support> and C<postgres_support>, and set them +to true/false depending on whether the user has the proper databases +installed and configured. + +Features set in this way using the Module::Build object will be +available for querying during the build/test process and after +installation via the generated C<...::ConfigData> module, as +C<< ...::ConfigData->feature($name) >>. + +The C<feature()> and C<config_data()> methods represent +Module::Build's main support for configuration of installed modules. +See also L<Module::Build::Authoring/"SAVING CONFIGURATION INFORMATION">. + +=item fix_shebang_line(@files) + +[version 0.??] + +Modify any "shebang" line in the specified files to use the path to the +perl executable being used for the current build. Files are modified +in-place. The existing shebang line must have a command that contains +"C<perl>"; arguments to the command do not count. In particular, this +means that the use of C<#!/usr/bin/env perl> will not be changed. + +For an explanation of shebang lines, see +L<http://en.wikipedia.org/wiki/Shebang_%28Unix%29>. + +=item have_c_compiler() + +[version 0.21] + +Returns true if the current system seems to have a working C compiler. +We currently determine this by attempting to compile a simple C source +file and reporting whether the attempt was successful. + +=item install_base_relpaths() + +=item install_base_relpaths($type) + +=item install_base_relpaths($type => $path) + +[version 0.28] + +Set or retrieve the relative paths that are appended to +C<install_base> for any installable element. This is useful if you +want to set the relative install path for custom build elements. + +With no argument, it returns a reference to a hash containing all +elements and their respective values. This hash should not be modified +directly; use the multiple argument below form to change values. + +The single argument form returns the value associated with the +element C<$type>. + +The multiple argument form allows you to set the paths for element types. +C<$value> must be a relative path using Unix-like paths. (A series of +directories separated by slashes, e.g. C<foo/bar>.) The return value is a +localized path based on C<$value>. + +Assigning the value C<undef> to an element causes it to be removed. + +=item install_destination($type) + +[version 0.28] + +Returns the directory in which items of type C<$type> (e.g. C<lib>, +C<arch>, C<bin>, or anything else returned by the L</install_types()> +method) will be installed during the C<install> action. Any settings +for C<install_path>, C<install_base>, and C<prefix> are taken into +account when determining the return value. + +=item install_path() + +=item install_path($type) + +=item install_path($type => $path) + +[version 0.28] + +Set or retrieve paths for specific installable elements. This is +useful when you want to examine any explicit install paths specified +by the user on the command line, or if you want to set the install +path for a specific installable element based on another attribute +like C<install_base()>. + +With no argument, it returns a reference to a hash containing all +elements and their respective values. This hash should not be modified +directly; use the multiple argument below form to change values. + +The single argument form returns the value associated with the +element C<$type>. + +The multiple argument form allows you to set the paths for element types. +The supplied C<$path> should be an absolute path to install elements +of C<$type>. The return value is C<$path>. + +Assigning the value C<undef> to an element causes it to be removed. + +=item install_types() + +[version 0.28] + +Returns a list of installable types that this build knows about. +These types each correspond to the name of a directory in F<blib/>, +and the list usually includes items such as C<lib>, C<arch>, C<bin>, +C<script>, C<libdoc>, C<bindoc>, and if HTML documentation is to be +built, C<libhtml> and C<binhtml>. Other user-defined types may also +exist. + +=item invoked_action() + +[version 0.28] + +This is the name of the original action invoked by the user. This +value is set when the user invokes F<Build.PL>, the F<Build> script, +or programmatically through the L<dispatch()|/"dispatch($action, %args)"> +method. It does not change as sub-actions are executed as +dependencies are evaluated. + +To get the name of the currently executing dependency, see +L</current_action()> above. + +=item notes() + +=item notes($key) + +=item notes($key => $value) + +[version 0.20] + +The C<notes()> value allows you to store your own persistent +information about the build, and to share that information among +different entities involved in the build. See the example in the +C<current()> method. + +The C<notes()> method is essentially a glorified hash access. With no +arguments, C<notes()> returns the entire hash of notes. With one argument, +C<notes($key)> returns the value associated with the given key. With two +arguments, C<notes($key, $value)> sets the value associated with the given key +to C<$value> and returns the new value. + +The lifetime of the C<notes> data is for "a build" - that is, the +C<notes> hash is created when C<perl Build.PL> is run (or when the +C<new()> method is run, if the Module::Build Perl API is being used +instead of called from a shell), and lasts until C<perl Build.PL> is +run again or the C<clean> action is run. + +=item orig_dir() + +[version 0.28] + +Returns a string containing the working directory that was in effect +before the F<Build> script chdir()-ed into the C<base_dir>. This +might be useful for writing wrapper tools that might need to chdir() +back out. + +=item os_type() + +[version 0.04] + +If you're subclassing Module::Build and some code needs to alter its +behavior based on the current platform, you may only need to know +whether you're running on Windows, Unix, MacOS, VMS, etc., and not the +fine-grained value of Perl's C<$^O> variable. The C<os_type()> method +will return a string like C<Windows>, C<Unix>, C<MacOS>, C<VMS>, or +whatever is appropriate. If you're running on an unknown platform, it +will return C<undef> - there shouldn't be many unknown platforms +though. + +=item is_vmsish() + +=item is_windowsish() + +=item is_unixish() + +Convenience functions that return a boolean value indicating whether +this platform behaves respectively like VMS, Windows, or Unix. For +arbitrary reasons other platforms don't get their own such functions, +at least not yet. + + +=item prefix_relpaths() + +=item prefix_relpaths($installdirs) + +=item prefix_relpaths($installdirs, $type) + +=item prefix_relpaths($installdirs, $type => $path) + +[version 0.28] + +Set or retrieve the relative paths that are appended to C<prefix> for +any installable element. This is useful if you want to set the +relative install path for custom build elements. + +With no argument, it returns a reference to a hash containing all +elements and their respective values as defined by the current +C<installdirs> setting. + +With a single argument, it returns a reference to a hash containing +all elements and their respective values as defined by +C<$installdirs>. + +The hash returned by the above calls should not be modified directly; +use the three-argument below form to change values. + +The two argument form returns the value associated with the +element C<$type>. + +The multiple argument form allows you to set the paths for element types. +C<$value> must be a relative path using Unix-like paths. (A series of +directories separated by slashes, e.g. C<foo/bar>.) The return value is a +localized path based on C<$value>. + +Assigning the value C<undef> to an element causes it to be removed. + +=item get_metadata() + +[version 0.36] + +This method returns a hash reference of metadata that can be used to create a +YAML datastream. It is provided for authors to override or customize the fields +of F<META.yml>. E.g. + + package My::Builder; + use base 'Module::Build'; + + sub get_metadata { + my $self, @args = @_; + my $data = $self->SUPER::get_metadata(@args); + $data->{custom_field} = 'foo'; + return $data; + } + +Valid arguments include: + +=over + +=item * + +C<fatal> -- indicates whether missing required +metadata fields should be a fatal error or not. For META creation, it +generally should, but for MYMETA creation for end-users, it should not be +fatal. + +=item * + +C<auto> -- indicates whether any necessary configure_requires should be +automatically added. This is used in META creation. + +=back + +This method is a wrapper around the old prepare_metadata API now that we +no longer use YAML::Node to hold metadata. + +=item prepare_metadata() [deprecated] + +[version 0.36] + +[Deprecated] As of 0.36, authors should use C<get_metadata> instead. This +method is preserved for backwards compatibility only. + +It takes three positional arguments: a hashref (to which metadata will be +added), an optional arrayref (to which metadata keys will be added in order if +the arrayref exists), and a hashref of arguments (as provided to get_metadata). +The latter argument is new as of 0.36. Earlier versions are always fatal on +errors. + +Prior to version 0.36, this method took a YAML::Node as an argument to hold +assembled metadata. + +=item prereq_failures() + +[version 0.11] + +Returns a data structure containing information about any failed +prerequisites (of any of the types described above), or C<undef> if +all prerequisites are met. + +The data structure returned is a hash reference. The top level keys +are the type of prerequisite failed, one of "requires", +"build_requires", "conflicts", or "recommends". The associated values +are hash references whose keys are the names of required (or +conflicting) modules. The associated values of those are hash +references indicating some information about the failure. For example: + + { + have => '0.42', + need => '0.59', + message => 'Version 0.42 is installed, but we need version 0.59', + } + +or + + { + have => '<none>', + need => '0.59', + message => 'Prerequisite Foo isn't installed', + } + +This hash has the same structure as the hash returned by the +C<check_installed_status()> method, except that in the case of +"conflicts" dependencies we change the "need" key to "conflicts" and +construct a proper message. + +Examples: + + # Check a required dependency on Foo::Bar + if ( $build->prereq_failures->{requires}{Foo::Bar} ) { ... + + # Check whether there were any failures + if ( $build->prereq_failures ) { ... + + # Show messages for all failures + my $failures = $build->prereq_failures; + while (my ($type, $list) = each %$failures) { + while (my ($name, $hash) = each %$list) { + print "Failure for $name: $hash->{message}\n"; + } + } + +=item prereq_data() + +[version 0.32] + +Returns a reference to a hash describing all prerequisites. The keys of the +hash will be the various prerequisite types ('requires', 'build_requires', +'test_requires', 'configure_requires', 'recommends', or 'conflicts') and the values will be +references to hashes of module names and version numbers. Only prerequisites +types that are defined will be included. The C<prereq_data> action is just a +thin wrapper around the C<prereq_data()> method and dumps the hash as a string +that can be loaded using C<eval()>. + +=item prereq_report() + +[version 0.28] + +Returns a human-readable (table-form) string showing all +prerequisites, the versions required, and the versions actually +installed. This can be useful for reviewing the configuration of your +system prior to a build, or when compiling data to send for a bug +report. The C<prereq_report> action is just a thin wrapper around the +C<prereq_report()> method. + +=item prompt($message, $default) + +[version 0.12] + +Asks the user a question and returns their response as a string. The +first argument specifies the message to display to the user (for +example, C<"Where do you keep your money?">). The second argument, +which is optional, specifies a default answer (for example, +C<"wallet">). The user will be asked the question once. + +If C<prompt()> detects that it is not running interactively and there +is nothing on STDIN or if the PERL_MM_USE_DEFAULT environment variable +is set to true, the $default will be used without prompting. + +To prevent automated processes from blocking, the user must either set +PERL_MM_USE_DEFAULT or attach something to STDIN (this can be a +pipe/file containing a scripted set of answers or /dev/null.) + +If no $default is provided an empty string will be used instead. In +non-interactive mode, the absence of $default is an error (though +explicitly passing C<undef()> as the default is valid as of 0.27.) + +This method may be called as a class or object method. + +=item recommends() + +[version 0.21] + +Returns a hash reference indicating the C<recommends> prerequisites +that were passed to the C<new()> method. + +=item requires() + +[version 0.21] + +Returns a hash reference indicating the C<requires> prerequisites that +were passed to the C<new()> method. + +=item rscan_dir($dir, $pattern) + +[version 0.28] + +Uses C<File::Find> to traverse the directory C<$dir>, returning a +reference to an array of entries matching C<$pattern>. C<$pattern> +may either be a regular expression (using C<qr//> or just a plain +string), or a reference to a subroutine that will return true for +wanted entries. If C<$pattern> is not given, all entries will be +returned. + +Examples: + + # All the *.pm files in lib/ + $m->rscan_dir('lib', qr/\.pm$/) + + # All the files in blib/ that aren't *.html files + $m->rscan_dir('blib', sub {-f $_ and not /\.html$/}); + + # All the files in t/ + $m->rscan_dir('t'); + +=item runtime_params() + +=item runtime_params($key) + +[version 0.28] + +The C<runtime_params()> method stores the values passed on the command line +for valid properties (that is, any command line options for which +C<valid_property()> returns a true value). The value on the command line may +override the default value for a property, as well as any value specified in a +call to C<new()>. This allows you to programmatically tell if C<perl Build.PL> +or any execution of C<./Build> had command line options specified that +override valid properties. + +The C<runtime_params()> method is essentially a glorified read-only hash. With +no arguments, C<runtime_params()> returns the entire hash of properties +specified on the command line. With one argument, C<runtime_params($key)> +returns the value associated with the given key. + +The lifetime of the C<runtime_params> data is for "a build" - that is, the +C<runtime_params> hash is created when C<perl Build.PL> is run (or when the +C<new()> method is called, if the Module::Build Perl API is being used instead +of called from a shell), and lasts until C<perl Build.PL> is run again or the +C<clean> action is run. + +=item script_files() + +[version 0.18] + +Returns a hash reference whose keys are the perl script files to be +installed, if any. This corresponds to the C<script_files> parameter to the +C<new()> method. With an optional argument, this parameter may be set +dynamically. + +For backward compatibility, the C<scripts()> method does exactly the +same thing as C<script_files()>. C<scripts()> is deprecated, but it +will stay around for several versions to give people time to +transition. + +=item up_to_date($source_file, $derived_file) + +=item up_to_date(\@source_files, \@derived_files) + +[version 0.20] + +This method can be used to compare a set of source files to a set of +derived files. If any of the source files are newer than any of the +derived files, it returns false. Additionally, if any of the derived +files do not exist, it returns false. Otherwise it returns true. + +The arguments may be either a scalar or an array reference of file +names. + +=item y_n($message, $default) + +[version 0.12] + +Asks the user a yes/no question using C<prompt()> and returns true or +false accordingly. The user will be asked the question repeatedly +until they give an answer that looks like "yes" or "no". + +The first argument specifies the message to display to the user (for +example, C<"Shall I invest your money for you?">), and the second +argument specifies the default answer (for example, C<"y">). + +Note that the default is specified as a string like C<"y"> or C<"n">, +and the return value is a Perl boolean value like 1 or 0. I thought +about this for a while and this seemed like the most useful way to do +it. + +This method may be called as a class or object method. + +=back + + +=head2 Autogenerated Accessors + +In addition to the aforementioned methods, there are also some get/set +accessor methods for the following properties: + +=over 4 + +=item PL_files() + +=item allow_mb_mismatch() + +=item allow_pureperl() + +=item auto_configure_requires() + +=item autosplit() + +=item base_dir() + +=item bindoc_dirs() + +=item blib() + +=item build_bat() + +=item build_class() + +=item build_elements() + +=item build_requires() + +=item build_script() + +=item bundle_inc() + +=item bundle_inc_preload() + +=item c_source() + +=item config_dir() + +=item configure_requires() + +=item conflicts() + +=item cpan_client() + +=item create_license() + +=item create_makefile_pl() + +=item create_packlist() + +=item create_readme() + +=item debug() + +=item debugger() + +=item destdir() + +=item dynamic_config() + +=item extra_manify_args() + +=item get_options() + +=item html_css() + +=item include_dirs() + +=item install_base() + +=item installdirs() + +=item libdoc_dirs() + +=item license() + +=item magic_number() + +=item mb_version() + +=item meta_add() + +=item meta_merge() + +=item metafile() + +=item metafile2() + +=item module_name() + +=item mymetafile() + +=item mymetafile2() + +=item needs_compiler() + +=item orig_dir() + +=item perl() + +=item pm_files() + +=item pod_files() + +=item pollute() + +=item prefix() + +=item prereq_action_types() + +=item program_name() + +=item pureperl_only() + +=item quiet() + +=item recommends() + +=item recurse_into() + +=item recursive_test_files() + +=item requires() + +=item scripts() + +=item sign() + +=item tap_harness_args() + +=item test_file_exts() + +=item test_requires() + +=item use_rcfile() + +=item use_tap_harness() + +=item verbose() + +=item xs_files() + +=back + +=head1 MODULE METADATA + +If you would like to add other useful metadata, C<Module::Build> +supports this with the C<meta_add> and C<meta_merge> arguments to +L</new()>. The authoritative list of supported metadata can be found at +L<CPAN::Meta::Spec> but for convenience - here are a few of the more useful ones: + +=over 4 + +=item keywords + +For describing the distribution using keyword (or "tags") in order to +make CPAN.org indexing and search more efficient and useful. + +=item resources + +A list of additional resources available for users of the +distribution. This can include links to a homepage on the web, a +bug tracker, the repository location, and even a subscription page for the +distribution mailing list. + +=back + + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + + +=head1 SEE ALSO + +perl(1), L<Module::Build>(3), L<Module::Build::Authoring>(3), +L<Module::Build::Cookbook>(3), L<ExtUtils::MakeMaker>(3) + +F<META.yml> Specification: +L<CPAN::Meta::Spec> + +=cut diff --git a/lib/Module/Build/Authoring.pod b/lib/Module/Build/Authoring.pod new file mode 100644 index 0000000..a32b31e --- /dev/null +++ b/lib/Module/Build/Authoring.pod @@ -0,0 +1,326 @@ +=head1 NAME + +Module::Build::Authoring - Authoring Module::Build modules + +=head1 DESCRIPTION + +When creating a C<Build.PL> script for a module, something like the +following code will typically be used: + + use Module::Build; + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + license => 'perl', + requires => { + 'perl' => '5.6.1', + 'Some::Module' => '1.23', + 'Other::Module' => '>= 1.2, != 1.5, < 2.0', + }, + ); + $build->create_build_script; + +A simple module could get away with something as short as this for its +C<Build.PL> script: + + use Module::Build; + Module::Build->new( + module_name => 'Foo::Bar', + license => 'perl', + )->create_build_script; + +The model used by C<Module::Build> is a lot like the C<MakeMaker> +metaphor, with the following correspondences: + + In Module::Build In ExtUtils::MakeMaker + --------------------------- ------------------------ + Build.PL (initial script) Makefile.PL (initial script) + Build (a short perl script) Makefile (a long Makefile) + _build/ (saved state info) various config text in the Makefile + +Any customization can be done simply by subclassing C<Module::Build> +and adding a method called (for example) C<ACTION_test>, overriding +the default 'test' action. You could also add a method called +C<ACTION_whatever>, and then you could perform the action C<Build +whatever>. + +For information on providing compatibility with +C<ExtUtils::MakeMaker>, see L<Module::Build::Compat> and +L<http://www.makemaker.org/wiki/index.cgi?ModuleBuildConversionGuide>. + + +=head1 STRUCTURE + +Module::Build creates a class hierarchy conducive to customization. +Here is the parent-child class hierarchy in classy ASCII art: + + /--------------------\ + | Your::Parent | (If you subclass Module::Build) + \--------------------/ + | + | + /--------------------\ (Doesn't define any functionality + | Module::Build | of its own - just figures out what + \--------------------/ other modules to load.) + | + | + /-----------------------------------\ (Some values of $^O may + | Module::Build::Platform::$^O | define specialized functionality. + \-----------------------------------/ Otherwise it's ...::Default, a + | pass-through class.) + | + /--------------------------\ + | Module::Build::Base | (Most of the functionality of + \--------------------------/ Module::Build is defined here.) + + +=head1 SUBCLASSING + +Right now, there are two ways to subclass Module::Build. The first +way is to create a regular module (in a C<.pm> file) that inherits +from Module::Build, and use that module's class instead of using +Module::Build directly: + + ------ in Build.PL: ---------- + #!/usr/bin/perl + + use lib q(/nonstandard/library/path); + use My::Builder; # Or whatever you want to call it + + my $build = My::Builder->new + ( + module_name => 'Foo::Bar', # All the regular args... + license => 'perl', + dist_author => 'A N Other <me@here.net.au>', + requires => { Carp => 0 } + ); + $build->create_build_script; + +This is relatively straightforward, and is the best way to do things +if your My::Builder class contains lots of code. The +C<create_build_script()> method will ensure that the current value of +C<@INC> (including the C</nonstandard/library/path>) is propagated to +the Build script, so that My::Builder can be found when running build +actions. If you find that you need to C<chdir> into a different directories +in your subclass methods or actions, be sure to always return to the original +directory (available via the C<base_dir()> method) before returning control +to the parent class. This is important to avoid data serialization problems. + +For very small additions, Module::Build provides a C<subclass()> +method that lets you subclass Module::Build more conveniently, without +creating a separate file for your module: + + ------ in Build.PL: ---------- + #!/usr/bin/perl + + use Module::Build; + my $class = Module::Build->subclass + ( + class => 'My::Builder', + code => q{ + sub ACTION_foo { + print "I'm fooing to death!\n"; + } + }, + ); + + my $build = $class->new + ( + module_name => 'Foo::Bar', # All the regular args... + license => 'perl', + dist_author => 'A N Other <me@here.net.au>', + requires => { Carp => 0 } + ); + $build->create_build_script; + +Behind the scenes, this actually does create a C<.pm> file, since the +code you provide must persist after Build.PL is run if it is to be +very useful. + +See also the documentation for the L<Module::Build::API/"subclass()"> +method. + + +=head1 PREREQUISITES + +=head2 Types of prerequisites + +To specify what versions of other modules are used by this +distribution, several types of prerequisites can be defined with the +following parameters: + +=over 3 + +=item configure_requires + +Items that must be installed I<before> configuring this distribution +(i.e. before running the F<Build.PL> script). This might be a +specific minimum version of C<Module::Build> or any other module the +F<Build.PL> needs in order to do its stuff. Clients like C<CPAN.pm> +or C<CPANPLUS> will be expected to pick C<configure_requires> out of the +F<META.yml> file and install these items before running the +C<Build.PL>. + +If no configure_requires is specified, the current version of Module::Build +is automatically added to configure_requires. + +=item build_requires + +Items that are necessary for building and testing this distribution, +but aren't necessary after installation. This can help users who only +want to install these items temporarily. It also helps reduce the +size of the CPAN dependency graph if everything isn't smooshed into +C<requires>. + +=item requires + +Items that are necessary for basic functioning. + +=item recommends + +Items that are recommended for enhanced functionality, but there are +ways to use this distribution without having them installed. You +might also think of this as "can use" or "is aware of" or "changes +behavior in the presence of". + +=item test_requires + +Items that are necessary for testing. + +=item conflicts + +Items that can cause problems with this distribution when installed. +This is pretty rare. + +=back + +=head2 Format of prerequisites + +The prerequisites are given in a hash reference, where the keys are +the module names and the values are version specifiers: + + requires => { + Foo::Module => '2.4', + Bar::Module => 0, + Ken::Module => '>= 1.2, != 1.5, < 2.0', + perl => '5.6.0' + }, + +The above four version specifiers have different effects. The value +C<'2.4'> means that B<at least> version 2.4 of C<Foo::Module> must be +installed. The value C<0> means that B<any> version of C<Bar::Module> +is acceptable, even if C<Bar::Module> doesn't define a version. The +more verbose value C<'E<gt>= 1.2, != 1.5, E<lt> 2.0'> means that +C<Ken::Module>'s version must be B<at least> 1.2, B<less than> 2.0, +and B<not equal to> 1.5. The list of criteria is separated by commas, +and all criteria must be satisfied. + +A special C<perl> entry lets you specify the versions of the Perl +interpreter that are supported by your module. The same version +dependency-checking semantics are available, except that we also +understand perl's new double-dotted version numbers. + +=head2 XS Extensions + +Modules which need to compile XS code should list C<ExtUtils::CBuilder> +as a C<build_requires> element. + + +=head1 SAVING CONFIGURATION INFORMATION + +Module::Build provides a very convenient way to save configuration +information that your installed modules (or your regression tests) can +access. If your Build process calls the C<feature()> or +C<config_data()> methods, then a C<Foo::Bar::ConfigData> module will +automatically be created for you, where C<Foo::Bar> is the +C<module_name> parameter as passed to C<new()>. This module provides +access to the data saved by these methods, and a way to update the +values. There is also a utility script called C<config_data> +distributed with Module::Build that provides a command line interface +to this same functionality. See also the generated +C<Foo::Bar::ConfigData> documentation, and the C<config_data> +script's documentation, for more information. + + +=head1 STARTING MODULE DEVELOPMENT + +When starting development on a new module, it's rarely worth your time +to create a tree of all the files by hand. Some automatic +module-creators are available: the oldest is C<h2xs>, which has +shipped with perl itself for a long time. Its name reflects the fact +that modules were originally conceived of as a way to wrap up a C +library (thus the C<h> part) into perl extensions (thus the C<xs> +part). + +These days, C<h2xs> has largely been superseded by modules like +C<ExtUtils::ModuleMaker>, and C<Module::Starter>. They have varying +degrees of support for C<Module::Build>. + + +=head1 AUTOMATION + +One advantage of Module::Build is that since it's implemented as Perl +methods, you can invoke these methods directly if you want to install +a module non-interactively. For instance, the following Perl script +will invoke the entire build/install procedure: + + my $build = Module::Build->new(module_name => 'MyModule'); + $build->dispatch('build'); + $build->dispatch('test'); + $build->dispatch('install'); + +If any of these steps encounters an error, it will throw a fatal +exception. + +You can also pass arguments as part of the build process: + + my $build = Module::Build->new(module_name => 'MyModule'); + $build->dispatch('build'); + $build->dispatch('test', verbose => 1); + $build->dispatch('install', sitelib => '/my/secret/place/'); + +Building and installing modules in this way skips creating the +C<Build> script. + + +=head1 MIGRATION + +Note that if you want to provide both a F<Makefile.PL> and a +F<Build.PL> for your distribution, you probably want to add the +following to C<WriteMakefile> in your F<Makefile.PL> so that C<MakeMaker> +doesn't try to run your F<Build.PL> as a normal F<.PL> file: + + PL_FILES => {}, + +You may also be interested in looking at the C<Module::Build::Compat> +module, which can automatically create various kinds of F<Makefile.PL> +compatibility layers. + + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +Development questions, bug reports, and patches should be sent to the +Module-Build mailing list at <module-build@perl.org>. + +Bug reports are also welcome at +<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Build>. + +The latest development version is available from the Git +repository at <https://github.com/Perl-Toolchain-Gang/Module-Build> + + +=head1 SEE ALSO + +perl(1), L<Module::Build>(3), L<Module::Build::API>(3), +L<Module::Build::Cookbook>(3), L<ExtUtils::MakeMaker>(3), L<YAML>(3) + +F<META.yml> Specification: +L<CPAN::Meta::Spec> + +L<http://www.dsmit.com/cons/> + +L<http://search.cpan.org/dist/PerlBuildSystem/> + +=cut diff --git a/lib/Module/Build/Base.pm b/lib/Module/Build/Base.pm new file mode 100644 index 0000000..1cbc61e --- /dev/null +++ b/lib/Module/Build/Base.pm @@ -0,0 +1,5688 @@ +# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- +# vim:ts=8:sw=2:et:sta:sts=2 +package Module::Build::Base; + +use 5.006; +use strict; +use warnings; + +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; + +use Carp; +use Cwd (); +use File::Copy (); +use File::Find (); +use File::Path (); +use File::Basename (); +use File::Spec 0.82 (); +use File::Compare (); +use Module::Build::Dumper (); +use Text::ParseWords (); + +use Module::Metadata; +use Module::Build::Notes; +use Module::Build::Config; +use version; + + +#################### Constructors ########################### +sub new { + my $self = shift()->_construct(@_); + + $self->{invoked_action} = $self->{action} ||= 'Build_PL'; + $self->cull_args(@ARGV); + + die "Too early to specify a build action '$self->{action}'. Do 'Build $self->{action}' instead.\n" + if $self->{action} && $self->{action} ne 'Build_PL'; + + $self->check_manifest; + $self->auto_require; + + # All checks must run regardless if one fails, so no short circuiting! + if( grep { !$_ } $self->check_prereq, $self->check_autofeatures ) { + $self->log_warn(<<EOF); + +ERRORS/WARNINGS FOUND IN PREREQUISITES. You may wish to install the versions +of the modules indicated above before proceeding with this installation + +EOF + unless ( + $self->dist_name eq 'Module-Build' || + $ENV{PERL5_CPANPLUS_IS_RUNNING} || $ENV{PERL5_CPAN_IS_RUNNING} + ) { + $self->log_warn( + "Run 'Build installdeps' to install missing prerequisites.\n\n" + ); + } + } + + # record for later use in resume; + $self->{properties}{_added_to_INC} = [ $self->_added_to_INC ]; + + $self->set_bundle_inc; + + $self->dist_name; + $self->dist_version; + $self->release_status; + $self->_guess_module_name unless $self->module_name; + + $self->_find_nested_builds; + + return $self; +} + +sub resume { + my $package = shift; + my $self = $package->_construct(@_); + $self->read_config; + + my @added_earlier = @{ $self->{properties}{_added_to_INC} || [] }; + + @INC = ($self->_added_to_INC, @added_earlier, $self->_default_INC); + + # If someone called Module::Build->current() or + # Module::Build->new_from_context() and the correct class to use is + # actually a *subclass* of Module::Build, we may need to load that + # subclass here and re-delegate the resume() method to it. + unless ( $package->isa($self->build_class) ) { + my $build_class = $self->build_class; + my $config_dir = $self->config_dir || '_build'; + my $build_lib = File::Spec->catdir( $config_dir, 'lib' ); + unshift( @INC, $build_lib ); + unless ( $build_class->can('new') ) { + eval "require $build_class; 1" or die "Failed to re-load '$build_class': $@"; + } + return $build_class->resume(@_); + } + + unless ($self->_perl_is_same($self->{properties}{perl})) { + my $perl = $self->find_perl_interpreter; + die(<<"DIEFATAL"); +* FATAL ERROR: Perl interpreter mismatch. Configuration was initially + created with '$self->{properties}{perl}' + but we are now using '$perl'. You must + run 'Build realclean' or 'make realclean' and re-configure. +DIEFATAL + } + + $self->cull_args(@ARGV); + + unless ($self->allow_mb_mismatch) { + my $mb_version = $Module::Build::VERSION; + if ( $mb_version ne $self->{properties}{mb_version} ) { + $self->log_warn(<<"MISMATCH"); +* WARNING: Configuration was initially created with Module::Build + version '$self->{properties}{mb_version}' but we are now using version '$mb_version'. + If errors occur, you must re-run the Build.PL or Makefile.PL script. +MISMATCH + } + } + + $self->{invoked_action} = $self->{action} ||= 'build'; + + return $self; +} + +sub new_from_context { + my ($package, %args) = @_; + + $package->run_perl_script('Build.PL',[],[$package->unparse_args(\%args)]); + return $package->resume; +} + +sub current { + # hmm, wonder what the right thing to do here is + local @ARGV; + return shift()->resume; +} + +sub _construct { + my ($package, %input) = @_; + + my $args = delete $input{args} || {}; + my $config = delete $input{config} || {}; + + my $self = bless { + args => {%$args}, + config => Module::Build::Config->new(values => $config), + properties => { + base_dir => $package->cwd, + mb_version => $Module::Build::VERSION, + %input, + }, + phash => {}, + stash => {}, # temporary caching, not stored in _build + }, $package; + + $self->_set_defaults; + my ($p, $ph) = ($self->{properties}, $self->{phash}); + + foreach (qw(notes config_data features runtime_params cleanup auto_features)) { + my $file = File::Spec->catfile($self->config_dir, $_); + $ph->{$_} = Module::Build::Notes->new(file => $file); + $ph->{$_}->restore if -e $file; + if (exists $p->{$_}) { + my $vals = delete $p->{$_}; + while (my ($k, $v) = each %$vals) { + $self->$_($k, $v); + } + } + } + + # The following warning could be unnecessary if the user is running + # an embedded perl, but there aren't too many of those around, and + # embedded perls aren't usually used to install modules, and the + # installation process sometimes needs to run external scripts + # (e.g. to run tests). + $p->{perl} = $self->find_perl_interpreter + or $self->log_warn("Warning: Can't locate your perl binary"); + + my $blibdir = sub { File::Spec->catdir($p->{blib}, @_) }; + $p->{bindoc_dirs} ||= [ $blibdir->("script") ]; + $p->{libdoc_dirs} ||= [ $blibdir->("lib"), $blibdir->("arch") ]; + + $p->{dist_author} = [ $p->{dist_author} ] if defined $p->{dist_author} and not ref $p->{dist_author}; + + # Synonyms + $p->{requires} = delete $p->{prereq} if defined $p->{prereq}; + $p->{script_files} = delete $p->{scripts} if defined $p->{scripts}; + + # Convert to from shell strings to arrays + for ('extra_compiler_flags', 'extra_linker_flags') { + $p->{$_} = [ $self->split_like_shell($p->{$_}) ] if exists $p->{$_}; + } + + # Convert to arrays + for ('include_dirs') { + $p->{$_} = [ $p->{$_} ] if exists $p->{$_} && !ref $p->{$_} + } + + $self->add_to_cleanup( @{delete $p->{add_to_cleanup}} ) + if $p->{add_to_cleanup}; + + return $self; +} + +################## End constructors ######################### + +sub log_info { + my $self = shift; + print @_ if ref($self) && ( $self->verbose || ! $self->quiet ); +} +sub log_verbose { + my $self = shift; + print @_ if ref($self) && $self->verbose; +} +sub log_debug { + my $self = shift; + print @_ if ref($self) && $self->debug; +} + +sub log_warn { + # Try to make our call stack invisible + shift; + if (@_ and $_[-1] !~ /\n$/) { + my (undef, $file, $line) = caller(); + warn @_, " at $file line $line.\n"; + } else { + warn @_; + } +} + + +# install paths must be generated when requested to be sure all changes +# to config (from various sources) are included +sub _default_install_paths { + my $self = shift; + my $c = $self->{config}; + my $p = {}; + + my @libstyle = $c->get('installstyle') ? + File::Spec->splitdir($c->get('installstyle')) : qw(lib perl5); + my $arch = $c->get('archname'); + my $version = $c->get('version'); + + my $bindoc = $c->get('installman1dir') || undef; + my $libdoc = $c->get('installman3dir') || undef; + + my $binhtml = $c->get('installhtml1dir') || $c->get('installhtmldir') || undef; + my $libhtml = $c->get('installhtml3dir') || $c->get('installhtmldir') || undef; + + $p->{install_sets} = + { + core => { + lib => $c->get('installprivlib'), + arch => $c->get('installarchlib'), + bin => $c->get('installbin'), + script => $c->get('installscript'), + bindoc => $bindoc, + libdoc => $libdoc, + binhtml => $binhtml, + libhtml => $libhtml, + }, + site => { + lib => $c->get('installsitelib'), + arch => $c->get('installsitearch'), + bin => $c->get('installsitebin') || $c->get('installbin'), + script => $c->get('installsitescript') || + $c->get('installsitebin') || $c->get('installscript'), + bindoc => $c->get('installsiteman1dir') || $bindoc, + libdoc => $c->get('installsiteman3dir') || $libdoc, + binhtml => $c->get('installsitehtml1dir') || $binhtml, + libhtml => $c->get('installsitehtml3dir') || $libhtml, + }, + vendor => { + lib => $c->get('installvendorlib'), + arch => $c->get('installvendorarch'), + bin => $c->get('installvendorbin') || $c->get('installbin'), + script => $c->get('installvendorscript') || + $c->get('installvendorbin') || $c->get('installscript'), + bindoc => $c->get('installvendorman1dir') || $bindoc, + libdoc => $c->get('installvendorman3dir') || $libdoc, + binhtml => $c->get('installvendorhtml1dir') || $binhtml, + libhtml => $c->get('installvendorhtml3dir') || $libhtml, + }, + }; + + $p->{original_prefix} = + { + core => $c->get('installprefixexp') || $c->get('installprefix') || + $c->get('prefixexp') || $c->get('prefix') || '', + site => $c->get('siteprefixexp'), + vendor => $c->get('usevendorprefix') ? $c->get('vendorprefixexp') : '', + }; + $p->{original_prefix}{site} ||= $p->{original_prefix}{core}; + + # Note: you might be tempted to use $Config{installstyle} here + # instead of hard-coding lib/perl5, but that's been considered and + # (at least for now) rejected. `perldoc Config` has some wisdom + # about it. + $p->{install_base_relpaths} = + { + lib => ['lib', 'perl5'], + arch => ['lib', 'perl5', $arch], + bin => ['bin'], + script => ['bin'], + bindoc => ['man', 'man1'], + libdoc => ['man', 'man3'], + binhtml => ['html'], + libhtml => ['html'], + }; + + $p->{prefix_relpaths} = + { + core => { + lib => [@libstyle], + arch => [@libstyle, $version, $arch], + bin => ['bin'], + script => ['bin'], + bindoc => ['man', 'man1'], + libdoc => ['man', 'man3'], + binhtml => ['html'], + libhtml => ['html'], + }, + vendor => { + lib => [@libstyle], + arch => [@libstyle, $version, $arch], + bin => ['bin'], + script => ['bin'], + bindoc => ['man', 'man1'], + libdoc => ['man', 'man3'], + binhtml => ['html'], + libhtml => ['html'], + }, + site => { + lib => [@libstyle, 'site_perl'], + arch => [@libstyle, 'site_perl', $version, $arch], + bin => ['bin'], + script => ['bin'], + bindoc => ['man', 'man1'], + libdoc => ['man', 'man3'], + binhtml => ['html'], + libhtml => ['html'], + }, + }; + return $p +} + +sub _find_nested_builds { + my $self = shift; + my $r = $self->recurse_into or return; + + my ($file, @r); + if (!ref($r) && $r eq 'auto') { + local *DH; + opendir DH, $self->base_dir + or die "Can't scan directory " . $self->base_dir . " for nested builds: $!"; + while (defined($file = readdir DH)) { + my $subdir = File::Spec->catdir( $self->base_dir, $file ); + next unless -d $subdir; + push @r, $subdir if -e File::Spec->catfile( $subdir, 'Build.PL' ); + } + } + + $self->recurse_into(\@r); +} + +sub cwd { + return Cwd::cwd(); +} + +sub _quote_args { + # Returns a string that can become [part of] a command line with + # proper quoting so that the subprocess sees this same list of args. + my ($self, @args) = @_; + + my @quoted; + + for (@args) { + if ( /^[^\s*?!\$<>;\\|'"\[\]\{\}]+$/ ) { + # Looks pretty safe + push @quoted, $_; + } else { + # XXX this will obviously have to improve - is there already a + # core module lying around that does proper quoting? + s/('+)/'"$1"'/g; + push @quoted, qq('$_'); + } + } + + return join " ", @quoted; +} + +sub _backticks { + my ($self, @cmd) = @_; + if ($self->have_forkpipe) { + local *FH; + my $pid = open *FH, "-|"; + if ($pid) { + return wantarray ? <FH> : join '', <FH>; + } else { + die "Can't execute @cmd: $!\n" unless defined $pid; + exec { $cmd[0] } @cmd; + } + } else { + my $cmd = $self->_quote_args(@cmd); + return `$cmd`; + } +} + +# Tells us whether the construct open($fh, '-|', @command) is +# supported. It would probably be better to dynamically sense this. +sub have_forkpipe { 1 } + +# Determine whether a given binary is the same as the perl +# (configuration) that started this process. +sub _perl_is_same { + my ($self, $perl) = @_; + + my @cmd = ($perl); + + # When run from the perl core, @INC will include the directories + # where perl is yet to be installed. We need to reference the + # absolute path within the source distribution where it can find + # it's Config.pm This also prevents us from picking up a Config.pm + # from a different configuration that happens to be already + # installed in @INC. + if ($ENV{PERL_CORE}) { + push @cmd, '-I' . File::Spec->catdir(File::Basename::dirname($perl), 'lib'); + } + + push @cmd, qw(-MConfig=myconfig -e print -e myconfig); + return $self->_backticks(@cmd) eq Config->myconfig; +} + +# cache _discover_perl_interpreter() results +{ + my $known_perl; + sub find_perl_interpreter { + my $self = shift; + + return $known_perl if defined($known_perl); + return $known_perl = $self->_discover_perl_interpreter; + } +} + +# Returns the absolute path of the perl interpreter used to invoke +# this process. The path is derived from $^X or $Config{perlpath}. On +# some platforms $^X contains the complete absolute path of the +# interpreter, on other it may contain a relative path, or simply +# 'perl'. This can also vary depending on whether a path was supplied +# when perl was invoked. Additionally, the value in $^X may omit the +# executable extension on platforms that use one. It's a fatal error +# if the interpreter can't be found because it can result in undefined +# behavior by routines that depend on it (generating errors or +# invoking the wrong perl.) +sub _discover_perl_interpreter { + my $proto = shift; + my $c = ref($proto) ? $proto->{config} : 'Module::Build::Config'; + + my $perl = $^X; + my $perl_basename = File::Basename::basename($perl); + + my @potential_perls; + + # Try 1, Check $^X for absolute path + push( @potential_perls, $perl ) + if File::Spec->file_name_is_absolute($perl); + + # Try 2, Check $^X for a valid relative path + my $abs_perl = File::Spec->rel2abs($perl); + push( @potential_perls, $abs_perl ); + + # Try 3, Last ditch effort: These two option use hackery to try to locate + # a suitable perl. The hack varies depending on whether we are running + # from an installed perl or an uninstalled perl in the perl source dist. + if ($ENV{PERL_CORE}) { + + # Try 3.A, If we are in a perl source tree, running an uninstalled + # perl, we can keep moving up the directory tree until we find our + # binary. We wouldn't do this under any other circumstances. + + # CBuilder is also in the core, so it should be available here + require ExtUtils::CBuilder; + my $perl_src = Cwd::realpath( ExtUtils::CBuilder->perl_src ); + if ( defined($perl_src) && length($perl_src) ) { + my $uninstperl = + File::Spec->rel2abs(File::Spec->catfile( $perl_src, $perl_basename )); + push( @potential_perls, $uninstperl ); + } + + } else { + + # Try 3.B, First look in $Config{perlpath}, then search the user's + # PATH. We do not want to do either if we are running from an + # uninstalled perl in a perl source tree. + + push( @potential_perls, $c->get('perlpath') ); + + push( @potential_perls, + map File::Spec->catfile($_, $perl_basename), File::Spec->path() ); + } + + # Now that we've enumerated the potential perls, it's time to test + # them to see if any of them match our configuration, returning the + # absolute path of the first successful match. + my $exe = $c->get('exe_ext'); + foreach my $thisperl ( @potential_perls ) { + + if (defined $exe) { + $thisperl .= $exe unless $thisperl =~ m/$exe$/i; + } + + if ( -f $thisperl && $proto->_perl_is_same($thisperl) ) { + return $thisperl; + } + } + + # We've tried all alternatives, and didn't find a perl that matches + # our configuration. Throw an exception, and list alternatives we tried. + my @paths = map File::Basename::dirname($_), @potential_perls; + die "Can't locate the perl binary used to run this script " . + "in (@paths)\n"; +} + +# Adapted from IPC::Cmd::can_run() +sub find_command { + my ($self, $command) = @_; + + if( File::Spec->file_name_is_absolute($command) ) { + return $self->_maybe_command($command); + + } else { + for my $dir ( File::Spec->path ) { + my $abs = File::Spec->catfile($dir, $command); + return $abs if $abs = $self->_maybe_command($abs); + } + } +} + +# Copied from ExtUtils::MM_Unix::maybe_command +sub _maybe_command { + my($self,$file) = @_; + return $file if -x $file && ! -d $file; + return; +} + +sub _is_interactive { + return -t STDIN && (-t STDOUT || !(-f STDOUT || -c STDOUT)) ; # Pipe? +} + +# NOTE this is a blocking operation if(-t STDIN) +sub _is_unattended { + my $self = shift; + return $ENV{PERL_MM_USE_DEFAULT} || + ( !$self->_is_interactive && eof STDIN ); +} + +sub _readline { + my $self = shift; + return undef if $self->_is_unattended; + + my $answer = <STDIN>; + chomp $answer if defined $answer; + return $answer; +} + +sub prompt { + my $self = shift; + my $mess = shift + or die "prompt() called without a prompt message"; + + # use a list to distinguish a default of undef() from no default + my @def; + @def = (shift) if @_; + # use dispdef for output + my @dispdef = scalar(@def) ? + ('[', (defined($def[0]) ? $def[0] . ' ' : ''), ']') : + (' ', ''); + + local $|=1; + print "$mess ", @dispdef; + + if ( $self->_is_unattended && !@def ) { + die <<EOF; +ERROR: This build seems to be unattended, but there is no default value +for this question. Aborting. +EOF + } + + my $ans = $self->_readline(); + + if ( !defined($ans) # Ctrl-D or unattended + or !length($ans) ) { # User hit return + print "$dispdef[1]\n"; + $ans = scalar(@def) ? $def[0] : ''; + } + + return $ans; +} + +sub y_n { + my $self = shift; + my ($mess, $def) = @_; + + die "y_n() called without a prompt message" unless $mess; + die "Invalid default value: y_n() default must be 'y' or 'n'" + if $def && $def !~ /^[yn]/i; + + my $answer; + while (1) { # XXX Infinite or a large number followed by an exception ? + $answer = $self->prompt(@_); + return 1 if $answer =~ /^y/i; + return 0 if $answer =~ /^n/i; + local $|=1; + print "Please answer 'y' or 'n'.\n"; + } +} + +sub current_action { shift->{action} } +sub invoked_action { shift->{invoked_action} } + +sub notes { shift()->{phash}{notes}->access(@_) } +sub config_data { shift()->{phash}{config_data}->access(@_) } +sub runtime_params { shift->{phash}{runtime_params}->read( @_ ? shift : () ) } # Read-only +sub auto_features { shift()->{phash}{auto_features}->access(@_) } + +sub features { + my $self = shift; + my $ph = $self->{phash}; + + if (@_) { + my $key = shift; + if ($ph->{features}->exists($key)) { + return $ph->{features}->access($key, @_); + } + + if (my $info = $ph->{auto_features}->access($key)) { + my $disabled; + for my $type ( @{$self->prereq_action_types} ) { + next if $type eq 'description' || $type eq 'recommends' || ! exists $info->{$type}; + my $prereqs = $info->{$type}; + for my $modname ( sort keys %$prereqs ) { + my $spec = $prereqs->{$modname}; + my $status = $self->check_installed_status($modname, $spec); + if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; } + if ( ! eval "require $modname; 1" ) { return 0; } + } + } + return 1; + } + + return $ph->{features}->access($key, @_); + } + + # No args - get the auto_features & overlay the regular features + my %features; + my %auto_features = $ph->{auto_features}->access(); + while (my ($name, $info) = each %auto_features) { + my $failures = $self->prereq_failures($info); + my $disabled = grep( /^(?:\w+_)?(?:requires|conflicts)$/, + keys %$failures ) ? 1 : 0; + $features{$name} = $disabled ? 0 : 1; + } + %features = (%features, $ph->{features}->access()); + + return wantarray ? %features : \%features; +} +BEGIN { *feature = \&features } # Alias + +sub _mb_feature { + my $self = shift; + + if (($self->module_name || '') eq 'Module::Build') { + # We're building Module::Build itself, so ...::ConfigData isn't + # valid, but $self->features() should be. + return $self->feature(@_); + } else { + require Module::Build::ConfigData; + return Module::Build::ConfigData->feature(@_); + } +} + +sub _warn_mb_feature_deps { + my $self = shift; + my $name = shift; + $self->log_warn( + "The '$name' feature is not available. Please install missing\n" . + "feature dependencies and try again.\n". + $self->_feature_deps_msg($name) . "\n" + ); +} + +sub add_build_element { + my ($self, $elem) = @_; + my $elems = $self->build_elements; + push @$elems, $elem unless grep { $_ eq $elem } @$elems; +} + +sub ACTION_config_data { + my $self = shift; + return unless $self->has_config_data; + + my $module_name = $self->module_name + or die "The config_data feature requires that 'module_name' be set"; + my $notes_name = $module_name . '::ConfigData'; # TODO: Customize name ??? + my $notes_pm = File::Spec->catfile($self->blib, 'lib', split /::/, "$notes_name.pm"); + + return if $self->up_to_date(['Build.PL', + $self->config_file('config_data'), + $self->config_file('features') + ], $notes_pm); + + $self->log_verbose("Writing config notes to $notes_pm\n"); + File::Path::mkpath(File::Basename::dirname($notes_pm)); + + Module::Build::Notes->write_config_data + ( + file => $notes_pm, + module => $module_name, + config_module => $notes_name, + config_data => scalar $self->config_data, + feature => scalar $self->{phash}{features}->access(), + auto_features => scalar $self->auto_features, + ); +} + +######################################################################## +{ # enclosing these lexicals -- TODO + my %valid_properties = ( __PACKAGE__, {} ); + my %additive_properties; + + sub _mb_classes { + my $class = ref($_[0]) || $_[0]; + return ($class, $class->mb_parents); + } + + sub valid_property { + my ($class, $prop) = @_; + return grep exists( $valid_properties{$_}{$prop} ), $class->_mb_classes; + } + + sub valid_properties { + return keys %{ shift->valid_properties_defaults() }; + } + + sub valid_properties_defaults { + my %out; + for my $class (reverse shift->_mb_classes) { + @out{ keys %{ $valid_properties{$class} } } = map { + $_->() + } values %{ $valid_properties{$class} }; + } + return \%out; + } + + sub array_properties { + map { exists $additive_properties{$_}->{ARRAY} ? @{$additive_properties{$_}->{ARRAY}} : () } shift->_mb_classes; + } + + sub hash_properties { + map { exists $additive_properties{$_}->{HASH} ? @{$additive_properties{$_}->{HASH}} : () } shift->_mb_classes; + } + + sub add_property { + my ($class, $property) = (shift, shift); + die "Property '$property' already exists" + if $class->valid_property($property); + my %p = @_ == 1 ? ( default => shift ) : @_; + + my $type = ref $p{default}; + $valid_properties{$class}{$property} = + $type eq 'CODE' ? $p{default} : + $type eq 'HASH' ? sub { return { %{ $p{default} } } } : + $type eq 'ARRAY'? sub { return [ @{ $p{default} } ] } : + sub { return $p{default} } ; + + push @{$additive_properties{$class}->{$type}}, $property + if $type; + + unless ($class->can($property)) { + # TODO probably should put these in a util package + my $sub = $type eq 'HASH' + ? _make_hash_accessor($property, \%p) + : _make_accessor($property, \%p); + no strict 'refs'; + *{"$class\::$property"} = $sub; + } + + return $class; + } + + sub property_error { + my $self = shift; + die 'ERROR: ', @_; + } + + sub _set_defaults { + my $self = shift; + + # Set the build class. + $self->{properties}{build_class} ||= ref $self; + + # If there was no orig_dir, set to the same as base_dir + $self->{properties}{orig_dir} ||= $self->{properties}{base_dir}; + + my $defaults = $self->valid_properties_defaults; + + foreach my $prop (keys %$defaults) { + $self->{properties}{$prop} = $defaults->{$prop} + unless exists $self->{properties}{$prop}; + } + + # Copy defaults for arrays any arrays. + for my $prop ($self->array_properties) { + $self->{properties}{$prop} = [@{$defaults->{$prop}}] + unless exists $self->{properties}{$prop}; + } + # Copy defaults for arrays any hashes. + for my $prop ($self->hash_properties) { + $self->{properties}{$prop} = {%{$defaults->{$prop}}} + unless exists $self->{properties}{$prop}; + } + } + +} # end enclosure +######################################################################## +sub _make_hash_accessor { + my ($property, $p) = @_; + my $check = $p->{check} || sub { 1 }; + + return sub { + my $self = shift; + + # This is only here to deprecate the historic accident of calling + # properties as class methods - I suspect it only happens in our + # test suite. + unless(ref($self)) { + carp("\n$property not a class method (@_)"); + return; + } + + my $x = $self->{properties}; + return $x->{$property} unless @_; + + my $prop = $x->{$property}; + if ( defined $_[0] && !ref $_[0] ) { + if ( @_ == 1 ) { + return exists $prop->{$_[0]} ? $prop->{$_[0]} : undef; + } elsif ( @_ % 2 == 0 ) { + my %new = (%{ $prop }, @_); + local $_ = \%new; + $x->{$property} = \%new if $check->($self); + return $x->{$property}; + } else { + die "Unexpected arguments for property '$property'\n"; + } + } else { + die "Unexpected arguments for property '$property'\n" + if defined $_[0] && ref $_[0] ne 'HASH'; + local $_ = $_[0]; + $x->{$property} = shift if $check->($self); + } + }; +} +######################################################################## +sub _make_accessor { + my ($property, $p) = @_; + my $check = $p->{check} || sub { 1 }; + + return sub { + my $self = shift; + + # This is only here to deprecate the historic accident of calling + # properties as class methods - I suspect it only happens in our + # test suite. + unless(ref($self)) { + carp("\n$property not a class method (@_)"); + return; + } + + my $x = $self->{properties}; + return $x->{$property} unless @_; + local $_ = $_[0]; + $x->{$property} = shift if $check->($self); + return $x->{$property}; + }; +} +######################################################################## + +# Add the default properties. +__PACKAGE__->add_property(auto_configure_requires => 1); +__PACKAGE__->add_property(blib => 'blib'); +__PACKAGE__->add_property(build_class => 'Module::Build'); +__PACKAGE__->add_property(build_elements => [qw(PL support pm xs share_dir pod script)]); +__PACKAGE__->add_property(build_script => 'Build'); +__PACKAGE__->add_property(build_bat => 0); +__PACKAGE__->add_property(bundle_inc => []); +__PACKAGE__->add_property(bundle_inc_preload => []); +__PACKAGE__->add_property(config_dir => '_build'); +__PACKAGE__->add_property(dynamic_config => 1); +__PACKAGE__->add_property(include_dirs => []); +__PACKAGE__->add_property(license => 'unknown'); +__PACKAGE__->add_property(metafile => 'META.yml'); +__PACKAGE__->add_property(mymetafile => 'MYMETA.yml'); +__PACKAGE__->add_property(metafile2 => 'META.json'); +__PACKAGE__->add_property(mymetafile2 => 'MYMETA.json'); +__PACKAGE__->add_property(recurse_into => []); +__PACKAGE__->add_property(use_rcfile => 1); +__PACKAGE__->add_property(create_packlist => 1); +__PACKAGE__->add_property(allow_mb_mismatch => 0); +__PACKAGE__->add_property(config => undef); +__PACKAGE__->add_property(test_file_exts => ['.t']); +__PACKAGE__->add_property(use_tap_harness => 0); +__PACKAGE__->add_property(cpan_client => 'cpan'); +__PACKAGE__->add_property(tap_harness_args => {}); +__PACKAGE__->add_property(pureperl_only => 0); +__PACKAGE__->add_property(allow_pureperl => 0); +__PACKAGE__->add_property( + 'installdirs', + default => 'site', + check => sub { + return 1 if /^(core|site|vendor)$/; + return shift->property_error( + $_ eq 'perl' + ? 'Perhaps you meant installdirs to be "core" rather than "perl"?' + : 'installdirs must be one of "core", "site", or "vendor"' + ); + return shift->property_error("Perhaps you meant 'core'?") if $_ eq 'perl'; + return 0; + }, +); + +{ + __PACKAGE__->add_property(html_css => ''); +} + +{ + my @prereq_action_types = qw(requires build_requires test_requires conflicts recommends); + foreach my $type (@prereq_action_types) { + __PACKAGE__->add_property($type => {}); + } + __PACKAGE__->add_property(prereq_action_types => \@prereq_action_types); +} + +__PACKAGE__->add_property($_ => {}) for qw( + get_options + install_base_relpaths + install_path + install_sets + meta_add + meta_merge + original_prefix + prefix_relpaths + configure_requires +); + +__PACKAGE__->add_property($_) for qw( + PL_files + autosplit + base_dir + bindoc_dirs + c_source + create_license + create_makefile_pl + create_readme + debugger + destdir + dist_abstract + dist_author + dist_name + dist_suffix + dist_version + dist_version_from + extra_compiler_flags + extra_linker_flags + has_config_data + install_base + libdoc_dirs + magic_number + mb_version + module_name + needs_compiler + orig_dir + perl + pm_files + pod_files + pollute + prefix + program_name + quiet + recursive_test_files + release_status + script_files + scripts + share_dir + sign + test_files + verbose + debug + xs_files + extra_manify_args +); + +sub config { + my $self = shift; + my $c = ref($self) ? $self->{config} : 'Module::Build::Config'; + return $c->all_config unless @_; + + my $key = shift; + return $c->get($key) unless @_; + + my $val = shift; + return $c->set($key => $val); +} + +sub mb_parents { + # Code borrowed from Class::ISA. + my @in_stack = (shift); + my %seen = ($in_stack[0] => 1); + + my ($current, @out); + while (@in_stack) { + next unless defined($current = shift @in_stack) + && $current->isa('Module::Build::Base'); + push @out, $current; + next if $current eq 'Module::Build::Base'; + no strict 'refs'; + unshift @in_stack, + map { + my $c = $_; # copy, to avoid being destructive + substr($c,0,2) = "main::" if substr($c,0,2) eq '::'; + # Canonize the :: -> main::, ::foo -> main::foo thing. + # Should I ever canonize the Foo'Bar = Foo::Bar thing? + $seen{$c}++ ? () : $c; + } @{"$current\::ISA"}; + + # I.e., if this class has any parents (at least, ones I've never seen + # before), push them, in order, onto the stack of classes I need to + # explore. + } + shift @out; + return @out; +} + +sub extra_linker_flags { shift->_list_accessor('extra_linker_flags', @_) } +sub extra_compiler_flags { shift->_list_accessor('extra_compiler_flags', @_) } + +sub _list_accessor { + (my $self, local $_) = (shift, shift); + my $p = $self->{properties}; + $p->{$_} = [@_] if @_; + $p->{$_} = [] unless exists $p->{$_}; + return ref($p->{$_}) ? $p->{$_} : [$p->{$_}]; +} + +# XXX Problem - if Module::Build is loaded from a different directory, +# it'll look for (and perhaps destroy/create) a _build directory. +sub subclass { + my ($pack, %opts) = @_; + + my $build_dir = '_build'; # XXX The _build directory is ostensibly settable by the user. Shouldn't hard-code here. + $pack->delete_filetree($build_dir) if -e $build_dir; + + die "Must provide 'code' or 'class' option to subclass()\n" + unless $opts{code} or $opts{class}; + + $opts{code} ||= ''; + $opts{class} ||= 'MyModuleBuilder'; + + my $filename = File::Spec->catfile($build_dir, 'lib', split '::', $opts{class}) . '.pm'; + my $filedir = File::Basename::dirname($filename); + $pack->log_verbose("Creating custom builder $filename in $filedir\n"); + + File::Path::mkpath($filedir); + die "Can't create directory $filedir: $!" unless -d $filedir; + + open(my $fh, '>', $filename) or die "Can't create $filename: $!"; + print $fh <<EOF; +package $opts{class}; +use $pack; +\@ISA = qw($pack); +$opts{code} +1; +EOF + close $fh; + + unshift @INC, File::Spec->catdir(File::Spec->rel2abs($build_dir), 'lib'); + eval "use $opts{class}"; + die $@ if $@; + + return $opts{class}; +} + +sub _guess_module_name { + my $self = shift; + my $p = $self->{properties}; + return if $p->{module_name}; + if ( $p->{dist_version_from} && -e $p->{dist_version_from} ) { + my $mi = Module::Metadata->new_from_file($self->dist_version_from); + $p->{module_name} = $mi->name; + } + else { + my $mod_path = my $mod_name = $p->{dist_name}; + $mod_name =~ s{-}{::}g; + $mod_path =~ s{-}{/}g; + $mod_path .= ".pm"; + if ( -e $mod_path || -e "lib/$mod_path" ) { + $p->{module_name} = $mod_name; + } + else { + $self->log_warn( << 'END_WARN' ); +No 'module_name' was provided and it could not be inferred +from other properties. This will prevent a packlist from +being written for this file. Please set either 'module_name' +or 'dist_version_from' in Build.PL. +END_WARN + } + } +} + +sub dist_name { + my $self = shift; + my $p = $self->{properties}; + my $me = 'dist_name'; + return $p->{$me} if defined $p->{$me}; + + die "Can't determine distribution name, must supply either 'dist_name' or 'module_name' parameter" + unless $self->module_name; + + ($p->{$me} = $self->module_name) =~ s/::/-/g; + + return $p->{$me}; +} + +sub release_status { + my ($self) = @_; + my $me = 'release_status'; + my $p = $self->{properties}; + + if ( ! defined $p->{$me} ) { + $p->{$me} = $self->_is_dev_version ? 'testing' : 'stable'; + } + + unless ( $p->{$me} =~ qr/\A(?:stable|testing|unstable)\z/ ) { + die "Illegal value '$p->{$me}' for $me\n"; + } + + if ( $p->{$me} eq 'stable' && $self->_is_dev_version ) { + my $version = $self->dist_version; + die "Illegal value '$p->{$me}' with version '$version'\n"; + } + return $p->{$me}; +} + +sub dist_suffix { + my ($self) = @_; + my $p = $self->{properties}; + my $me = 'dist_suffix'; + + return $p->{$me} if defined $p->{$me}; + + if ( $self->release_status eq 'stable' ) { + $p->{$me} = ""; + } + else { + # non-stable release but non-dev version number needs '-TRIAL' appended + $p->{$me} = $self->_is_dev_version ? "" : "TRIAL" ; + } + + return $p->{$me}; +} + +sub dist_version_from { + my ($self) = @_; + my $p = $self->{properties}; + my $me = 'dist_version_from'; + + if ($self->module_name) { + $p->{$me} ||= + join( '/', 'lib', split(/::/, $self->module_name) ) . '.pm'; + } + return $p->{$me} || undef; +} + +sub dist_version { + my ($self) = @_; + my $p = $self->{properties}; + my $me = 'dist_version'; + + return $p->{$me} if defined $p->{$me}; + + if ( my $dist_version_from = $self->dist_version_from ) { + my $version_from = File::Spec->catfile( split( qr{/}, $dist_version_from ) ); + my $pm_info = Module::Metadata->new_from_file( $version_from ) + or die "Can't find file $version_from to determine version"; + #$p->{$me} is undef here + $p->{$me} = $self->normalize_version( $pm_info->version() ); + unless (defined $p->{$me}) { + die "Can't determine distribution version from $version_from"; + } + } + + die ("Can't determine distribution version, must supply either 'dist_version',\n". + "'dist_version_from', or 'module_name' parameter") + unless defined $p->{$me}; + + return $p->{$me}; +} + +sub _is_dev_version { + my ($self) = @_; + my $dist_version = $self->dist_version; + my $version_obj = eval { version->new( $dist_version ) }; + # assume it's normal if the version string is fatal -- in this case + # the author might be doing something weird so should play along and + # assume they'll specify all necessary behavior + return $@ ? 0 : $version_obj->is_alpha; +} + +sub dist_author { shift->_pod_parse('author') } +sub dist_abstract { shift->_pod_parse('abstract') } + +sub _pod_parse { + my ($self, $part) = @_; + my $p = $self->{properties}; + my $member = "dist_$part"; + return $p->{$member} if defined $p->{$member}; + + my $docfile = $self->_main_docfile + or return; + open(my $fh, '<', $docfile) + or return; + + require Module::Build::PodParser; + my $parser = Module::Build::PodParser->new(fh => $fh); + my $method = "get_$part"; + return $p->{$member} = $parser->$method(); +} + +sub version_from_file { # Method provided for backwards compatibility + return Module::Metadata->new_from_file($_[1])->version(); +} + +sub find_module_by_name { # Method provided for backwards compatibility + return Module::Metadata->find_module_by_name(@_[1,2]); +} + +{ + # $unlink_list_for_pid{$$} = [ ... ] + my %unlink_list_for_pid; + + sub _unlink_on_exit { + my $self = shift; + for my $f ( @_ ) { + push @{$unlink_list_for_pid{$$}}, $f if -f $f; + } + return 1; + } + + END { + for my $f ( map glob($_), @{ $unlink_list_for_pid{$$} || [] } ) { + next unless -e $f; + File::Path::rmtree($f, 0, 0); + } + } +} + +sub add_to_cleanup { + my $self = shift; + my %files = map {$self->localize_file_path($_), 1} @_; + $self->{phash}{cleanup}->write(\%files); +} + +sub cleanup { + my $self = shift; + my $all = $self->{phash}{cleanup}->read; + return keys %$all; +} + +sub config_file { + my $self = shift; + return unless -d $self->config_dir; + return File::Spec->catfile($self->config_dir, @_); +} + +sub read_config { + my ($self) = @_; + + my $file = $self->config_file('build_params') + or die "Can't find 'build_params' in " . $self->config_dir; + open(my $fh, '<', $file) or die "Can't read '$file': $!"; + my $ref = eval do {local $/; <$fh>}; + die if $@; + close $fh; + my $c; + ($self->{args}, $c, $self->{properties}) = @$ref; + $self->{config} = Module::Build::Config->new(values => $c); +} + +sub has_config_data { + my $self = shift; + return scalar grep $self->{phash}{$_}->has_data(), qw(config_data features auto_features); +} + +sub _write_data { + my ($self, $filename, $data) = @_; + + my $file = $self->config_file($filename); + open(my $fh, '>', $file) or die "Can't create '$file': $!"; + unless (ref($data)) { # e.g. magicnum + print $fh $data; + return; + } + + print {$fh} Module::Build::Dumper->_data_dump($data); + close $fh; +} + +sub write_config { + my ($self) = @_; + + File::Path::mkpath($self->{properties}{config_dir}); + -d $self->{properties}{config_dir} or die "Can't mkdir $self->{properties}{config_dir}: $!"; + + my @items = @{ $self->prereq_action_types }; + $self->_write_data('prereqs', { map { $_, $self->$_() } @items }); + $self->_write_data('build_params', [$self->{args}, $self->{config}->values_set, $self->{properties}]); + + # Set a new magic number and write it to a file + $self->_write_data('magicnum', $self->magic_number(int rand 1_000_000)); + + $self->{phash}{$_}->write() foreach qw(notes cleanup features auto_features config_data runtime_params); +} + +{ + # packfile map -- keys are guts of regular expressions; If they match, + # values are module names corresponding to the packlist + my %packlist_map = ( + '^File::Spec' => 'Cwd', + '^Devel::AssertOS' => 'Devel::CheckOS', + ); + + sub _find_packlist { + my ($self, $inst, $mod) = @_; + my $lookup = $mod; + my $packlist = eval { $inst->packlist($lookup) }; + if ( ! $packlist ) { + # try from packlist_map + while ( my ($re, $new_mod) = each %packlist_map ) { + if ( $mod =~ qr/$re/ ) { + $lookup = $new_mod; + $packlist = eval { $inst->packlist($lookup) }; + last; + } + } + } + return $packlist ? $lookup : undef; + } + + sub set_bundle_inc { + my $self = shift; + + my $bundle_inc = $self->{properties}{bundle_inc}; + my $bundle_inc_preload = $self->{properties}{bundle_inc_preload}; + # We're in author mode if inc::latest is loaded, but not from cwd + return unless inc::latest->can('loaded_modules'); + require ExtUtils::Installed; + # ExtUtils::Installed is buggy about finding additions to default @INC + my $inst = eval { ExtUtils::Installed->new(extra_libs => [@INC]) }; + if ($@) { + $self->log_warn( << "EUI_ERROR" ); +Bundling in inc/ is disabled because ExtUtils::Installed could not +create a list of your installed modules. Here is the error: +$@ +EUI_ERROR + return; + } + my @bundle_list = map { [ $_, 0 ] } inc::latest->loaded_modules; + + # XXX TODO: Need to get ordering of prerequisites correct so they are + # are loaded in the right order. Use an actual tree?! + + while( @bundle_list ) { + my ($mod, $prereq) = @{ shift @bundle_list }; + + # XXX TODO: Append prereqs to list + # skip if core or already in bundle or preload lists + # push @bundle_list, [$_, 1] for prereqs() + + # Locate packlist for bundling + my $lookup = $self->_find_packlist($inst,$mod); + if ( ! $lookup ) { + # XXX Really needs a more helpful error message here + die << "NO_PACKLIST"; +Could not find a packlist for '$mod'. If it's a core module, try +force installing it from CPAN. +NO_PACKLIST + } + else { + push @{ $prereq ? $bundle_inc_preload : $bundle_inc }, $lookup; + } + } + } # sub check_bundling +} + +sub check_autofeatures { + my ($self) = @_; + my $features = $self->auto_features; + + return 1 unless %$features; + + # TODO refactor into ::Util + my $longest = sub { + my @str = @_ or croak("no strings given"); + + my @len = map({length($_)} @str); + my $max = 0; + my $longest; + for my $i (0..$#len) { + ($max, $longest) = ($len[$i], $str[$i]) if($len[$i] > $max); + } + return($longest); + }; + my $max_name_len = length($longest->(keys %$features)); + + my ($num_disabled, $log_text) = (0, "\nChecking optional features...\n"); + for my $name ( sort keys %$features ) { + $log_text .= $self->_feature_deps_msg($name, $max_name_len); + } + + $num_disabled = () = $log_text =~ /disabled/g; + + # warn user if features disabled + if ( $num_disabled ) { + $self->log_warn( $log_text ); + return 0; + } + else { + $self->log_verbose( $log_text ); + return 1; + } +} + +sub _feature_deps_msg { + my ($self, $name, $max_name_len) = @_; + $max_name_len ||= length $name; + my $features = $self->auto_features; + my $info = $features->{$name}; + my $feature_text = "$name" . '.' x ($max_name_len - length($name) + 4); + + my ($log_text, $disabled) = ('',''); + if ( my $failures = $self->prereq_failures($info) ) { + $disabled = grep( /^(?:\w+_)?(?:requires|conflicts)$/, + keys %$failures ) ? 1 : 0; + $feature_text .= $disabled ? "disabled\n" : "enabled\n"; + + for my $type ( @{ $self->prereq_action_types } ) { + next unless exists $failures->{$type}; + $feature_text .= " $type:\n"; + my $prereqs = $failures->{$type}; + for my $module ( sort keys %$prereqs ) { + my $status = $prereqs->{$module}; + my $required = + ($type =~ /^(?:\w+_)?(?:requires|conflicts)$/) ? 1 : 0; + my $prefix = ($required) ? '!' : '*'; + $feature_text .= " $prefix $status->{message}\n"; + } + } + } else { + $feature_text .= "enabled\n"; + } + $log_text .= $feature_text if $disabled || $self->verbose; + return $log_text; +} + +# Automatically detect configure_requires prereqs +sub auto_config_requires { + my ($self) = @_; + my $p = $self->{properties}; + + # add current Module::Build to configure_requires if there + # isn't one already specified (but not ourself, so we're not circular) + if ( $self->dist_name ne 'Module-Build' + && $self->auto_configure_requires + && ! exists $p->{configure_requires}{'Module::Build'} + ) { + (my $ver = $VERSION) =~ s/^(\d+\.\d\d).*$/$1/; # last major release only + $self->log_warn(<<EOM); +Module::Build was not found in configure_requires! Adding it now +automatically as: configure_requires => { 'Module::Build' => $ver } +EOM + $self->_add_prereq('configure_requires', 'Module::Build', $ver); + } + + # if we're in author mode, add inc::latest modules to + # configure_requires if not already set. If we're not in author mode + # then configure_requires will have been satisfied, or we'll just + # live with what we've bundled + if ( inc::latest->can('loaded_module') ) { + for my $mod ( inc::latest->loaded_modules ) { + next if exists $p->{configure_requires}{$mod}; + $self->_add_prereq('configure_requires', $mod, $mod->VERSION); + } + } + + return; +} + +# Automatically detect and add prerequisites based on configuration +sub auto_require { + my ($self) = @_; + my $p = $self->{properties}; + + # If needs_compiler is not explicitly set, automatically set it + # If set, we need ExtUtils::CBuilder (and a compiler) + my $xs_files = $self->find_xs_files; + if ( ! defined $p->{needs_compiler} ) { + $self->needs_compiler( keys %$xs_files || defined $self->c_source ); + } + if ($self->needs_compiler) { + $self->_add_prereq('build_requires', 'ExtUtils::CBuilder', 0); + if ( ! $self->have_c_compiler ) { + $self->log_warn(<<'EOM'); +Warning: ExtUtils::CBuilder not installed or no compiler detected +Proceeding with configuration, but compilation may fail during Build + +EOM + } + } + + # If using share_dir, require File::ShareDir + if ( $self->share_dir ) { + $self->_add_prereq( 'requires', 'File::ShareDir', '1.00' ); + } + + return; +} + +sub _add_prereq { + my ($self, $type, $module, $version) = @_; + my $p = $self->{properties}; + $version = 0 unless defined $version; + if ( exists $p->{$type}{$module} ) { + return if $self->compare_versions( $version, '<=', $p->{$type}{$module} ); + } + $self->log_verbose("Adding to $type\: $module => $version\n"); + $p->{$type}{$module} = $version; + return 1; +} + +sub prereq_failures { + my ($self, $info) = @_; + + my @types = @{ $self->prereq_action_types }; + $info ||= {map {$_, $self->$_()} @types}; + + my $out; + + foreach my $type (@types) { + my $prereqs = $info->{$type}; + for my $modname ( keys %$prereqs ) { + my $spec = $prereqs->{$modname}; + my $status = $self->check_installed_status($modname, $spec); + + if ($type =~ /^(?:\w+_)?conflicts$/) { + next if !$status->{ok}; + $status->{conflicts} = delete $status->{need}; + $status->{message} = "$modname ($status->{have}) conflicts with this distribution"; + + } elsif ($type =~ /^(?:\w+_)?recommends$/) { + next if $status->{ok}; + $status->{message} = (!ref($status->{have}) && $status->{have} eq '<none>' + ? "$modname is not installed" + : "$modname ($status->{have}) is installed, but we prefer to have $spec"); + } else { + next if $status->{ok}; + } + + $out->{$type}{$modname} = $status; + } + } + + return $out; +} + +# returns a hash of defined prerequisites; i.e. only prereq types with values +sub _enum_prereqs { + my $self = shift; + my %prereqs; + foreach my $type ( @{ $self->prereq_action_types } ) { + if ( $self->can( $type ) ) { + my $prereq = $self->$type() || {}; + $prereqs{$type} = $prereq if %$prereq; + } + } + return \%prereqs; +} + +sub check_prereq { + my $self = shift; + + # Check to see if there are any prereqs to check + my $info = $self->_enum_prereqs; + return 1 unless $info; + + my $log_text = "Checking prerequisites...\n"; + + my $failures = $self->prereq_failures($info); + + if ( $failures ) { + $self->log_warn($log_text); + for my $type ( @{ $self->prereq_action_types } ) { + my $prereqs = $failures->{$type}; + $self->log_warn(" ${type}:\n") if keys %$prereqs; + for my $module ( sort keys %$prereqs ) { + my $status = $prereqs->{$module}; + my $prefix = ($type =~ /^(?:\w+_)?recommends$/) ? "* " : "! "; + $self->log_warn(" $prefix $status->{message}\n"); + } + } + return 0; + } else { + $self->log_verbose($log_text . "Looks good\n\n"); + return 1; + } +} + +sub perl_version { + my ($self) = @_; + # Check the current perl interpreter + # It's much more convenient to use $] here than $^V, but 'man + # perlvar' says I'm not supposed to. Bloody tyrant. + return $^V ? $self->perl_version_to_float(sprintf "%vd", $^V) : $]; +} + +sub perl_version_to_float { + my ($self, $version) = @_; + return $version if grep( /\./, $version ) < 2; + $version =~ s/\./../; + $version =~ s/\.(\d+)/sprintf '%03d', $1/eg; + return $version; +} + +sub _parse_conditions { + my ($self, $spec) = @_; + + return ">= 0" if not defined $spec; + if ($spec =~ /^\s*([\w.]+)\s*$/) { # A plain number, maybe with dots, letters, and underscores + return (">= $spec"); + } else { + return split /\s*,\s*/, $spec; + } +} + +sub try_require { + my ($self, $modname, $spec) = @_; + my $status = $self->check_installed_status($modname, defined($spec) ? $spec : 0); + return unless $status->{ok}; + my $path = $modname; + $path =~ s{::}{/}g; + $path .= ".pm"; + if ( defined $INC{$path} ) { + return 1; + } + elsif ( exists $INC{$path} ) { # failed before, don't try again + return; + } + else { + return eval "require $modname"; + } +} + +sub check_installed_status { + my ($self, $modname, $spec) = @_; + my %status = (need => $spec); + + if ($modname eq 'perl') { + $status{have} = $self->perl_version; + + } elsif (eval { no strict; $status{have} = ${"${modname}::VERSION"} }) { + # Don't try to load if it's already loaded + + } else { + my $pm_info = Module::Metadata->new_from_module( $modname ); + unless (defined( $pm_info )) { + @status{ qw(have message) } = ('<none>', "$modname is not installed"); + return \%status; + } + + $status{have} = eval { $pm_info->version() }; + if ($spec and !defined($status{have})) { + @status{ qw(have message) } = (undef, "Couldn't find a \$VERSION in prerequisite $modname"); + return \%status; + } + } + + my @conditions = $self->_parse_conditions($spec); + + foreach (@conditions) { + my ($op, $version) = /^\s* (<=?|>=?|==|!=) \s* ([\w.]+) \s*$/x + or die "Invalid prerequisite condition '$_' for $modname"; + + $version = $self->perl_version_to_float($version) + if $modname eq 'perl'; + + next if $op eq '>=' and !$version; # Module doesn't have to actually define a $VERSION + + unless ($self->compare_versions( $status{have}, $op, $version )) { + $status{message} = "$modname ($status{have}) is installed, but we need version $op $version"; + return \%status; + } + } + + $status{ok} = 1; + return \%status; +} + +sub compare_versions { + my $self = shift; + my ($v1, $op, $v2) = @_; + $v1 = version->new($v1) + unless eval { $v1->isa('version') }; + + my $eval_str = "\$v1 $op \$v2"; + my $result = eval $eval_str; + $self->log_warn("error comparing versions: '$eval_str' $@") if $@; + + return $result; +} + +# I wish I could set $! to a string, but I can't, so I use $@ +sub check_installed_version { + my ($self, $modname, $spec) = @_; + + my $status = $self->check_installed_status($modname, $spec); + + if ($status->{ok}) { + return $status->{have} if $status->{have} and "$status->{have}" ne '<none>'; + return '0 but true'; + } + + $@ = $status->{message}; + return 0; +} + +sub make_executable { + # Perl's chmod() is mapped to useful things on various non-Unix + # platforms, so we use it in the base class even though it looks + # Unixish. + + my $self = shift; + foreach (@_) { + my $current_mode = (stat $_)[2]; + chmod $current_mode | oct(111), $_; + } +} + +sub is_executable { + # We assume this does the right thing on generic platforms, though + # we do some other more specific stuff on Unixish platforms. + my ($self, $file) = @_; + return -x $file; +} + +sub _startperl { shift()->config('startperl') } + +# Return any directories in @INC which are not in the default @INC for +# this perl. For example, stuff passed in with -I or loaded with "use lib". +sub _added_to_INC { + my $self = shift; + + my %seen; + $seen{$_}++ foreach $self->_default_INC; + return grep !$seen{$_}++, @INC; +} + +# Determine the default @INC for this Perl +{ + my @default_inc; # Memoize + sub _default_INC { + my $self = shift; + return @default_inc if @default_inc; + + local $ENV{PERL5LIB}; # this is not considered part of the default. + + my $perl = ref($self) ? $self->perl : $self->find_perl_interpreter; + + my @inc = $self->_backticks($perl, '-le', 'print for @INC'); + chomp @inc; + + return @default_inc = @inc; + } +} + +sub print_build_script { + my ($self, $fh) = @_; + + my $build_package = $self->build_class; + + my $closedata=""; + + my $config_requires; + if ( -f $self->metafile ) { + my $meta = eval { $self->read_metafile( $self->metafile ) }; + $config_requires = $meta && $meta->{prereqs}{configure}{requires}{'Module::Build'}; + } + $config_requires ||= 0; + + my %q = map {$_, $self->$_()} qw(config_dir base_dir); + + $q{base_dir} = Win32::GetShortPathName($q{base_dir}) if $self->is_windowsish; + + $q{magic_numfile} = $self->config_file('magicnum'); + + my @myINC = $self->_added_to_INC; + for (@myINC, values %q) { + $_ = File::Spec->canonpath( $_ ) unless $self->is_vmsish; + s/([\\\'])/\\$1/g; + } + + my $quoted_INC = join ",\n", map " '$_'", @myINC; + my $shebang = $self->_startperl; + my $magic_number = $self->magic_number; + + print $fh <<EOF; +$shebang + +use strict; +use Cwd; +use File::Basename; +use File::Spec; + +sub magic_number_matches { + return 0 unless -e '$q{magic_numfile}'; + my \$FH; + open \$FH, '<','$q{magic_numfile}' or return 0; + my \$filenum = <\$FH>; + close \$FH; + return \$filenum == $magic_number; +} + +my \$progname; +my \$orig_dir; +BEGIN { + \$^W = 1; # Use warnings + \$progname = basename(\$0); + \$orig_dir = Cwd::cwd(); + my \$base_dir = '$q{base_dir}'; + if (!magic_number_matches()) { + unless (chdir(\$base_dir)) { + die ("Couldn't chdir(\$base_dir), aborting\\n"); + } + unless (magic_number_matches()) { + die ("Configuration seems to be out of date, please re-run 'perl Build.PL' again.\\n"); + } + } + unshift \@INC, + ( +$quoted_INC + ); +} + +close(*DATA) unless eof(*DATA); # ensure no open handles to this script + +use $build_package; +Module::Build->VERSION(q{$config_requires}); + +# Some platforms have problems setting \$^X in shebang contexts, fix it up here +\$^X = Module::Build->find_perl_interpreter; + +if (-e 'Build.PL' and not $build_package->up_to_date('Build.PL', \$progname)) { + warn "Warning: Build.PL has been altered. You may need to run 'perl Build.PL' again.\\n"; +} + +# This should have just enough arguments to be able to bootstrap the rest. +my \$build = $build_package->resume ( + properties => { + config_dir => '$q{config_dir}', + orig_dir => \$orig_dir, + }, +); + +\$build->dispatch; +EOF +} + +sub create_mymeta { + my ($self) = @_; + + my ($meta_obj, $mymeta); + my @metafiles = ( $self->metafile2, $self->metafile, ); + my @mymetafiles = ( $self->mymetafile2, $self->mymetafile, ); + + # cleanup old MYMETA + for my $f ( @mymetafiles ) { + if ( $self->delete_filetree($f) ) { + $self->log_verbose("Removed previous '$f'\n"); + } + } + + # Try loading META.json or META.yml + if ( $self->try_require("CPAN::Meta", "2.110420") ) { + for my $file ( @metafiles ) { + next unless -f $file; + $meta_obj = eval { CPAN::Meta->load_file($file, { lazy_validation => 0 }) }; + last if $meta_obj; + } + } + + # maybe get a copy in spec v2 format (regardless of original source) + + my $mymeta_obj; + if ($meta_obj) { + # if we have metadata, just update it + my %updated = ( + %{ $meta_obj->as_struct({ version => 2.0 }) }, + prereqs => $self->_normalize_prereqs, + dynamic_config => 0, + generated_by => "Module::Build version $Module::Build::VERSION", + ); + $mymeta_obj = CPAN::Meta->new( \%updated, { lazy_validation => 0 } ); + } + else { + $mymeta_obj = $self->_get_meta_object(quiet => 0, dynamic => 0, fatal => 1, auto => 0); + } + + my @created = $self->_write_meta_files( $mymeta_obj, 'MYMETA' ); + + $self->log_warn("Could not create MYMETA files\n") + unless @created; + + return 1; +} + +sub create_build_script { + my ($self) = @_; + + $self->write_config; + $self->create_mymeta; + + # Create Build + my ($build_script, $dist_name, $dist_version) + = map $self->$_(), qw(build_script dist_name dist_version); + + if ( $self->delete_filetree($build_script) ) { + $self->log_verbose("Removed previous script '$build_script'\n"); + } + + $self->log_info("Creating new '$build_script' script for ", + "'$dist_name' version '$dist_version'\n"); + open(my $fh, '>', $build_script) or die "Can't create '$build_script': $!"; + $self->print_build_script($fh); + close $fh; + + $self->make_executable($build_script); + + return 1; +} + +sub check_manifest { + my $self = shift; + return unless -e 'MANIFEST'; + + # Stolen nearly verbatim from MakeMaker. But ExtUtils::Manifest + # could easily be re-written into a modern Perl dialect. + + require ExtUtils::Manifest; # ExtUtils::Manifest is not warnings clean. + local ($^W, $ExtUtils::Manifest::Quiet) = (0,1); + + $self->log_verbose("Checking whether your kit is complete...\n"); + if (my @missed = ExtUtils::Manifest::manicheck()) { + $self->log_warn("WARNING: the following files are missing in your kit:\n", + "\t", join("\n\t", @missed), "\n", + "Please inform the author.\n\n"); + } else { + $self->log_verbose("Looks good\n\n"); + } +} + +sub dispatch { + my $self = shift; + local $self->{_completed_actions} = {}; + + if (@_) { + my ($action, %p) = @_; + my $args = $p{args} ? delete($p{args}) : {}; + + local $self->{invoked_action} = $action; + local $self->{args} = {%{$self->{args}}, %$args}; + local $self->{properties} = {%{$self->{properties}}, %p}; + return $self->_call_action($action); + } + + die "No build action specified" unless $self->{action}; + local $self->{invoked_action} = $self->{action}; + $self->_call_action($self->{action}); +} + +sub _call_action { + my ($self, $action) = @_; + + return if $self->{_completed_actions}{$action}++; + + local $self->{action} = $action; + my $method = $self->can_action( $action ); + die "No action '$action' defined, try running the 'help' action.\n" unless $method; + $self->log_debug("Starting ACTION_$action\n"); + my $rc = $self->$method(); + $self->log_debug("Finished ACTION_$action\n"); + return $rc; +} + +sub can_action { + my ($self, $action) = @_; + return $self->can( "ACTION_$action" ); +} + +# cuts the user-specified options out of the command-line args +sub cull_options { + my $self = shift; + my (@argv) = @_; + + # XXX is it even valid to call this as a class method? + return({}, @argv) unless(ref($self)); # no object + + my $specs = $self->get_options; + return({}, @argv) unless($specs and %$specs); # no user options + + require Getopt::Long; + # XXX Should we let Getopt::Long handle M::B's options? That would + # be easy-ish to add to @specs right here, but wouldn't handle options + # passed without "--" as M::B currently allows. We might be able to + # get around this by setting the "prefix_pattern" Configure option. + my @specs; + my $args = {}; + # Construct the specifications for GetOptions. + while (my ($k, $v) = each %$specs) { + # Throw an error if specs conflict with our own. + die "Option specification '$k' conflicts with a " . ref $self + . " option of the same name" + if $self->valid_property($k); + push @specs, $k . (defined $v->{type} ? $v->{type} : ''); + push @specs, $v->{store} if exists $v->{store}; + $args->{$k} = $v->{default} if exists $v->{default}; + } + + local @ARGV = @argv; # No other way to dupe Getopt::Long + + # Get the options values and return them. + # XXX Add option to allow users to set options? + if ( @specs ) { + Getopt::Long::Configure('pass_through'); + Getopt::Long::GetOptions($args, @specs); + } + + return $args, @ARGV; +} + +sub unparse_args { + my ($self, $args) = @_; + my @out; + while (my ($k, $v) = each %$args) { + push @out, (ref $v eq 'HASH' ? map {+"--$k", "$_=$v->{$_}"} keys %$v : + ref $v eq 'ARRAY' ? map {+"--$k", $_} @$v : + ("--$k", $v)); + } + return @out; +} + +sub args { + my $self = shift; + return wantarray ? %{ $self->{args} } : $self->{args} unless @_; + my $key = shift; + $self->{args}{$key} = shift if @_; + return $self->{args}{$key}; +} + +# allows select parameters (with underscores) to be spoken with dashes +# when used as command-line options +sub _translate_option { + my $self = shift; + my $opt = shift; + + (my $tr_opt = $opt) =~ tr/-/_/; + + return $tr_opt if grep $tr_opt =~ /^(?:no_?)?$_$/, qw( + create_license + create_makefile_pl + create_readme + extra_compiler_flags + extra_linker_flags + install_base + install_path + meta_add + meta_merge + test_files + use_rcfile + use_tap_harness + tap_harness_args + cpan_client + pureperl_only + allow_pureperl + ); # normalize only selected option names + + return $opt; +} + +my %singular_argument = map { ($_ => 1) } qw/install_base prefix destdir installdirs verbose quiet uninst debug sign/; + +sub _read_arg { + my ($self, $args, $key, $val) = @_; + + $key = $self->_translate_option($key); + + if ( exists $args->{$key} and not $singular_argument{$key} ) { + $args->{$key} = [ $args->{$key} ] unless ref $args->{$key}; + push @{$args->{$key}}, $val; + } else { + $args->{$key} = $val; + } +} + +# decide whether or not an option requires/has an operand +sub _optional_arg { + my $self = shift; + my $opt = shift; + my $argv = shift; + + $opt = $self->_translate_option($opt); + + my @bool_opts = qw( + build_bat + create_license + create_readme + pollute + quiet + uninst + use_rcfile + verbose + debug + sign + use_tap_harness + pureperl_only + allow_pureperl + ); + + # inverted boolean options; eg --noverbose or --no-verbose + # converted to proper name & returned with false value (verbose, 0) + if ( grep $opt =~ /^no[-_]?$_$/, @bool_opts ) { + $opt =~ s/^no-?//; + return ($opt, 0); + } + + # non-boolean option; return option unchanged along with its argument + return ($opt, shift(@$argv)) unless grep $_ eq $opt, @bool_opts; + + # we're punting a bit here, if an option appears followed by a digit + # we take the digit as the argument for the option. If there is + # nothing that looks like a digit, we pretend the option is a flag + # that is being set and has no argument. + my $arg = 1; + $arg = shift(@$argv) if @$argv && $argv->[0] =~ /^\d+$/; + + return ($opt, $arg); +} + +sub read_args { + my $self = shift; + + (my $args, @_) = $self->cull_options(@_); + my %args = %$args; + + my $opt_re = qr/[\w\-]+/; + + my ($action, @argv); + while (@_) { + local $_ = shift; + if ( /^(?:--)?($opt_re)=(.*)$/ ) { + $self->_read_arg(\%args, $1, $2); + } elsif ( /^--($opt_re)$/ ) { + my($opt, $arg) = $self->_optional_arg($1, \@_); + $self->_read_arg(\%args, $opt, $arg); + } elsif ( /^($opt_re)$/ and !defined($action)) { + $action = $1; + } else { + push @argv, $_; + } + } + $args{ARGV} = \@argv; + + for ('extra_compiler_flags', 'extra_linker_flags') { + $args{$_} = [ $self->split_like_shell($args{$_}) ] if exists $args{$_}; + } + + # Convert to arrays + for ('include_dirs') { + $args{$_} = [ $args{$_} ] if exists $args{$_} && !ref $args{$_} + } + + # Hashify these parameters + for ($self->hash_properties, 'config') { + next unless exists $args{$_}; + my %hash; + $args{$_} ||= []; + $args{$_} = [ $args{$_} ] unless ref $args{$_}; + foreach my $arg ( @{$args{$_}} ) { + $arg =~ /($opt_re)=(.*)/ + or die "Malformed '$_' argument: '$arg' should be something like 'foo=bar'"; + $hash{$1} = $2; + } + $args{$_} = \%hash; + } + + # De-tilde-ify any path parameters + for my $key (qw(prefix install_base destdir)) { + next if !defined $args{$key}; + $args{$key} = $self->_detildefy($args{$key}); + } + + for my $key (qw(install_path)) { + next if !defined $args{$key}; + + for my $subkey (keys %{$args{$key}}) { + next if !defined $args{$key}{$subkey}; + my $subkey_ext = $self->_detildefy($args{$key}{$subkey}); + if ( $subkey eq 'html' ) { # translate for compatibility + $args{$key}{binhtml} = $subkey_ext; + $args{$key}{libhtml} = $subkey_ext; + } else { + $args{$key}{$subkey} = $subkey_ext; + } + } + } + + if ($args{makefile_env_macros}) { + require Module::Build::Compat; + %args = (%args, Module::Build::Compat->makefile_to_build_macros); + } + + return \%args, $action; +} + +# Default: do nothing. Overridden for Unix & Windows. +sub _detildefy {} + + +# merge Module::Build argument lists that have already been parsed +# by read_args(). Takes two references to option hashes and merges +# the contents, giving priority to the first. +sub _merge_arglist { + my( $self, $opts1, $opts2 ) = @_; + + $opts1 ||= {}; + $opts2 ||= {}; + my %new_opts = %$opts1; + while (my ($key, $val) = each %$opts2) { + if ( exists( $opts1->{$key} ) ) { + if ( ref( $val ) eq 'HASH' ) { + while (my ($k, $v) = each %$val) { + $new_opts{$key}{$k} = $v unless exists( $opts1->{$key}{$k} ); + } + } + } else { + $new_opts{$key} = $val + } + } + + return %new_opts; +} + +# Look for a home directory on various systems. +sub _home_dir { + my @home_dirs; + push( @home_dirs, $ENV{HOME} ) if $ENV{HOME}; + + push( @home_dirs, File::Spec->catpath($ENV{HOMEDRIVE}, $ENV{HOMEPATH}, '') ) + if $ENV{HOMEDRIVE} && $ENV{HOMEPATH}; + + my @other_home_envs = qw( USERPROFILE APPDATA WINDIR SYS$LOGIN ); + push( @home_dirs, map $ENV{$_}, grep $ENV{$_}, @other_home_envs ); + + my @real_home_dirs = grep -d, @home_dirs; + + return wantarray ? @real_home_dirs : shift( @real_home_dirs ); +} + +sub _find_user_config { + my $self = shift; + my $file = shift; + foreach my $dir ( $self->_home_dir ) { + my $path = File::Spec->catfile( $dir, $file ); + return $path if -e $path; + } + return undef; +} + +# read ~/.modulebuildrc returning global options '*' and +# options specific to the currently executing $action. +sub read_modulebuildrc { + my( $self, $action ) = @_; + + return () unless $self->use_rcfile; + + my $modulebuildrc; + if ( exists($ENV{MODULEBUILDRC}) && $ENV{MODULEBUILDRC} eq 'NONE' ) { + return (); + } elsif ( exists($ENV{MODULEBUILDRC}) && -e $ENV{MODULEBUILDRC} ) { + $modulebuildrc = $ENV{MODULEBUILDRC}; + } elsif ( exists($ENV{MODULEBUILDRC}) ) { + $self->log_warn("WARNING: Can't find resource file " . + "'$ENV{MODULEBUILDRC}' defined in environment.\n" . + "No options loaded\n"); + return (); + } else { + $modulebuildrc = $self->_find_user_config( '.modulebuildrc' ); + return () unless $modulebuildrc; + } + + open(my $fh, '<', $modulebuildrc ) + or die "Can't open $modulebuildrc: $!"; + + my %options; my $buffer = ''; + while (defined( my $line = <$fh> )) { + chomp( $line ); + $line =~ s/#.*$//; + next unless length( $line ); + + if ( $line =~ /^\S/ ) { + if ( $buffer ) { + my( $action, $options ) = split( /\s+/, $buffer, 2 ); + $options{$action} .= $options . ' '; + $buffer = ''; + } + $buffer = $line; + } else { + $buffer .= $line; + } + } + + if ( $buffer ) { # anything left in $buffer ? + my( $action, $options ) = split( /\s+/, $buffer, 2 ); + $options{$action} .= $options . ' '; # merge if more than one line + } + + my ($global_opts) = + $self->read_args( $self->split_like_shell( $options{'*'} || '' ) ); + + # let fakeinstall act like install if not provided + if ( $action eq 'fakeinstall' && ! exists $options{fakeinstall} ) { + $action = 'install'; + } + my ($action_opts) = + $self->read_args( $self->split_like_shell( $options{$action} || '' ) ); + + # specific $action options take priority over global options '*' + return $self->_merge_arglist( $action_opts, $global_opts ); +} + +# merge the relevant options in ~/.modulebuildrc into Module::Build's +# option list where they do not conflict with commandline options. +sub merge_modulebuildrc { + my( $self, $action, %cmdline_opts ) = @_; + my %rc_opts = $self->read_modulebuildrc( $action || $self->{action} || 'build' ); + my %new_opts = $self->_merge_arglist( \%cmdline_opts, \%rc_opts ); + $self->merge_args( $action, %new_opts ); +} + +sub merge_args { + my ($self, $action, %args) = @_; + $self->{action} = $action if defined $action; + + my %additive = map { $_ => 1 } $self->hash_properties; + + # Extract our 'properties' from $cmd_args, the rest are put in 'args'. + while (my ($key, $val) = each %args) { + $self->{phash}{runtime_params}->access( $key => $val ) + if $self->valid_property($key); + + if ($key eq 'config') { + $self->config($_ => $val->{$_}) foreach keys %$val; + } else { + my $add_to = $additive{$key} ? $self->{properties}{$key} : + $self->valid_property($key) ? $self->{properties} : + $self->{args} ; + + if ($additive{$key}) { + $add_to->{$_} = $val->{$_} foreach keys %$val; + } else { + $add_to->{$key} = $val; + } + } + } +} + +sub cull_args { + my $self = shift; + my @arg_list = @_; + unshift @arg_list, $self->split_like_shell($ENV{PERL_MB_OPT}) + if $ENV{PERL_MB_OPT}; + my ($args, $action) = $self->read_args(@arg_list); + $self->merge_args($action, %$args); + $self->merge_modulebuildrc( $action, %$args ); +} + +sub super_classes { + my ($self, $class, $seen) = @_; + $class ||= ref($self) || $self; + $seen ||= {}; + + no strict 'refs'; + my @super = grep {not $seen->{$_}++} $class, @{ $class . '::ISA' }; + return @super, map {$self->super_classes($_,$seen)} @super; +} + +sub known_actions { + my ($self) = @_; + + my %actions; + no strict 'refs'; + + foreach my $class ($self->super_classes) { + foreach ( keys %{ $class . '::' } ) { + $actions{$1}++ if /^ACTION_(\w+)/; + } + } + + return wantarray ? sort keys %actions : \%actions; +} + +sub get_action_docs { + my ($self, $action) = @_; + my $actions = $self->known_actions; + die "No known action '$action'" unless $actions->{$action}; + + my ($files_found, @docs) = (0); + foreach my $class ($self->super_classes) { + (my $file = $class) =~ s{::}{/}g; + # NOTE: silently skipping relative paths if any chdir() happened + $file = $INC{$file . '.pm'} or next; + open(my $fh, '<', $file) or next; + $files_found++; + + # Code below modified from /usr/bin/perldoc + + # Skip to ACTIONS section + local $_; + while (<$fh>) { + last if /^=head1 ACTIONS\s/; + } + + # Look for our action and determine the style + my $style; + while (<$fh>) { + last if /^=head1 /; + + # only item and head2 are allowed (3&4 are not in 5.005) + if(/^=(item|head2)\s+\Q$action\E\b/) { + $style = $1; + push @docs, $_; + last; + } + } + $style or next; # not here + + # and the content + if($style eq 'item') { + my ($found, $inlist) = (0, 0); + while (<$fh>) { + if (/^=(item|back)/) { + last unless $inlist; + } + push @docs, $_; + ++$inlist if /^=over/; + --$inlist if /^=back/; + } + } + else { # head2 style + # stop at anything equal or greater than the found level + while (<$fh>) { + last if(/^=(?:head[12]|cut)/); + push @docs, $_; + } + } + # TODO maybe disallow overriding just pod for an action + # TODO and possibly: @docs and last; + } + + unless ($files_found) { + $@ = "Couldn't find any documentation to search"; + return; + } + unless (@docs) { + $@ = "Couldn't find any docs for action '$action'"; + return; + } + + return join '', @docs; +} + +sub ACTION_prereq_report { + my $self = shift; + $self->log_info( $self->prereq_report ); +} + +sub ACTION_prereq_data { + my $self = shift; + $self->log_info( Module::Build::Dumper->_data_dump( $self->prereq_data ) ); +} + +sub prereq_data { + my $self = shift; + my @types = ('configure_requires', @{ $self->prereq_action_types } ); + my $info = { map { $_ => $self->$_() } grep { %{$self->$_()} } @types }; + return $info; +} + +sub prereq_report { + my $self = shift; + my $info = $self->prereq_data; + + my $output = ''; + foreach my $type (keys %$info) { + my $prereqs = $info->{$type}; + $output .= "\n$type:\n"; + my $mod_len = 2; + my $ver_len = 4; + my %mods; + while ( my ($modname, $spec) = each %$prereqs ) { + my $len = length $modname; + $mod_len = $len if $len > $mod_len; + $spec ||= '0'; + $len = length $spec; + $ver_len = $len if $len > $ver_len; + + my $mod = $self->check_installed_status($modname, $spec); + $mod->{name} = $modname; + $mod->{ok} ||= 0; + $mod->{ok} = ! $mod->{ok} if $type =~ /^(\w+_)?conflicts$/; + + $mods{lc $modname} = $mod; + } + + my $space = q{ } x ($mod_len - 3); + my $vspace = q{ } x ($ver_len - 3); + my $sline = q{-} x ($mod_len - 3); + my $vline = q{-} x ($ver_len - 3); + my $disposition = ($type =~ /^(\w+_)?conflicts$/) ? + 'Clash' : 'Need'; + $output .= + " Module $space $disposition $vspace Have\n". + " ------$sline+------$vline-+----------\n"; + + + for my $k (sort keys %mods) { + my $mod = $mods{$k}; + my $space = q{ } x ($mod_len - length $k); + my $vspace = q{ } x ($ver_len - length $mod->{need}); + my $f = $mod->{ok} ? ' ' : '!'; + $output .= + " $f $mod->{name} $space $mod->{need} $vspace ". + (defined($mod->{have}) ? $mod->{have} : "")."\n"; + } + } + return $output; +} + +sub ACTION_help { + my ($self) = @_; + my $actions = $self->known_actions; + + if (@{$self->{args}{ARGV}}) { + my $msg = eval {$self->get_action_docs($self->{args}{ARGV}[0], $actions)}; + print $@ ? "$@\n" : $msg; + return; + } + + print <<EOF; + + Usage: $0 <action> --arg1=value --arg2=value ... + Example: $0 test --verbose=1 + + Actions defined: +EOF + + print $self->_action_listing($actions); + + print "\nRun `Build help <action>` for details on an individual action.\n"; + print "See `perldoc Module::Build` for complete documentation.\n"; +} + +sub _action_listing { + my ($self, $actions) = @_; + + # Flow down columns, not across rows + my @actions = sort keys %$actions; + @actions = map $actions[($_ + ($_ % 2) * @actions) / 2], 0..$#actions; + + my $out = ''; + while (my ($one, $two) = splice @actions, 0, 2) { + $out .= sprintf(" %-12s %-12s\n", $one, $two||''); + } + $out =~ s{\s*$}{}mg; # remove trailing spaces + return $out; +} + +sub ACTION_retest { + my ($self) = @_; + + # Protect others against our @INC changes + local @INC = @INC; + + # Filter out nonsensical @INC entries - some versions of + # Test::Harness will really explode the number of entries here + @INC = grep {ref() || -d} @INC if @INC > 100; + + $self->do_tests; +} + +sub ACTION_testall { + my ($self) = @_; + + my @types; + for my $action (grep { $_ ne 'all' } $self->get_test_types) { + # XXX We can't just dispatch because we get multiple summaries but + # we'll need to dispatch to support custom setup/teardown in the + # action. To support that, we'll need to call something besides + # Harness::runtests() because we'll need to collect the results in + # parts, then run the summary. + push(@types, $action); + #$self->_call_action( "test$action" ); + } + $self->generic_test(types => ['default', @types]); +} + +sub get_test_types { + my ($self) = @_; + + my $t = $self->{properties}->{test_types}; + return ( defined $t ? ( keys %$t ) : () ); +} + + +sub ACTION_test { + my ($self) = @_; + $self->generic_test(type => 'default'); +} + +sub generic_test { + my $self = shift; + (@_ % 2) and croak('Odd number of elements in argument hash'); + my %args = @_; + + my $p = $self->{properties}; + + my @types = ( + (exists($args{type}) ? $args{type} : ()), + (exists($args{types}) ? @{$args{types}} : ()), + ); + @types or croak "need some types of tests to check"; + + my %test_types = ( + default => $p->{test_file_exts}, + (defined($p->{test_types}) ? %{$p->{test_types}} : ()), + ); + + for my $type (@types) { + croak "$type not defined in test_types!" + unless defined $test_types{ $type }; + } + + # we use local here because it ends up two method calls deep + local $p->{test_file_exts} = [ map { ref $_ ? @$_ : $_ } @test_types{@types} ]; + $self->depends_on('code'); + + # Protect others against our @INC changes + local @INC = @INC; + + # Make sure we test the module in blib/ + unshift @INC, (File::Spec->catdir($p->{base_dir}, $self->blib, 'lib'), + File::Spec->catdir($p->{base_dir}, $self->blib, 'arch')); + + # Filter out nonsensical @INC entries - some versions of + # Test::Harness will really explode the number of entries here + @INC = grep {ref() || -d} @INC if @INC > 100; + + $self->do_tests; +} + +# Test::Harness dies on failure but TAP::Harness does not, so we must +# die if running under TAP::Harness +sub do_tests { + my $self = shift; + + my $tests = $self->find_test_files; + + local $ENV{PERL_DL_NONLAZY} = 1; + + if(@$tests) { + my $args = $self->tap_harness_args; + if($self->use_tap_harness or ($args and %$args)) { + my $aggregate = $self->run_tap_harness($tests); + if ( $aggregate->has_errors ) { + die "Errors in testing. Cannot continue.\n"; + } + } + else { + $self->run_test_harness($tests); + } + } + else { + $self->log_info("No tests defined.\n"); + } + + $self->run_visual_script; +} + +sub run_tap_harness { + my ($self, $tests) = @_; + + require TAP::Harness; + + # TODO allow the test @INC to be set via our API? + + my $aggregate = TAP::Harness->new({ + lib => [@INC], + verbosity => $self->{properties}{verbose}, + switches => [ $self->harness_switches ], + %{ $self->tap_harness_args }, + })->runtests(@$tests); + + return $aggregate; +} + +sub run_test_harness { + my ($self, $tests) = @_; + require Test::Harness; + + local $Test::Harness::verbose = $self->verbose || 0; + local $Test::Harness::switches = join ' ', $self->harness_switches; + + Test::Harness::runtests(@$tests); +} + +sub run_visual_script { + my $self = shift; + # This will get run and the user will see the output. It doesn't + # emit Test::Harness-style output. + $self->run_perl_script('visual.pl', '-Mblib='.$self->blib) + if -e 'visual.pl'; +} + +sub harness_switches { + shift->{properties}{debugger} ? qw(-w -d) : (); +} + +sub test_files { + my $self = shift; + my $p = $self->{properties}; + if (@_) { + return $p->{test_files} = (@_ == 1 ? shift : [@_]); + } + return $self->find_test_files; +} + +sub expand_test_dir { + my ($self, $dir) = @_; + my $exts = $self->{properties}{test_file_exts}; + + return sort map { @{$self->rscan_dir($dir, qr{^[^.].*\Q$_\E$})} } @$exts + if $self->recursive_test_files; + + return sort map { glob File::Spec->catfile($dir, "*$_") } @$exts; +} + +sub ACTION_testdb { + my ($self) = @_; + local $self->{properties}{debugger} = 1; + $self->depends_on('test'); +} + +sub ACTION_testcover { + my ($self) = @_; + + unless (Module::Metadata->find_module_by_name('Devel::Cover')) { + warn("Cannot run testcover action unless Devel::Cover is installed.\n"); + return; + } + + $self->add_to_cleanup('coverage', 'cover_db'); + $self->depends_on('code'); + + # See whether any of the *.pm files have changed since last time + # testcover was run. If so, start over. + if (-e 'cover_db') { + my $pm_files = $self->rscan_dir + (File::Spec->catdir($self->blib, 'lib'), $self->file_qr('\.pm$') ); + my $cover_files = $self->rscan_dir('cover_db', sub {-f $_ and not /\.html$/}); + + $self->do_system(qw(cover -delete)) + unless $self->up_to_date($pm_files, $cover_files) + && $self->up_to_date($self->test_files, $cover_files); + } + + local $Test::Harness::switches = + local $Test::Harness::Switches = + local $ENV{HARNESS_PERL_SWITCHES} = "-MDevel::Cover"; + + $self->depends_on('test'); + $self->do_system('cover'); +} + +sub ACTION_code { + my ($self) = @_; + + # All installable stuff gets created in blib/ . + # Create blib/arch to keep blib.pm happy + my $blib = $self->blib; + $self->add_to_cleanup($blib); + File::Path::mkpath( File::Spec->catdir($blib, 'arch') ); + + if (my $split = $self->autosplit) { + $self->autosplit_file($_, $blib) for ref($split) ? @$split : ($split); + } + + foreach my $element (@{$self->build_elements}) { + my $method = "process_${element}_files"; + $method = "process_files_by_extension" unless $self->can($method); + $self->$method($element); + } + + $self->depends_on('config_data'); +} + +sub ACTION_build { + my $self = shift; + $self->log_info("Building " . $self->dist_name . "\n"); + $self->depends_on('code'); + $self->depends_on('docs'); +} + +sub process_files_by_extension { + my ($self, $ext) = @_; + + my $method = "find_${ext}_files"; + my $files = $self->can($method) ? $self->$method() : $self->_find_file_by_type($ext, 'lib'); + + while (my ($file, $dest) = each %$files) { + $self->copy_if_modified(from => $file, to => File::Spec->catfile($self->blib, $dest) ); + } +} + +sub process_support_files { + my $self = shift; + my $p = $self->{properties}; + return unless $p->{c_source}; + + my $files; + if (ref($p->{c_source}) eq "ARRAY") { + push @{$p->{include_dirs}}, @{$p->{c_source}}; + for my $path (@{$p->{c_source}}) { + push @$files, @{ $self->rscan_dir($path, $self->file_qr('\.c(c|p|pp|xx|\+\+)?$')) }; + } + } else { + push @{$p->{include_dirs}}, $p->{c_source}; + $files = $self->rscan_dir($p->{c_source}, $self->file_qr('\.c(c|p|pp|xx|\+\+)?$')); + } + + foreach my $file (@$files) { + push @{$p->{objects}}, $self->compile_c($file); + } +} + +sub process_share_dir_files { + my $self = shift; + my $files = $self->_find_share_dir_files; + return unless $files; + + # root for all File::ShareDir paths + my $share_prefix = File::Spec->catdir($self->blib, qw/lib auto share/); + + # copy all share files to blib + while (my ($file, $dest) = each %$files) { + $self->copy_if_modified( + from => $file, to => File::Spec->catfile( $share_prefix, $dest ) + ); + } +} + +sub _find_share_dir_files { + my $self = shift; + my $share_dir = $self->share_dir; + return unless $share_dir; + + my @file_map; + if ( $share_dir->{dist} ) { + my $prefix = "dist/".$self->dist_name; + push @file_map, $self->_share_dir_map( $prefix, $share_dir->{dist} ); + } + + if ( $share_dir->{module} ) { + for my $mod ( keys %{ $share_dir->{module} } ) { + (my $altmod = $mod) =~ s{::}{-}g; + my $prefix = "module/$altmod"; + push @file_map, $self->_share_dir_map($prefix, $share_dir->{module}{$mod}); + } + } + + return { @file_map }; +} + +sub _share_dir_map { + my ($self, $prefix, $list) = @_; + my %files; + for my $dir ( @$list ) { + for my $f ( @{ $self->rscan_dir( $dir, sub {-f} )} ) { + $f =~ s{\A.*?\Q$dir\E/}{}; + $files{"$dir/$f"} = "$prefix/$f"; + } + } + return %files; +} + +sub process_PL_files { + my ($self) = @_; + my $files = $self->find_PL_files; + + while (my ($file, $to) = each %$files) { + unless ($self->up_to_date( $file, $to )) { + $self->run_perl_script($file, [], [@$to]) or die "$file failed"; + $self->add_to_cleanup(@$to); + } + } +} + +sub process_xs_files { + my $self = shift; + return if $self->pureperl_only && $self->allow_pureperl; + my $files = $self->find_xs_files; + croak 'Can\'t build xs files under --pureperl-only' if %$files && $self->pureperl_only; + while (my ($from, $to) = each %$files) { + unless ($from eq $to) { + $self->add_to_cleanup($to); + $self->copy_if_modified( from => $from, to => $to ); + } + $self->process_xs($to); + } +} + +sub process_pod_files { shift()->process_files_by_extension(shift()) } +sub process_pm_files { shift()->process_files_by_extension(shift()) } + +sub process_script_files { + my $self = shift; + my $files = $self->find_script_files; + return unless keys %$files; + + my $script_dir = File::Spec->catdir($self->blib, 'script'); + File::Path::mkpath( $script_dir ); + + foreach my $file (keys %$files) { + my $result = $self->copy_if_modified($file, $script_dir, 'flatten') or next; + $self->fix_shebang_line($result) unless $self->is_vmsish; + $self->make_executable($result); + } +} + +sub find_PL_files { + my $self = shift; + if (my $files = $self->{properties}{PL_files}) { + # 'PL_files' is given as a Unix file spec, so we localize_file_path(). + + if (ref $files eq 'ARRAY') { + return { map {$_, [/^(.*)\.PL$/]} + map $self->localize_file_path($_), + @$files }; + + } elsif (ref $files eq 'HASH') { + my %out; + while (my ($file, $to) = each %$files) { + $out{ $self->localize_file_path($file) } = [ map $self->localize_file_path($_), + ref $to ? @$to : ($to) ]; + } + return \%out; + + } else { + die "'PL_files' must be a hash reference or array reference"; + } + } + + return unless -d 'lib'; + return { + map {$_, [/^(.*)\.PL$/i ]} + @{ $self->rscan_dir('lib', $self->file_qr('\.PL$')) } + }; +} + +sub find_pm_files { shift->_find_file_by_type('pm', 'lib') } +sub find_pod_files { shift->_find_file_by_type('pod', 'lib') } +sub find_xs_files { shift->_find_file_by_type('xs', 'lib') } + +sub find_script_files { + my $self = shift; + if (my $files = $self->script_files) { + # Always given as a Unix file spec. Values in the hash are + # meaningless, but we preserve if present. + return { map {$self->localize_file_path($_), $files->{$_}} keys %$files }; + } + + # No default location for script files + return {}; +} + +sub find_test_files { + my $self = shift; + my $p = $self->{properties}; + + if (my $files = $p->{test_files}) { + $files = [keys %$files] if ref $files eq 'HASH'; + $files = [map { -d $_ ? $self->expand_test_dir($_) : $_ } + map glob, + $self->split_like_shell($files)]; + + # Always given as a Unix file spec. + return [ map $self->localize_file_path($_), @$files ]; + + } else { + # Find all possible tests in t/ or test.pl + my @tests; + push @tests, 'test.pl' if -e 'test.pl'; + push @tests, $self->expand_test_dir('t') if -e 't' and -d _; + return \@tests; + } +} + +sub _find_file_by_type { + my ($self, $type, $dir) = @_; + + if (my $files = $self->{properties}{"${type}_files"}) { + # Always given as a Unix file spec + return { map $self->localize_file_path($_), %$files }; + } + + return {} unless -d $dir; + return { map {$_, $_} + map $self->localize_file_path($_), + grep !/\.\#/, + @{ $self->rscan_dir($dir, $self->file_qr("\\.$type\$")) } }; +} + +sub localize_file_path { + my ($self, $path) = @_; + return File::Spec->catfile( split m{/}, $path ); +} + +sub localize_dir_path { + my ($self, $path) = @_; + return File::Spec->catdir( split m{/}, $path ); +} + +sub fix_shebang_line { # Adapted from fixin() in ExtUtils::MM_Unix 1.35 + my ($self, @files) = @_; + my $c = ref($self) ? $self->{config} : 'Module::Build::Config'; + + my ($does_shbang) = $c->get('sharpbang') =~ /^\s*\#\!/; + for my $file (@files) { + open(my $FIXIN, '<', $file) or die "Can't process '$file': $!"; + local $/ = "\n"; + chomp(my $line = <$FIXIN>); + next unless $line =~ s/^\s*\#!\s*//; # Not a shebang file. + + my ($cmd, $arg) = (split(' ', $line, 2), ''); + next unless $cmd =~ /perl/i; + my $interpreter = $self->{properties}{perl}; + + $self->log_verbose("Changing sharpbang in $file to $interpreter\n"); + my $shb = ''; + $shb .= $c->get('sharpbang')."$interpreter $arg\n" if $does_shbang; + + # I'm not smart enough to know the ramifications of changing the + # embedded newlines here to \n, so I leave 'em in. + $shb .= qq{ +eval 'exec $interpreter $arg -S \$0 \${1+"\$\@"}' + if 0; # not running under some shell +} unless $self->is_windowsish; # this won't work on win32, so don't + + open(my $FIXOUT, '>', "$file.new") + or die "Can't create new $file: $!\n"; + + # Print out the new #! line (or equivalent). + local $\; + undef $/; # Was localized above + print $FIXOUT $shb, <$FIXIN>; + close $FIXIN; + close $FIXOUT; + + rename($file, "$file.bak") + or die "Can't rename $file to $file.bak: $!"; + + rename("$file.new", $file) + or die "Can't rename $file.new to $file: $!"; + + $self->delete_filetree("$file.bak") + or $self->log_warn("Couldn't clean up $file.bak, leaving it there"); + + $self->do_system($c->get('eunicefix'), $file) if $c->get('eunicefix') ne ':'; + } +} + + +sub ACTION_testpod { + my $self = shift; + $self->depends_on('docs'); + + eval q{use Test::Pod 0.95; 1} + or die "The 'testpod' action requires Test::Pod version 0.95"; + + my @files = sort keys %{$self->_find_pods($self->libdoc_dirs)}, + keys %{$self->_find_pods + ($self->bindoc_dirs, + exclude => [ $self->file_qr('\.bat$') ])} + or die "Couldn't find any POD files to test\n"; + + { package # hide from PAUSE + Module::Build::PodTester; # Don't want to pollute the main namespace + Test::Pod->import( tests => scalar @files ); + pod_file_ok($_) foreach @files; + } +} + +sub ACTION_testpodcoverage { + my $self = shift; + + $self->depends_on('docs'); + + eval q{use Test::Pod::Coverage 1.00; 1} + or die "The 'testpodcoverage' action requires ", + "Test::Pod::Coverage version 1.00"; + + # TODO this needs test coverage! + + # XXX work-around a bug in Test::Pod::Coverage previous to v1.09 + # Make sure we test the module in blib/ + local @INC = @INC; + my $p = $self->{properties}; + unshift(@INC, + # XXX any reason to include arch? + File::Spec->catdir($p->{base_dir}, $self->blib, 'lib'), + #File::Spec->catdir($p->{base_dir}, $self->blib, 'arch') + ); + + all_pod_coverage_ok(); +} + +sub ACTION_docs { + my $self = shift; + + $self->depends_on('code'); + $self->depends_on('manpages', 'html'); +} + +# Given a file type, will return true if the file type would normally +# be installed when neither install-base nor prefix has been set. +# I.e. it will be true only if the path is set from Config.pm or +# set explicitly by the user via install-path. +sub _is_default_installable { + my $self = shift; + my $type = shift; + return ( $self->install_destination($type) && + ( $self->install_path($type) || + $self->install_sets($self->installdirs)->{$type} ) + ) ? 1 : 0; +} + +sub _is_ActivePerl { +# return 0; + my $self = shift; + unless (exists($self->{_is_ActivePerl})) { + $self->{_is_ActivePerl} = (eval { require ActivePerl::DocTools; } || 0); + } + return $self->{_is_ActivePerl}; +} + +sub _is_ActivePPM { +# return 0; + my $self = shift; + unless (exists($self->{_is_ActivePPM})) { + $self->{_is_ActivePPM} = (eval { require ActivePerl::PPM; } || 0); + } + return $self->{_is_ActivePPM}; +} + +sub ACTION_manpages { + my $self = shift; + + return unless $self->_mb_feature('manpage_support'); + + $self->depends_on('code'); + + my %extra_manify_args = $self->{properties}{'extra_manify_args'} ? %{ $self->{properties}{'extra_manify_args'} } : (); + + foreach my $type ( qw(bin lib) ) { + next unless ( $self->invoked_action eq 'manpages' || $self->_is_default_installable("${type}doc")); + my $files = $self->_find_pods( $self->{properties}{"${type}doc_dirs"}, + exclude => [ $self->file_qr('\.bat$') ] ); + next unless %$files; + + my $sub = $self->can("manify_${type}_pods"); + $self->$sub( %extra_manify_args ) if defined( $sub ); + } +} + +sub manify_bin_pods { + my $self = shift; + my %podman_args = (section => 1, @_); # binaries go in section 1 + + my $files = $self->_find_pods( $self->{properties}{bindoc_dirs}, + exclude => [ $self->file_qr('\.bat$') ] ); + return unless keys %$files; + + my $mandir = File::Spec->catdir( $self->blib, 'bindoc' ); + File::Path::mkpath( $mandir, 0, oct(777) ); + + require Pod::Man; + foreach my $file (keys %$files) { + # Pod::Simple based parsers only support one document per instance. + # This is expected to change in a future version (Pod::Simple > 3.03). + my $parser = Pod::Man->new( %podman_args ); + my $manpage = $self->man1page_name( $file ) . '.' . + $self->config( 'man1ext' ); + my $outfile = File::Spec->catfile($mandir, $manpage); + next if $self->up_to_date( $file, $outfile ); + $self->log_verbose("Manifying $file -> $outfile\n"); + eval { $parser->parse_from_file( $file, $outfile ); 1 } + or $self->log_warn("Error creating '$outfile': $@\n"); + $files->{$file} = $outfile; + } +} + +sub manify_lib_pods { + my $self = shift; + my %podman_args = (section => 3, @_); # libraries go in section 3 + + my $files = $self->_find_pods($self->{properties}{libdoc_dirs}); + return unless keys %$files; + + my $mandir = File::Spec->catdir( $self->blib, 'libdoc' ); + File::Path::mkpath( $mandir, 0, oct(777) ); + + require Pod::Man; + while (my ($file, $relfile) = each %$files) { + # Pod::Simple based parsers only support one document per instance. + # This is expected to change in a future version (Pod::Simple > 3.03). + my $parser = Pod::Man->new( %podman_args ); + my $manpage = $self->man3page_name( $relfile ) . '.' . + $self->config( 'man3ext' ); + my $outfile = File::Spec->catfile( $mandir, $manpage); + next if $self->up_to_date( $file, $outfile ); + $self->log_verbose("Manifying $file -> $outfile\n"); + eval { $parser->parse_from_file( $file, $outfile ); 1 } + or $self->log_warn("Error creating '$outfile': $@\n"); + $files->{$file} = $outfile; + } +} + +sub _find_pods { + my ($self, $dirs, %args) = @_; + my %files; + foreach my $spec (@$dirs) { + my $dir = $self->localize_dir_path($spec); + next unless -e $dir; + + FILE: foreach my $file ( @{ $self->rscan_dir( $dir ) } ) { + foreach my $regexp ( @{ $args{exclude} } ) { + next FILE if $file =~ $regexp; + } + $file = $self->localize_file_path($file); + $files{$file} = File::Spec->abs2rel($file, $dir) if $self->contains_pod( $file ) + } + } + return \%files; +} + +sub contains_pod { + my ($self, $file) = @_; + return '' unless -T $file; # Only look at text files + + open(my $fh, '<', $file ) or die "Can't open $file: $!"; + while (my $line = <$fh>) { + return 1 if $line =~ /^\=(?:head|pod|item)/; + } + + return ''; +} + +sub ACTION_html { + my $self = shift; + + return unless $self->_mb_feature('HTML_support'); + + $self->depends_on('code'); + + foreach my $type ( qw(bin lib) ) { + next unless ( $self->invoked_action eq 'html' || $self->_is_default_installable("${type}html")); + $self->htmlify_pods( $type ); + } +} + +# 1) If it's an ActiveState perl install, we need to run +# ActivePerl::DocTools->UpdateTOC; +# 2) Links to other modules are not being generated +sub htmlify_pods { + my $self = shift; + my $type = shift; + my $htmldir = shift || File::Spec->catdir($self->blib, "${type}html"); + + $self->add_to_cleanup('pod2htm*'); + + my $pods = $self->_find_pods( $self->{properties}{"${type}doc_dirs"}, + exclude => [ $self->file_qr('\.(?:bat|com|html)$') ] ); + return unless %$pods; # nothing to do + + unless ( -d $htmldir ) { + File::Path::mkpath($htmldir, 0, oct(755)) + or die "Couldn't mkdir $htmldir: $!"; + } + + my @rootdirs = ($type eq 'bin') ? qw(bin) : + $self->installdirs eq 'core' ? qw(lib) : qw(site lib); + my $podroot = $ENV{PERL_CORE} + ? File::Basename::dirname($ENV{PERL_CORE}) + : $self->original_prefix('core'); + + my $htmlroot = $self->install_sets('core')->{libhtml}; + my $podpath; + unless (defined $self->args('html_links') and !$self->args('html_links')) { + my @podpath = ( (map { File::Spec->abs2rel($_ ,$podroot) } grep { -d } + ( $self->install_sets('core', 'lib'), # lib + $self->install_sets('core', 'bin'), # bin + $self->install_sets('site', 'lib'), # site/lib + ) ), File::Spec->rel2abs($self->blib) ); + + $podpath = $ENV{PERL_CORE} + ? File::Spec->catdir($podroot, 'lib') + : join(":", map { tr,:\\,|/,; $_ } @podpath); + } + + my $blibdir = join('/', File::Spec->splitdir( + (File::Spec->splitpath(File::Spec->rel2abs($htmldir),1))[1]),'' + ); + + my ($with_ActiveState, $htmltool); + + if ( $with_ActiveState = $self->_is_ActivePerl + && eval { require ActivePerl::DocTools::Pod; 1 } + ) { + my $tool_v = ActiveState::DocTools::Pod->VERSION; + $htmltool = "ActiveState::DocTools::Pod"; + $htmltool .= " $tool_v" if $tool_v && length $tool_v; + } + else { + require Module::Build::PodParser; + require Pod::Html; + $htmltool = "Pod::Html " . Pod::Html->VERSION; + } + $self->log_verbose("Converting Pod to HTML with $htmltool\n"); + + my $errors = 0; + + POD: + foreach my $pod ( keys %$pods ) { + + my ($name, $path) = File::Basename::fileparse($pods->{$pod}, + $self->file_qr('\.(?:pm|plx?|pod)$') + ); + my @dirs = File::Spec->splitdir( File::Spec->canonpath( $path ) ); + pop( @dirs ) if scalar(@dirs) && $dirs[-1] eq File::Spec->curdir; + + my $fulldir = File::Spec->catdir($htmldir, @rootdirs, @dirs); + my $tmpfile = File::Spec->catfile($fulldir, "${name}.tmp"); + my $outfile = File::Spec->catfile($fulldir, "${name}.html"); + my $infile = File::Spec->abs2rel($pod); + + next if $self->up_to_date($infile, $outfile); + + unless ( -d $fulldir ){ + File::Path::mkpath($fulldir, 0, oct(755)) + or die "Couldn't mkdir $fulldir: $!"; + } + + $self->log_verbose("HTMLifying $infile -> $outfile\n"); + if ( $with_ActiveState ) { + my $depth = @rootdirs + @dirs; + my %opts = ( infile => $infile, + outfile => $tmpfile, + ( defined($podpath) ? (podpath => $podpath) : ()), + podroot => $podroot, + index => 1, + depth => $depth, + ); + eval { + ActivePerl::DocTools::Pod::pod2html(%opts); + 1; + } or $self->log_warn("[$htmltool] pod2html (" . + join(", ", map { "q{$_} => q{$opts{$_}}" } (keys %opts)) . ") failed: $@"); + } else { + my $path2root = File::Spec->catdir((File::Spec->updir) x @dirs); + open(my $fh, '<', $infile) or die "Can't read $infile: $!"; + my $abstract = Module::Build::PodParser->new(fh => $fh)->get_abstract(); + + my $title = join( '::', (@dirs, $name) ); + $title .= " - $abstract" if $abstract; + + my @opts = ( + "--title=$title", + ( defined($podpath) ? "--podpath=$podpath" : ()), + "--infile=$infile", + "--outfile=$tmpfile", + "--podroot=$podroot", + ($path2root ? "--htmlroot=$path2root" : ()), + ); + + unless ( eval{Pod::Html->VERSION(1.12)} ) { + push( @opts, ('--flush') ); # caching removed in 1.12 + } + + if ( eval{Pod::Html->VERSION(1.12)} ) { + push( @opts, ('--header', '--backlink') ); + } elsif ( eval{Pod::Html->VERSION(1.03)} ) { + push( @opts, ('--header', '--backlink=Back to Top') ); + } + + $self->log_verbose("P::H::pod2html @opts\n"); + { + my $orig = Cwd::getcwd(); + eval { Pod::Html::pod2html(@opts); 1 } + or $self->log_warn("[$htmltool] pod2html( " . + join(", ", map { "q{$_}" } @opts) . ") failed: $@"); + chdir($orig); + } + } + # We now have to cleanup the resulting html file + if ( ! -r $tmpfile ) { + $errors++; + next POD; + } + open(my $fh, '<', $tmpfile) or die "Can't read $tmpfile: $!"; + my $html = join('',<$fh>); + close $fh; + if (!$self->_is_ActivePerl) { + # These fixups are already done by AP::DT:P:pod2html + # The output from pod2html is NOT XHTML! + # IE6+ will display content that is not valid for DOCTYPE + $html =~ s#^<!DOCTYPE .*?>#<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">#im; + $html =~ s#<html xmlns="http://www.w3.org/1999/xhtml">#<html>#i; + + # IE6+ will not display local HTML files with strict + # security without this comment + $html =~ s#<head>#<head>\n<!-- saved from url=(0017)http://localhost/ -->#i; + } + # Fixup links that point to our temp blib + $html =~ s/\Q$blibdir\E//g; + + open($fh, '>', $outfile) or die "Can't write $outfile: $!"; + print $fh $html; + close $fh; + unlink($tmpfile); + } + + return ! $errors; + +} + +# Adapted from ExtUtils::MM_Unix +sub man1page_name { + my $self = shift; + return File::Basename::basename( shift ); +} + +# Adapted from ExtUtils::MM_Unix and Pod::Man +# Depending on M::B's dependency policy, it might make more sense to refactor +# Pod::Man::begin_pod() to extract a name() methods, and use them... +# -spurkis +sub man3page_name { + my $self = shift; + my ($vol, $dirs, $file) = File::Spec->splitpath( shift ); + my @dirs = File::Spec->splitdir( File::Spec->canonpath($dirs) ); + + # Remove known exts from the base name + $file =~ s/\.p(?:od|m|l)\z//i; + + return join( $self->manpage_separator, @dirs, $file ); +} + +sub manpage_separator { + return '::'; +} + +# For systems that don't have 'diff' executable, should use Algorithm::Diff +sub ACTION_diff { + my $self = shift; + $self->depends_on('build'); + my $local_lib = File::Spec->rel2abs('lib'); + my @myINC = grep {$_ ne $local_lib} @INC; + + # The actual install destination might not be in @INC, so check there too. + push @myINC, map $self->install_destination($_), qw(lib arch); + + my @flags = @{$self->{args}{ARGV}}; + @flags = $self->split_like_shell($self->{args}{flags} || '') unless @flags; + + my $installmap = $self->install_map; + delete $installmap->{read}; + delete $installmap->{write}; + + my $text_suffix = $self->file_qr('\.(pm|pod)$'); + + while (my $localdir = each %$installmap) { + my @localparts = File::Spec->splitdir($localdir); + my $files = $self->rscan_dir($localdir, sub {-f}); + + foreach my $file (@$files) { + my @parts = File::Spec->splitdir($file); + @parts = @parts[@localparts .. $#parts]; # Get rid of blib/lib or similar + + my $installed = Module::Metadata->find_module_by_name( + join('::', @parts), \@myINC ); + if (not $installed) { + print "Only in lib: $file\n"; + next; + } + + my $status = File::Compare::compare($installed, $file); + next if $status == 0; # Files are the same + die "Can't compare $installed and $file: $!" if $status == -1; + + if ($file =~ $text_suffix) { + $self->do_system('diff', @flags, $installed, $file); + } else { + print "Binary files $file and $installed differ\n"; + } + } + } +} + +sub ACTION_pure_install { + shift()->depends_on('install'); +} + +sub ACTION_install { + my ($self) = @_; + require ExtUtils::Install; + $self->depends_on('build'); + # RT#63003 suggest that odd circumstances that we might wind up + # in a different directory than we started, so wrap with _do_in_dir to + # ensure we get back to where we started; hope this fixes it! + $self->_do_in_dir( ".", sub { + ExtUtils::Install::install( + $self->install_map, $self->verbose, 0, $self->{args}{uninst}||0 + ); + }); + if ($self->_is_ActivePerl && $self->{_completed_actions}{html}) { + $self->log_info("Building ActivePerl Table of Contents\n"); + eval { ActivePerl::DocTools::WriteTOC(verbose => $self->verbose ? 1 : 0); 1; } + or $self->log_warn("AP::DT:: WriteTOC() failed: $@"); + } + if ($self->_is_ActivePPM) { + # We touch 'lib/perllocal.pod'. There is an existing logic in subroutine _init_db() + # of 'ActivePerl/PPM/InstallArea.pm' that says that if 'lib/perllocal.pod' has a 'date-last-touched' + # greater than that of the PPM SQLite databases ('etc/ppm-perl-area.db' and/or + # 'site/etc/ppm-site-area.db') then the PPM SQLite databases are rebuilt from scratch. + + # in the following line, 'perllocal.pod' this is *always* 'lib/perllocal.pod', never 'site/lib/perllocal.pod' + my $F_perllocal = File::Spec->catfile($self->install_sets('core', 'lib'), 'perllocal.pod'); + my $dt_stamp = time; + + $self->log_info("For ActivePerl's PPM: touch '$F_perllocal'\n"); + + open my $perllocal, ">>", $F_perllocal; + close $perllocal; + utime($dt_stamp, $dt_stamp, $F_perllocal); + } +} + +sub ACTION_fakeinstall { + my ($self) = @_; + require ExtUtils::Install; + my $eui_version = ExtUtils::Install->VERSION; + if ( $eui_version < 1.32 ) { + $self->log_warn( + "The 'fakeinstall' action requires Extutils::Install 1.32 or later.\n" + . "(You only have version $eui_version)." + ); + return; + } + $self->depends_on('build'); + ExtUtils::Install::install($self->install_map, !$self->quiet, 1, $self->{args}{uninst}||0); +} + +sub ACTION_versioninstall { + my ($self) = @_; + + die "You must have only.pm 0.25 or greater installed for this operation: $@\n" + unless eval { require only; 'only'->VERSION(0.25); 1 }; + + $self->depends_on('build'); + + my %onlyargs = map {exists($self->{args}{$_}) ? ($_ => $self->{args}{$_}) : ()} + qw(version versionlib); + only::install::install(%onlyargs); +} + +sub ACTION_installdeps { + my ($self) = @_; + + # XXX include feature prerequisites as optional prereqs? + + my $info = $self->_enum_prereqs; + if (! $info ) { + $self->log_info( "No prerequisites detected\n" ); + return; + } + + my $failures = $self->prereq_failures($info); + if ( ! $failures ) { + $self->log_info( "All prerequisites satisfied\n" ); + return; + } + + my @install; + while (my ($type, $prereqs) = each %$failures) { + if($type =~ m/^(?:\w+_)?requires$/) { + push(@install, keys %$prereqs); + next; + } + $self->log_info("Checking optional dependencies:\n"); + while (my ($module, $status) = each %$prereqs) { + push(@install, $module) if($self->y_n("Install $module?", 'y')); + } + } + + return unless @install; + + my ($command, @opts) = $self->split_like_shell($self->cpan_client); + + # relative command should be relative to our active Perl + # so we need to locate that command + if ( ! File::Spec->file_name_is_absolute( $command ) ) { + # prefer site to vendor to core + my @loc = ( 'site', 'vendor', '' ); + my @bindirs = File::Basename::dirname($self->perl); + push @bindirs, + map { + ($self->config->{"install${_}bin"}, $self->config->{"install${_}script"}) + } @loc; + for my $d ( @bindirs ) { + my $abs_cmd = $self->find_command(File::Spec->catfile( $d, $command )); + if ( defined $abs_cmd ) { + $command = $abs_cmd; + last; + } + } + } + + $self->do_system($command, @opts, @install); +} + +sub ACTION_clean { + my ($self) = @_; + $self->log_info("Cleaning up build files\n"); + foreach my $item (map glob($_), $self->cleanup) { + $self->delete_filetree($item); + } +} + +sub ACTION_realclean { + my ($self) = @_; + $self->depends_on('clean'); + $self->log_info("Cleaning up configuration files\n"); + $self->delete_filetree( + $self->config_dir, $self->mymetafile, $self->mymetafile2, $self->build_script + ); +} + +sub ACTION_ppd { + my ($self) = @_; + + require Module::Build::PPMMaker; + my $ppd = Module::Build::PPMMaker->new(); + my $file = $ppd->make_ppd(%{$self->{args}}, build => $self); + $self->add_to_cleanup($file); +} + +sub ACTION_ppmdist { + my ($self) = @_; + + $self->depends_on( 'build' ); + + my $ppm = $self->ppm_name; + $self->delete_filetree( $ppm ); + $self->log_info( "Creating $ppm\n" ); + $self->add_to_cleanup( $ppm, "$ppm.tar.gz" ); + + my %types = ( # translate types/dirs to those expected by ppm + lib => 'lib', + arch => 'arch', + bin => 'bin', + script => 'script', + bindoc => 'man1', + libdoc => 'man3', + binhtml => undef, + libhtml => undef, + ); + + foreach my $type ($self->install_types) { + next if exists( $types{$type} ) && !defined( $types{$type} ); + + my $dir = File::Spec->catdir( $self->blib, $type ); + next unless -e $dir; + + my $files = $self->rscan_dir( $dir ); + foreach my $file ( @$files ) { + next unless -f $file; + my $rel_file = + File::Spec->abs2rel( File::Spec->rel2abs( $file ), + File::Spec->rel2abs( $dir ) ); + my $to_file = + File::Spec->catfile( $ppm, 'blib', + exists( $types{$type} ) ? $types{$type} : $type, + $rel_file ); + $self->copy_if_modified( from => $file, to => $to_file ); + } + } + + foreach my $type ( qw(bin lib) ) { + $self->htmlify_pods( $type, File::Spec->catdir($ppm, 'blib', 'html') ); + } + + # create a tarball; + # the directory tar'ed must be blib so we need to do a chdir first + my $target = File::Spec->catfile( File::Spec->updir, $ppm ); + $self->_do_in_dir( $ppm, sub { $self->make_tarball( 'blib', $target ) } ); + + $self->depends_on( 'ppd' ); + + $self->delete_filetree( $ppm ); +} + +sub ACTION_pardist { + my ($self) = @_; + + # Need PAR::Dist + if ( not eval { require PAR::Dist; PAR::Dist->VERSION(0.17) } ) { + $self->log_warn( + "In order to create .par distributions, you need to\n" + . "install PAR::Dist first." + ); + return(); + } + + $self->depends_on( 'build' ); + + return PAR::Dist::blib_to_par( + name => $self->dist_name, + version => $self->dist_version, + ); +} + +sub ACTION_dist { + my ($self) = @_; + + # MUST dispatch() and not depends_ok() so we generate a clean distdir + $self->dispatch('distdir'); + + my $dist_dir = $self->dist_dir; + + $self->make_tarball($dist_dir); + $self->delete_filetree($dist_dir); +} + +sub ACTION_distcheck { + my ($self) = @_; + + $self->_check_manifest_skip unless $self->invoked_action eq 'distclean'; + + require ExtUtils::Manifest; + local $^W; # ExtUtils::Manifest is not warnings clean. + my ($missing, $extra) = ExtUtils::Manifest::fullcheck(); + + return unless @$missing || @$extra; + + my $msg = "MANIFEST appears to be out of sync with the distribution\n"; + if ( $self->invoked_action eq 'distcheck' ) { + die $msg; + } else { + warn $msg; + } +} + +sub _check_mymeta_skip { + my $self = shift; + my $maniskip = shift || 'MANIFEST.SKIP'; + + require ExtUtils::Manifest; + local $^W; # ExtUtils::Manifest is not warnings clean. + + # older ExtUtils::Manifest had a private _maniskip + my $skip_factory = ExtUtils::Manifest->can('maniskip') + || ExtUtils::Manifest->can('_maniskip'); + + my $mymetafile = $self->mymetafile; + # we can't check it, just add it anyway to be safe + for my $file ( $self->mymetafile, $self->mymetafile2 ) { + unless ( $skip_factory && $skip_factory->($maniskip)->($file) ) { + $self->log_warn("File '$maniskip' does not include '$file'. Adding it now.\n"); + my $safe = quotemeta($file); + $self->_append_maniskip("^$safe\$", $maniskip); + } + } +} + +sub _add_to_manifest { + my ($self, $manifest, $lines) = @_; + $lines = [$lines] unless ref $lines; + + my $existing_files = $self->_read_manifest($manifest); + return unless defined( $existing_files ); + + @$lines = grep {!exists $existing_files->{$_}} @$lines + or return; + + my $mode = (stat $manifest)[2]; + chmod($mode | oct(222), $manifest) or die "Can't make $manifest writable: $!"; + + open(my $fh, '<', $manifest) or die "Can't read $manifest: $!"; + my $last_line = (<$fh>)[-1] || "\n"; + my $has_newline = $last_line =~ /\n$/; + close $fh; + + open($fh, '>>', $manifest) or die "Can't write to $manifest: $!"; + print $fh "\n" unless $has_newline; + print $fh map "$_\n", @$lines; + close $fh; + chmod($mode, $manifest); + + $self->log_verbose(map "Added to $manifest: $_\n", @$lines); +} + +sub _sign_dir { + my ($self, $dir) = @_; + + unless (eval { require Module::Signature; 1 }) { + $self->log_warn("Couldn't load Module::Signature for 'distsign' action:\n $@\n"); + return; + } + + # Add SIGNATURE to the MANIFEST + { + my $manifest = File::Spec->catfile($dir, 'MANIFEST'); + die "Signing a distribution requires a MANIFEST file" unless -e $manifest; + $self->_add_to_manifest($manifest, "SIGNATURE Added here by Module::Build"); + } + + # Would be nice if Module::Signature took a directory argument. + + $self->_do_in_dir($dir, sub {local $Module::Signature::Quiet = 1; Module::Signature::sign()}); +} + +sub _do_in_dir { + my ($self, $dir, $do) = @_; + + my $start_dir = File::Spec->rel2abs($self->cwd); + chdir $dir or die "Can't chdir() to $dir: $!"; + eval {$do->()}; + my @err = $@ ? ($@) : (); + chdir $start_dir or push @err, "Can't chdir() back to $start_dir: $!"; + die join "\n", @err if @err; +} + +sub ACTION_distsign { + my ($self) = @_; + { + local $self->{properties}{sign} = 0; # We'll sign it ourselves + $self->depends_on('distdir') unless -d $self->dist_dir; + } + $self->_sign_dir($self->dist_dir); +} + +sub ACTION_skipcheck { + my ($self) = @_; + + require ExtUtils::Manifest; + local $^W; # ExtUtils::Manifest is not warnings clean. + ExtUtils::Manifest::skipcheck(); +} + +sub ACTION_distclean { + my ($self) = @_; + + $self->depends_on('realclean'); + $self->depends_on('distcheck'); +} + +sub do_create_makefile_pl { + my $self = shift; + require Module::Build::Compat; + $self->log_info("Creating Makefile.PL\n"); + eval { Module::Build::Compat->create_makefile_pl($self->create_makefile_pl, $self, @_) }; + if ( $@ ) { + 1 while unlink 'Makefile.PL'; + die "$@\n"; + } + $self->_add_to_manifest('MANIFEST', 'Makefile.PL'); +} + +sub do_create_license { + my $self = shift; + $self->log_info("Creating LICENSE file\n"); + + if ( ! $self->_mb_feature('license_creation') ) { + $self->_warn_mb_feature_deps('license_creation'); + die "Aborting.\n"; + } + + my $l = $self->license + or die "Can't create LICENSE file: No license specified\n"; + + my $license = $self->_software_license_object + or die << "HERE"; +Can't create LICENSE file: '$l' is not a valid license key +or Software::License subclass; +HERE + + $self->delete_filetree('LICENSE'); + + open(my $fh, '>', 'LICENSE') + or die "Can't write LICENSE file: $!"; + print $fh $license->fulltext; + close $fh; + + $self->_add_to_manifest('MANIFEST', 'LICENSE'); +} + +sub do_create_readme { + my $self = shift; + $self->delete_filetree('README'); + + my $docfile = $self->_main_docfile; + unless ( $docfile ) { + $self->log_warn(<<EOF); +Cannot create README: can't determine which file contains documentation; +Must supply either 'dist_version_from', or 'module_name' parameter. +EOF + return; + } + + # work around some odd Pod::Readme->new() failures in test reports by + # confirming that new() is available + if ( eval {require Pod::Readme; Pod::Readme->can('new') } ) { + $self->log_info("Creating README using Pod::Readme\n"); + + my $parser = Pod::Readme->new; + $parser->parse_from_file($docfile, 'README', @_); + + } elsif ( eval {require Pod::Text; 1} ) { + $self->log_info("Creating README using Pod::Text\n"); + + if ( open(my $fh, '>', 'README') ) { + local $^W = 0; + no strict "refs"; + + # work around bug in Pod::Text 3.01, which expects + # Pod::Simple::parse_file to take input and output filehandles + # when it actually only takes an input filehandle + + my $old_parse_file; + $old_parse_file = \&{"Pod::Simple::parse_file"} + and + local *{"Pod::Simple::parse_file"} = sub { + my $self = shift; + $self->output_fh($_[1]) if $_[1]; + $self->$old_parse_file($_[0]); + } + if $Pod::Text::VERSION + == 3.01; # Split line to avoid evil version-finder + + Pod::Text::pod2text( $docfile, $fh ); + + close $fh; + } else { + $self->log_warn( + "Cannot create 'README' file: Can't open file for writing\n" ); + return; + } + + } else { + $self->log_warn("Can't load Pod::Readme or Pod::Text to create README\n"); + return; + } + + $self->_add_to_manifest('MANIFEST', 'README'); +} + +sub _main_docfile { + my $self = shift; + if ( my $pm_file = $self->dist_version_from ) { + (my $pod_file = $pm_file) =~ s/.pm$/.pod/; + return (-e $pod_file ? $pod_file : $pm_file); + } else { + return undef; + } +} + +sub do_create_bundle_inc { + my $self = shift; + my $dist_inc = File::Spec->catdir( $self->dist_dir, 'inc' ); + require inc::latest; + inc::latest->write($dist_inc, @{$self->bundle_inc_preload}); + inc::latest->bundle_module($_, $dist_inc) for @{$self->bundle_inc}; + return 1; +} + +sub ACTION_distdir { + my ($self) = @_; + + if ( @{$self->bundle_inc} && ! $self->_mb_feature('inc_bundling_support') ) { + $self->_warn_mb_feature_deps('inc_bundling_support'); + die "Aborting.\n"; + } + + $self->depends_on('distmeta'); + + my $dist_files = $self->_read_manifest('MANIFEST') + or die "Can't create distdir without a MANIFEST file - run 'manifest' action first.\n"; + delete $dist_files->{SIGNATURE}; # Don't copy, create a fresh one + die "No files found in MANIFEST - try running 'manifest' action?\n" + unless ($dist_files and keys %$dist_files); + my $metafile = $self->metafile; + $self->log_warn("*** Did you forget to add $metafile to the MANIFEST?\n") + unless exists $dist_files->{$metafile}; + + my $dist_dir = $self->dist_dir; + $self->delete_filetree($dist_dir); + $self->log_info("Creating $dist_dir\n"); + $self->add_to_cleanup($dist_dir); + + foreach my $file (keys %$dist_files) { + next if $file =~ m{^MYMETA\.}; # Double check that we skip MYMETA.* + my $new = $self->copy_if_modified(from => $file, to_dir => $dist_dir, verbose => 0); + } + + $self->do_create_bundle_inc if @{$self->bundle_inc}; + + $self->_sign_dir($dist_dir) if $self->{properties}{sign}; +} + +sub ACTION_disttest { + my ($self) = @_; + + $self->depends_on('distdir'); + + $self->_do_in_dir + ( $self->dist_dir, + sub { + local $ENV{AUTHOR_TESTING} = 1; + local $ENV{RELEASE_TESTING} = 1; + + # XXX could be different names for scripts + + $self->run_perl_script('Build.PL') # XXX Should this be run w/ --nouse-rcfile + or die "Error executing 'Build.PL' in dist directory: $!"; + $self->run_perl_script($self->build_script) + or die "Error executing $self->build_script in dist directory: $!"; + $self->run_perl_script($self->build_script, [], ['test']) + or die "Error executing 'Build test' in dist directory"; + }); +} + +sub ACTION_distinstall { + my ($self, @args) = @_; + + $self->depends_on('distdir'); + + $self->_do_in_dir ( $self->dist_dir, + sub { + $self->run_perl_script('Build.PL') + or die "Error executing 'Build.PL' in dist directory: $!"; + $self->run_perl_script($self->build_script) + or die "Error executing $self->build_script in dist directory: $!"; + $self->run_perl_script($self->build_script, [], ['install']) + or die "Error executing 'Build install' in dist directory"; + } + ); +} + +=begin private + + my $has_include = $build->_eumanifest_has_include; + +Returns true if the installed version of ExtUtils::Manifest supports +#include and #include_default directives. False otherwise. + +=end private + +=cut + +# #!include and #!include_default were added in 1.50 +sub _eumanifest_has_include { + my $self = shift; + + require ExtUtils::Manifest; + return eval { ExtUtils::Manifest->VERSION(1.50); 1 }; +} + + +=begin private + + my $maniskip_file = $build->_default_maniskip; + +Returns the location of the installed MANIFEST.SKIP file used by +default. + +=end private + +=cut + +sub _default_maniskip { + my $self = shift; + + my $default_maniskip; + for my $dir (@INC) { + $default_maniskip = File::Spec->catfile($dir, "ExtUtils", "MANIFEST.SKIP"); + last if -r $default_maniskip; + } + + return $default_maniskip; +} + + +=begin private + + my $content = $build->_slurp($file); + +Reads $file and returns the $content. + +=end private + +=cut + +sub _slurp { + my $self = shift; + my $file = shift; + my $mode = shift || ""; + open my $fh, "<$mode", $file or croak "Can't open $file for reading: $!"; + local $/; + return <$fh>; +} + +sub _spew { + my $self = shift; + my $file = shift; + my $content = shift || ""; + my $mode = shift || ""; + open my $fh, ">$mode", $file or croak "Can't open $file for writing: $!"; + print {$fh} $content; + close $fh; +} + +sub _case_tolerant { + my $self = shift; + if ( ref $self ) { + $self->{_case_tolerant} = File::Spec->case_tolerant + unless defined($self->{_case_tolerant}); + return $self->{_case_tolerant}; + } + else { + return File::Spec->case_tolerant; + } +} + +sub _append_maniskip { + my $self = shift; + my $skip = shift; + my $file = shift || 'MANIFEST.SKIP'; + return unless defined $skip && length $skip; + open(my $fh, '>>', $file) + or die "Can't open $file: $!"; + + print $fh "$skip\n"; + close $fh; +} + +sub _write_default_maniskip { + my $self = shift; + my $file = shift || 'MANIFEST.SKIP'; + open(my $fh, '>', $file) + or die "Can't open $file: $!"; + + my $content = $self->_eumanifest_has_include ? "#!include_default\n" + : $self->_slurp( $self->_default_maniskip ); + + $content .= <<'EOF'; +# Avoid configuration metadata file +^MYMETA\. + +# Avoid Module::Build generated and utility files. +\bBuild$ +\bBuild.bat$ +\b_build +\bBuild.COM$ +\bBUILD.COM$ +\bbuild.com$ +^MANIFEST\.SKIP + +# Avoid archives of this distribution +EOF + + # Skip, for example, 'Module-Build-0.27.tar.gz' + $content .= '\b'.$self->dist_name.'-[\d\.\_]+'."\n"; + + print $fh $content; + + close $fh; + + return; +} + +sub _check_manifest_skip { + my ($self) = @_; + + my $maniskip = 'MANIFEST.SKIP'; + + if ( ! -e $maniskip ) { + $self->log_warn("File '$maniskip' does not exist: Creating a temporary '$maniskip'\n"); + $self->_write_default_maniskip($maniskip); + $self->_unlink_on_exit($maniskip); + } + else { + # MYMETA must not be added to MANIFEST, so always confirm the skip + $self->_check_mymeta_skip( $maniskip ); + } + + return; +} + +sub ACTION_manifest { + my ($self) = @_; + + $self->_check_manifest_skip; + + require ExtUtils::Manifest; # ExtUtils::Manifest is not warnings clean. + local ($^W, $ExtUtils::Manifest::Quiet) = (0,1); + ExtUtils::Manifest::mkmanifest(); +} + +sub ACTION_manifest_skip { + my ($self) = @_; + + if ( -e 'MANIFEST.SKIP' ) { + $self->log_warn("MANIFEST.SKIP already exists.\n"); + return 0; + } + $self->log_info("Creating a new MANIFEST.SKIP file\n"); + return $self->_write_default_maniskip; + return -e 'MANIFEST.SKIP' +} + +# Case insensitive regex for files +sub file_qr { + return shift->{_case_tolerant} ? qr($_[0])i : qr($_[0]); +} + +sub dist_dir { + my ($self) = @_; + my $dir = join "-", $self->dist_name, $self->dist_version; + $dir .= "-" . $self->dist_suffix if $self->dist_suffix; + return $dir; +} + +sub ppm_name { + my $self = shift; + return 'PPM-' . $self->dist_dir; +} + +sub _files_in { + my ($self, $dir) = @_; + return unless -d $dir; + + local *DH; + opendir DH, $dir or die "Can't read directory $dir: $!"; + + my @files; + while (defined (my $file = readdir DH)) { + my $full_path = File::Spec->catfile($dir, $file); + next if -d $full_path; + push @files, $full_path; + } + return @files; +} + +sub share_dir { + my $self = shift; + my $p = $self->{properties}; + + $p->{share_dir} = shift if @_; + + # Always coerce to proper hash form + if ( ! defined $p->{share_dir} ) { + return; + } + elsif ( ! ref $p->{share_dir} ) { + # scalar -- treat as a single 'dist' directory + $p->{share_dir} = { dist => [ $p->{share_dir} ] }; + } + elsif ( ref $p->{share_dir} eq 'ARRAY' ) { + # array -- treat as a list of 'dist' directories + $p->{share_dir} = { dist => $p->{share_dir} }; + } + elsif ( ref $p->{share_dir} eq 'HASH' ) { + # hash -- check structure + my $share_dir = $p->{share_dir}; + # check dist key + if ( defined $share_dir->{dist} ) { + if ( ! ref $share_dir->{dist} ) { + # scalar, so upgrade to arrayref + $share_dir->{dist} = [ $share_dir->{dist} ]; + } + elsif ( ref $share_dir->{dist} ne 'ARRAY' ) { + die "'dist' key in 'share_dir' must be scalar or arrayref"; + } + } + # check module key + if ( defined $share_dir->{module} ) { + my $mod_hash = $share_dir->{module}; + if ( ref $mod_hash eq 'HASH' ) { + for my $k ( keys %$mod_hash ) { + if ( ! ref $mod_hash->{$k} ) { + $mod_hash->{$k} = [ $mod_hash->{$k} ]; + } + elsif( ref $mod_hash->{$k} ne 'ARRAY' ) { + die "modules in 'module' key of 'share_dir' must be scalar or arrayref"; + } + } + } + else { + die "'module' key in 'share_dir' must be hashref"; + } + } + } + else { + die "'share_dir' must be hashref, arrayref or string"; + } + + return $p->{share_dir}; +} + +sub script_files { + my $self = shift; + + for ($self->{properties}{script_files}) { + $_ = shift if @_; + next unless $_; + + # Always coerce into a hash + return $_ if ref $_ eq 'HASH'; + return $_ = { map {$_,1} @$_ } if ref $_ eq 'ARRAY'; + + die "'script_files' must be a hashref, arrayref, or string" if ref(); + + return $_ = { map {$_,1} $self->_files_in( $_ ) } if -d $_; + return $_ = {$_ => 1}; + } + + my %pl_files = map { + File::Spec->canonpath( $_ ) => 1 + } keys %{ $self->PL_files || {} }; + + my @bin_files = $self->_files_in('bin'); + + my %bin_map = map { + $_ => File::Spec->canonpath( $_ ) + } @bin_files; + + return $_ = { map {$_ => 1} grep !$pl_files{$bin_map{$_}}, @bin_files }; +} +BEGIN { *scripts = \&script_files; } + +{ + my %licenses = ( + perl => 'Perl_5', + apache => 'Apache_2_0', + apache_1_1 => 'Apache_1_1', + artistic => 'Artistic_1', + artistic_2 => 'Artistic_2', + lgpl => 'LGPL_2_1', + lgpl2 => 'LGPL_2_1', + lgpl3 => 'LGPL_3_0', + bsd => 'BSD', + gpl => 'GPL_1', + gpl2 => 'GPL_2', + gpl3 => 'GPL_3', + mit => 'MIT', + mozilla => 'Mozilla_1_1', + restrictive => 'Restricted', + open_source => undef, + unrestricted => undef, + unknown => undef, + ); + + # TODO - would be nice to not have these here, since they're more + # properly stored only in Software::License + my %license_urls = ( + perl => 'http://dev.perl.org/licenses/', + apache => 'http://apache.org/licenses/LICENSE-2.0', + apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1', + artistic => 'http://opensource.org/licenses/artistic-license.php', + artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', + lgpl => 'http://opensource.org/licenses/lgpl-license.php', + lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', + lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', + bsd => 'http://opensource.org/licenses/bsd-license.php', + gpl => 'http://opensource.org/licenses/gpl-license.php', + gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', + gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', + mit => 'http://opensource.org/licenses/mit-license.php', + mozilla => 'http://opensource.org/licenses/mozilla1.1.php', + restrictive => undef, + open_source => undef, + unrestricted => undef, + unknown => undef, + ); + sub valid_licenses { + return \%licenses; + } + sub _license_url { + return $license_urls{$_[1]}; + } +} + +sub _software_license_class { + my ($self, $license) = @_; + if ($self->valid_licenses->{$license} && eval { require Software::LicenseUtils; Software::LicenseUtils->VERSION(0.103009) }) { + my @classes = Software::LicenseUtils->guess_license_from_meta_key($license, 1); + if (@classes == 1) { + eval "require $classes[0]"; + return $classes[0]; + } + } + LICENSE: for my $l ( $self->valid_licenses->{ $license }, $license ) { + next unless defined $l; + my $trial = "Software::License::" . $l; + if ( eval "require Software::License; Software::License->VERSION(0.014); require $trial; 1" ) { + return $trial; + } + } + return; +} + +# use mapping or license name directly +sub _software_license_object { + my ($self) = @_; + return unless defined( my $license = $self->license ); + + my $class = $self->_software_license_class($license) or return; + + # Software::License requires a 'holder' argument + my $author = join( " & ", @{ $self->dist_author }) || 'unknown'; + my $sl = eval { $class->new({holder=>$author}) }; + if ( $@ ) { + $self->log_warn( "Error getting '$class' object: $@" ); + } + + return $sl; +} + +sub _hash_merge { + my ($self, $h, $k, $v) = @_; + if (ref $h->{$k} eq 'ARRAY') { + push @{$h->{$k}}, ref $v ? @$v : $v; + } elsif (ref $h->{$k} eq 'HASH') { + $h->{$k}{$_} = $v->{$_} foreach keys %$v; + } else { + $h->{$k} = $v; + } +} + +sub ACTION_distmeta { + my ($self) = @_; + $self->do_create_makefile_pl if $self->create_makefile_pl; + $self->do_create_readme if $self->create_readme; + $self->do_create_license if $self->create_license; + $self->do_create_metafile; +} + +sub do_create_metafile { + my $self = shift; + return if $self->{wrote_metadata}; + + my $p = $self->{properties}; + + unless ($p->{license}) { + $self->log_warn("No license specified, setting license = 'unknown'\n"); + $p->{license} = 'unknown'; + } + + my @metafiles = ( $self->metafile, $self->metafile2 ); + # If we're in the distdir, the metafile may exist and be non-writable. + $self->delete_filetree($_) for @metafiles; + + # Since we're building ourself, we have to do some special stuff + # here: the ConfigData module is found in blib/lib. + local @INC = @INC; + if (($self->module_name || '') eq 'Module::Build') { + $self->depends_on('config_data'); + push @INC, File::Spec->catdir($self->blib, 'lib'); + } + + my $meta_obj = $self->_get_meta_object( + quiet => 1, fatal => 1, auto => 1 + ); + my @created = $self->_write_meta_files( $meta_obj, 'META' ); + if ( @created ) { + $self->{wrote_metadata} = 1; + $self->_add_to_manifest('MANIFEST', $_) for @created; + } + return 1; +} + +sub _write_meta_files { + my $self = shift; + my ($meta, $file) = @_; + $file =~ s{\.(?:yml|json)$}{}; + + my @created; + push @created, "$file\.yml" + if $meta && $meta->save( "$file\.yml", {version => "1.4"} ); + push @created, "$file\.json" + if $meta && $meta->save( "$file\.json" ); + + if ( @created ) { + $self->log_info("Created " . join(" and ", @created) . "\n"); + } + return @created; +} + +sub _get_meta_object { + my $self = shift; + my %args = @_; + return unless $self->try_require("CPAN::Meta", "2.110420"); + + my $meta; + eval { + my $data = $self->get_metadata( + fatal => $args{fatal}, + auto => $args{auto}, + ); + $data->{dynamic_config} = $args{dynamic} if defined $args{dynamic}; + $meta = CPAN::Meta->create($data); + }; + if ($@ && ! $args{quiet}) { + $self->log_warn( + "Could not get valid metadata. Error is: $@\n" + ); + } + + return $meta; +} + +sub read_metafile { + my $self = shift; + my ($metafile) = @_; + + return unless $self->try_require("CPAN::Meta", "2.110420"); + my $meta = CPAN::Meta->load_file($metafile); + return $meta->as_struct( {version => "2.0"} ); +} + +sub normalize_version { + my ($self, $version) = @_; + $version = 0 unless defined $version and length $version; + + if ( $version =~ /[=<>!,]/ ) { # logic, not just version + # take as is without modification + } + elsif ( ref $version eq 'version') { # version objects + $version = $version->is_qv ? $version->normal : $version->stringify; + } + elsif ( $version =~ /^[^v][^.]*\.[^.]+\./ ) { # no leading v, multiple dots + # normalize string tuples without "v": "1.2.3" -> "v1.2.3" + $version = "v$version"; + } + else { + # leave alone + } + return $version; +} + +my %prereq_map = ( + requires => [ qw/runtime requires/], + configure_requires => [qw/configure requires/], + build_requires => [ qw/build requires/ ], + test_requires => [ qw/test requires/ ], + test_recommends => [ qw/test recommends/ ], + recommends => [ qw/runtime recommends/ ], + conflicts => [ qw/runtime conflicts/ ], +); + +sub _normalize_prereqs { + my ($self) = @_; + my $p = $self->{properties}; + + # copy prereq data structures so we can modify them before writing to META + my %prereq_types; + for my $type ( 'configure_requires', @{$self->prereq_action_types} ) { + if (exists $p->{$type} and keys %{ $p->{$type} }) { + my ($phase, $relation) = @{ $prereq_map{$type} }; + for my $mod ( keys %{ $p->{$type} } ) { + $prereq_types{$phase}{$relation}{$mod} = $self->normalize_version($p->{$type}{$mod}); + } + } + } + return \%prereq_types; +} + +sub _get_license { + my $self = shift; + + my $license = $self->license; + my ($meta_license, $meta_license_url); + + my $valid_licenses = $self->valid_licenses(); + if ( my $sl = $self->_software_license_object ) { + $meta_license = $sl->meta2_name; + $meta_license_url = $sl->url; + } + elsif ( exists $valid_licenses->{$license} ) { + $meta_license = $valid_licenses->{$license} ? lc $valid_licenses->{$license} : $license; + $meta_license_url = $self->_license_url( $license ); + } + else { + $self->log_warn( "Can not determine license type for '" . $self->license + . "'\nSetting META license field to 'unknown'.\n"); + $meta_license = 'unknown'; + } + return ($meta_license, $meta_license_url); +} + +sub get_metadata { + my ($self, %args) = @_; + + my $fatal = $args{fatal} || 0; + my $p = $self->{properties}; + + $self->auto_config_requires if $args{auto}; + + # validate required fields + foreach my $f (qw(dist_name dist_version dist_author dist_abstract license)) { + my $field = $self->$f(); + unless ( defined $field and length $field ) { + my $err = "ERROR: Missing required field '$f' for metafile\n"; + if ( $fatal ) { + die $err; + } + else { + $self->log_warn($err); + } + } + } + + my %metadata = ( + name => $self->dist_name, + version => $self->normalize_version($self->dist_version), + author => $self->dist_author, + abstract => $self->dist_abstract, + generated_by => "Module::Build version $Module::Build::VERSION", + 'meta-spec' => { + version => '2', + url => 'http://search.cpan.org/perldoc?CPAN::Meta::Spec', + }, + dynamic_config => exists $p->{dynamic_config} ? $p->{dynamic_config} : 1, + release_status => $self->release_status, + ); + + my ($meta_license, $meta_license_url) = $self->_get_license; + $metadata{license} = [ $meta_license ]; + $metadata{resources}{license} = [ $meta_license_url ] if defined $meta_license_url; + + $metadata{prereqs} = $self->_normalize_prereqs; + + if (exists $p->{no_index}) { + $metadata{no_index} = $p->{no_index}; + } elsif (my $pkgs = eval { $self->find_dist_packages }) { + $metadata{provides} = $pkgs if %$pkgs; + } else { + $self->log_warn("$@\nWARNING: Possible missing or corrupt 'MANIFEST' file.\n" . + "Nothing to enter for 'provides' field in metafile.\n"); + } + + if (my $add = $self->meta_add) { + if (not exists $add->{'meta-spec'} or $add->{'meta-spec'}{version} != 2) { + require CPAN::Meta::Converter; + if (CPAN::Meta::Converter->VERSION('2.141170')) { + $add = CPAN::Meta::Converter->new($add)->upgrade_fragment; + delete $add->{prereqs}; # XXX this would now overwrite all prereqs + } + else { + $self->log_warn("Can't meta_add without CPAN::Meta 2.141170"); + } + } + + while (my($k, $v) = each %{$add}) { + $metadata{$k} = $v; + } + } + + if (my $merge = $self->meta_merge) { + if (eval { require CPAN::Meta::Merge }) { + %metadata = %{ CPAN::Meta::Merge->new(default_version => '1.4')->merge(\%metadata, $merge) }; + } + else { + $self->log_warn("Can't merge without CPAN::Meta::Merge"); + } + } + + return \%metadata; +} + +# To preserve compatibility with old API, $node *must* be a hashref +# passed in to prepare_metadata. $keys is an arrayref holding a +# list of keys -- it's use is optional and generally no longer needed +# but kept for back compatibility. $args is an optional parameter to +# support the new 'fatal' toggle + +sub prepare_metadata { + my ($self, $node, $keys, $args) = @_; + unless ( ref $node eq 'HASH' ) { + croak "prepare_metadata() requires a hashref argument to hold output\n"; + } + croak 'Keys argument to prepare_metadata is no longer supported' if $keys; + %{$node} = %{ $self->get_meta(%{$args}) }; + return $node; +} + +sub _read_manifest { + my ($self, $file) = @_; + return undef unless -e $file; + + require ExtUtils::Manifest; # ExtUtils::Manifest is not warnings clean. + local ($^W, $ExtUtils::Manifest::Quiet) = (0,1); + return scalar ExtUtils::Manifest::maniread($file); +} + +sub find_dist_packages { + my $self = shift; + + # Only packages in .pm files are candidates for inclusion here. + # Only include things in the MANIFEST, not things in developer's + # private stock. + + my $manifest = $self->_read_manifest('MANIFEST') + or die "Can't find dist packages without a MANIFEST file\nRun 'Build manifest' to generate one\n"; + + # Localize + my %dist_files = map { $self->localize_file_path($_) => $_ } + keys %$manifest; + + my @pm_files = grep { $_ !~ m{^t} } # skip things in t/ + grep {exists $dist_files{$_}} + keys %{ $self->find_pm_files }; + + return $self->find_packages_in_files(\@pm_files, \%dist_files); +} + +# XXX Do not document this function; mst wrote it and now says the API is +# stupid and needs to be fixed and it shouldn't become a public API until then +sub find_packages_in_files { + my ($self, $file_list, $filename_map) = @_; + + # First, we enumerate all packages & versions, + # separating into primary & alternative candidates + my( %prime, %alt ); + foreach my $file (@{$file_list}) { + my $mapped_filename = $filename_map->{$file}; + my @path = split( /\//, $mapped_filename ); + (my $prime_package = join( '::', @path[1..$#path] )) =~ s/\.pm$//; + + my $pm_info = Module::Metadata->new_from_file( $file ); + + foreach my $package ( $pm_info->packages_inside ) { + next if $package eq 'main'; # main can appear numerous times, ignore + next if $package eq 'DB'; # special debugging package, ignore + next if grep /^_/, split( /::/, $package ); # private package, ignore + + my $version = $pm_info->version( $package ); + + if ( $package eq $prime_package ) { + if ( exists( $prime{$package} ) ) { + # Module::Metadata will handle this conflict + die "Unexpected conflict in '$package'; multiple versions found.\n"; + } else { + $prime{$package}{file} = $mapped_filename; + $prime{$package}{version} = $version if defined( $version ); + } + } else { + push( @{$alt{$package}}, { + file => $mapped_filename, + version => $version, + } ); + } + } + } + + # Then we iterate over all the packages found above, identifying conflicts + # and selecting the "best" candidate for recording the file & version + # for each package. + foreach my $package ( keys( %alt ) ) { + my $result = $self->_resolve_module_versions( $alt{$package} ); + + if ( exists( $prime{$package} ) ) { # primary package selected + + if ( $result->{err} ) { + # Use the selected primary package, but there are conflicting + # errors among multiple alternative packages that need to be + # reported + $self->log_warn( + "Found conflicting versions for package '$package'\n" . + " $prime{$package}{file} ($prime{$package}{version})\n" . + $result->{err} + ); + + } elsif ( defined( $result->{version} ) ) { + # There is a primary package selected, and exactly one + # alternative package + + if ( exists( $prime{$package}{version} ) && + defined( $prime{$package}{version} ) ) { + # Unless the version of the primary package agrees with the + # version of the alternative package, report a conflict + if ( $self->compare_versions( $prime{$package}{version}, '!=', + $result->{version} ) ) { + $self->log_warn( + "Found conflicting versions for package '$package'\n" . + " $prime{$package}{file} ($prime{$package}{version})\n" . + " $result->{file} ($result->{version})\n" + ); + } + + } else { + # The prime package selected has no version so, we choose to + # use any alternative package that does have a version + $prime{$package}{file} = $result->{file}; + $prime{$package}{version} = $result->{version}; + } + + } else { + # no alt package found with a version, but we have a prime + # package so we use it whether it has a version or not + } + + } else { # No primary package was selected, use the best alternative + + if ( $result->{err} ) { + $self->log_warn( + "Found conflicting versions for package '$package'\n" . + $result->{err} + ); + } + + # Despite possible conflicting versions, we choose to record + # something rather than nothing + $prime{$package}{file} = $result->{file}; + $prime{$package}{version} = $result->{version} + if defined( $result->{version} ); + } + } + + # Normalize versions or delete them if undef/0 + for my $provides ( values %prime ) { + if ( $provides->{version} ) { + $provides->{version} = $self->normalize_version( $provides->{version} ) + } + else { + delete $provides->{version}; + } + } + + return \%prime; +} + +# separate out some of the conflict resolution logic from +# $self->find_dist_packages(), above, into a helper function. +# +sub _resolve_module_versions { + my $self = shift; + + my $packages = shift; + + my( $file, $version ); + my $err = ''; + foreach my $p ( @$packages ) { + if ( defined( $p->{version} ) ) { + if ( defined( $version ) ) { + if ( $self->compare_versions( $version, '!=', $p->{version} ) ) { + $err .= " $p->{file} ($p->{version})\n"; + } else { + # same version declared multiple times, ignore + } + } else { + $file = $p->{file}; + $version = $p->{version}; + } + } + $file ||= $p->{file} if defined( $p->{file} ); + } + + if ( $err ) { + $err = " $file ($version)\n" . $err; + } + + my %result = ( + file => $file, + version => $version, + err => $err + ); + + return \%result; +} + +sub make_tarball { + my ($self, $dir, $file) = @_; + $file ||= $dir; + + $self->log_info("Creating $file.tar.gz\n"); + + if ($self->{args}{tar}) { + my $tar_flags = $self->verbose ? 'cvf' : 'cf'; + $self->do_system($self->split_like_shell($self->{args}{tar}), $tar_flags, "$file.tar", $dir); + $self->do_system($self->split_like_shell($self->{args}{gzip}), "$file.tar") if $self->{args}{gzip}; + } else { + eval { require Archive::Tar && Archive::Tar->VERSION(1.09); 1 } + or die "You must install Archive::Tar 1.09+ to make a distribution tarball\n". + "or specify a binary tar program with the '--tar' option.\n". + "See the documentation for the 'dist' action.\n"; + + my $files = $self->rscan_dir($dir); + + # Archive::Tar versions >= 1.09 use the following to enable a compatibility + # hack so that the resulting archive is compatible with older clients. + # If no file path is 100 chars or longer, we disable the prefix field + # for maximum compatibility. If there are any long file paths then we + # need the prefix field after all. + $Archive::Tar::DO_NOT_USE_PREFIX = + (grep { length($_) >= 100 } @$files) ? 0 : 1; + + my $tar = Archive::Tar->new; + $tar->add_files(@$files); + for my $f ($tar->get_files) { + $f->mode($f->mode & ~022); # chmod go-w + } + $tar->write("$file.tar.gz", 1); + } +} + +sub install_path { + my $self = shift; + my( $type, $value ) = ( @_, '<empty>' ); + + Carp::croak( 'Type argument missing' ) + unless defined( $type ); + + my $map = $self->{properties}{install_path}; + return $map unless @_; + + # delete existing value if $value is literal undef() + unless ( defined( $value ) ) { + delete( $map->{$type} ); + return undef; + } + + # return existing value if no new $value is given + if ( $value eq '<empty>' ) { + return undef unless exists $map->{$type}; + return $map->{$type}; + } + + # set value if $value is a valid relative path + return $map->{$type} = $value; +} + +sub install_sets { + # Usage: install_sets('site'), install_sets('site', 'lib'), + # or install_sets('site', 'lib' => $value); + my ($self, $dirs, $key, $value) = @_; + $dirs = $self->installdirs unless defined $dirs; + # update property before merging with defaults + if ( @_ == 4 && defined $dirs && defined $key) { + # $value can be undef; will mask default + $self->{properties}{install_sets}{$dirs}{$key} = $value; + } + my $map = { $self->_merge_arglist( + $self->{properties}{install_sets}, + $self->_default_install_paths->{install_sets} + )}; + if ( defined $dirs && defined $key ) { + return $map->{$dirs}{$key}; + } + elsif ( defined $dirs ) { + return $map->{$dirs}; + } + else { + croak "Can't determine installdirs for install_sets()"; + } +} + +sub original_prefix { + # Usage: original_prefix(), original_prefix('lib'), + # or original_prefix('lib' => $value); + my ($self, $key, $value) = @_; + # update property before merging with defaults + if ( @_ == 3 && defined $key) { + # $value can be undef; will mask default + $self->{properties}{original_prefix}{$key} = $value; + } + my $map = { $self->_merge_arglist( + $self->{properties}{original_prefix}, + $self->_default_install_paths->{original_prefix} + )}; + return $map unless defined $key; + return $map->{$key} +} + +sub install_base_relpaths { + # Usage: install_base_relpaths(), install_base_relpaths('lib'), + # or install_base_relpaths('lib' => $value); + my $self = shift; + if ( @_ > 1 ) { # change values before merge + $self->_set_relpaths($self->{properties}{install_base_relpaths}, @_); + } + my $map = { $self->_merge_arglist( + $self->{properties}{install_base_relpaths}, + $self->_default_install_paths->{install_base_relpaths} + )}; + return $map unless @_; + my $relpath = $map->{$_[0]}; + return defined $relpath ? File::Spec->catdir( @$relpath ) : undef; +} + +# Defaults to use in case the config install paths cannot be prefixified. +sub prefix_relpaths { + # Usage: prefix_relpaths('site'), prefix_relpaths('site', 'lib'), + # or prefix_relpaths('site', 'lib' => $value); + my $self = shift; + my $installdirs = shift || $self->installdirs + or croak "Can't determine installdirs for prefix_relpaths()"; + if ( @_ > 1 ) { # change values before merge + $self->{properties}{prefix_relpaths}{$installdirs} ||= {}; + $self->_set_relpaths($self->{properties}{prefix_relpaths}{$installdirs}, @_); + } + my $map = {$self->_merge_arglist( + $self->{properties}{prefix_relpaths}{$installdirs}, + $self->_default_install_paths->{prefix_relpaths}{$installdirs} + )}; + return $map unless @_; + my $relpath = $map->{$_[0]}; + return defined $relpath ? File::Spec->catdir( @$relpath ) : undef; +} + +sub _set_relpaths { + my $self = shift; + my( $map, $type, $value ) = @_; + + Carp::croak( 'Type argument missing' ) + unless defined( $type ); + + # set undef if $value is literal undef() + if ( ! defined( $value ) ) { + $map->{$type} = undef; + return; + } + # set value if $value is a valid relative path + else { + Carp::croak( "Value must be a relative path" ) + if File::Spec::Unix->file_name_is_absolute($value); + + my @value = split( /\//, $value ); + $map->{$type} = \@value; + } +} + +# Translated from ExtUtils::MM_Any::init_INSTALL_from_PREFIX +sub prefix_relative { + my ($self, $type) = @_; + my $installdirs = $self->installdirs; + + my $relpath = $self->install_sets($installdirs)->{$type}; + + return $self->_prefixify($relpath, + $self->original_prefix($installdirs), + $type, + ); +} + +# Translated from ExtUtils::MM_Unix::prefixify() +sub _prefixify { + my($self, $path, $sprefix, $type) = @_; + + my $rprefix = $self->prefix; + $rprefix .= '/' if $sprefix =~ m|/$|; + + $self->log_verbose(" prefixify $path from $sprefix to $rprefix\n") + if defined( $path ) && length( $path ); + + if( !defined( $path ) || ( length( $path ) == 0 ) ) { + $self->log_verbose(" no path to prefixify, falling back to default.\n"); + return $self->_prefixify_default( $type, $rprefix ); + } elsif( !File::Spec->file_name_is_absolute($path) ) { + $self->log_verbose(" path is relative, not prefixifying.\n"); + } elsif( $path !~ s{^\Q$sprefix\E\b}{}s ) { + $self->log_verbose(" cannot prefixify, falling back to default.\n"); + return $self->_prefixify_default( $type, $rprefix ); + } + + $self->log_verbose(" now $path in $rprefix\n"); + + return $path; +} + +sub _prefixify_default { + my $self = shift; + my $type = shift; + my $rprefix = shift; + + my $default = $self->prefix_relpaths($self->installdirs, $type); + if( !$default ) { + $self->log_verbose(" no default install location for type '$type', using prefix '$rprefix'.\n"); + return $rprefix; + } else { + return $default; + } +} + +sub install_destination { + my ($self, $type) = @_; + + return $self->install_path($type) if $self->install_path($type); + + if ( $self->install_base ) { + my $relpath = $self->install_base_relpaths($type); + return $relpath ? File::Spec->catdir($self->install_base, $relpath) : undef; + } + + if ( $self->prefix ) { + my $relpath = $self->prefix_relative($type); + return $relpath ? File::Spec->catdir($self->prefix, $relpath) : undef; + } + + return $self->install_sets($self->installdirs)->{$type}; +} + +sub install_types { + my $self = shift; + + my %types; + if ( $self->install_base ) { + %types = %{$self->install_base_relpaths}; + } elsif ( $self->prefix ) { + %types = %{$self->prefix_relpaths}; + } else { + %types = %{$self->install_sets($self->installdirs)}; + } + + %types = (%types, %{$self->install_path}); + + return sort keys %types; +} + +sub install_map { + my ($self, $blib) = @_; + $blib ||= $self->blib; + + my( %map, @skipping ); + foreach my $type ($self->install_types) { + my $localdir = File::Spec->catdir( $blib, $type ); + next unless -e $localdir; + + # the line "...next if (($type eq 'bindoc'..." was one of many changes introduced for + # improving HTML generation on ActivePerl, see https://rt.cpan.org/Public/Bug/Display.html?id=53478 + # Most changes were ok, but this particular line caused test failures in t/manifypods.t on windows, + # therefore it is commented out. + + # ********* next if (($type eq 'bindoc' || $type eq 'libdoc') && not $self->is_unixish); + + if (my $dest = $self->install_destination($type)) { + $map{$localdir} = $dest; + } else { + push( @skipping, $type ); + } + } + + $self->log_warn( + "WARNING: Can't figure out install path for types: @skipping\n" . + "Files will not be installed.\n" + ) if @skipping; + + # Write the packlist into the same place as ExtUtils::MakeMaker. + if ($self->create_packlist and my $module_name = $self->module_name) { + my $archdir = $self->install_destination('arch'); + my @ext = split /::/, $module_name; + $map{write} = File::Spec->catfile($archdir, 'auto', @ext, '.packlist'); + } + + # Handle destdir + if (length(my $destdir = $self->destdir || '')) { + foreach (keys %map) { + # Need to remove volume from $map{$_} using splitpath, or else + # we'll create something crazy like C:\Foo\Bar\E:\Baz\Quux + # VMS will always have the file separate than the path. + my ($volume, $path, $file) = File::Spec->splitpath( $map{$_}, 0 ); + + # catdir needs a list of directories, or it will create something + # crazy like volume:[Foo.Bar.volume.Baz.Quux] + my @dirs = File::Spec->splitdir($path); + + # First merge the directories + $path = File::Spec->catdir($destdir, @dirs); + + # Then put the file back on if there is one. + if ($file ne '') { + $map{$_} = File::Spec->catfile($path, $file) + } else { + $map{$_} = $path; + } + } + } + + $map{read} = ''; # To keep ExtUtils::Install quiet + + return \%map; +} + +sub depends_on { + my $self = shift; + foreach my $action (@_) { + $self->_call_action($action); + } +} + +sub rscan_dir { + my ($self, $dir, $pattern) = @_; + my @result; + local $_; # find() can overwrite $_, so protect ourselves + my $subr = !$pattern ? sub {push @result, $File::Find::name} : + !ref($pattern) || (ref $pattern eq 'Regexp') ? sub {push @result, $File::Find::name if /$pattern/} : + ref($pattern) eq 'CODE' ? sub {push @result, $File::Find::name if $pattern->()} : + die "Unknown pattern type"; + + File::Find::find({wanted => $subr, no_chdir => 1}, $dir); + return \@result; +} + +sub delete_filetree { + my $self = shift; + my $deleted = 0; + foreach (@_) { + next unless -e $_; + $self->log_verbose("Deleting $_\n"); + File::Path::rmtree($_, 0, 0); + die "Couldn't remove '$_': $!\n" if -e $_; + $deleted++; + } + return $deleted; +} + +sub autosplit_file { + my ($self, $file, $to) = @_; + require AutoSplit; + my $dir = File::Spec->catdir($to, 'lib', 'auto'); + AutoSplit::autosplit($file, $dir); +} + +sub cbuilder { + # Returns a CBuilder object + + my $self = shift; + my $s = $self->{stash}; + return $s->{_cbuilder} if $s->{_cbuilder}; + + require ExtUtils::CBuilder; + return $s->{_cbuilder} = ExtUtils::CBuilder->new( + config => $self->config, + ($self->quiet ? (quiet => 1 ) : ()), + ); +} + +sub have_c_compiler { + my ($self) = @_; + + my $p = $self->{properties}; + return $p->{_have_c_compiler} if defined $p->{_have_c_compiler}; + + $self->log_verbose("Checking if compiler tools configured... "); + my $b = $self->cbuilder; + my $have = $b && eval { $b->have_compiler }; + $self->log_verbose($have ? "ok.\n" : "failed.\n"); + return $p->{_have_c_compiler} = $have; +} + +sub compile_c { + my ($self, $file, %args) = @_; + + if ( ! $self->have_c_compiler ) { + die "Error: no compiler detected to compile '$file'. Aborting\n"; + } + + my $b = $self->cbuilder; + my $obj_file = $b->object_file($file); + $self->add_to_cleanup($obj_file); + return $obj_file if $self->up_to_date($file, $obj_file); + + $b->compile(source => $file, + defines => $args{defines}, + object_file => $obj_file, + include_dirs => $self->include_dirs, + extra_compiler_flags => $self->extra_compiler_flags, + ); + + return $obj_file; +} + +sub link_c { + my ($self, $spec) = @_; + my $p = $self->{properties}; # For convenience + + $self->add_to_cleanup($spec->{lib_file}); + + my $objects = $p->{objects} || []; + + return $spec->{lib_file} + if $self->up_to_date([$spec->{obj_file}, @$objects], + $spec->{lib_file}); + + my $module_name = $spec->{module_name} || $self->module_name; + + $self->cbuilder->link( + module_name => $module_name, + objects => [$spec->{obj_file}, @$objects], + lib_file => $spec->{lib_file}, + extra_linker_flags => $p->{extra_linker_flags} ); + + return $spec->{lib_file}; +} + +sub compile_xs { + my ($self, $file, %args) = @_; + + $self->log_verbose("$file -> $args{outfile}\n"); + + if (eval {require ExtUtils::ParseXS; 1}) { + + ExtUtils::ParseXS::process_file( + filename => $file, + prototypes => 0, + output => $args{outfile}, + ); + } else { + # Ok, I give up. Just use backticks. + + my $xsubpp = Module::Metadata->find_module_by_name('ExtUtils::xsubpp') + or die "Can't find ExtUtils::xsubpp in INC (@INC)"; + + my @typemaps; + push @typemaps, Module::Metadata->find_module_by_name( + 'ExtUtils::typemap', \@INC + ); + my $lib_typemap = Module::Metadata->find_module_by_name( + 'typemap', [File::Basename::dirname($file), File::Spec->rel2abs('.')] + ); + push @typemaps, $lib_typemap if $lib_typemap; + @typemaps = map {+'-typemap', $_} @typemaps; + + my $cf = $self->{config}; + my $perl = $self->{properties}{perl}; + + my @command = ($perl, "-I".$cf->get('installarchlib'), "-I".$cf->get('installprivlib'), $xsubpp, '-noprototypes', + @typemaps, $file); + + $self->log_info("@command\n"); + open(my $fh, '>', $args{outfile}) or die "Couldn't write $args{outfile}: $!"; + print {$fh} $self->_backticks(@command); + close $fh; + } +} + +sub split_like_shell { + my ($self, $string) = @_; + + return () unless defined($string); + return @$string if ref $string eq 'ARRAY'; + $string =~ s/^\s+|\s+$//g; + return () unless length($string); + + return Text::ParseWords::shellwords($string); +} + +sub oneliner { + # Returns a string that the shell can evaluate as a perl command. + # This should be avoided whenever possible, since "the shell" really + # means zillions of shells on zillions of platforms and it's really + # hard to get it right all the time. + + # Some of this code is stolen with permission from ExtUtils::MakeMaker. + + my($self, $cmd, $switches, $args) = @_; + $switches = [] unless defined $switches; + $args = [] unless defined $args; + + # Strip leading and trailing newlines + $cmd =~ s{^\n+}{}; + $cmd =~ s{\n+$}{}; + + my $perl = ref($self) ? $self->perl : $self->find_perl_interpreter; + return $self->_quote_args($perl, @$switches, '-e', $cmd, @$args); +} + +sub run_perl_script { + my ($self, $script, $preargs, $postargs) = @_; + foreach ($preargs, $postargs) { + $_ = [ $self->split_like_shell($_) ] unless ref(); + } + return $self->run_perl_command([@$preargs, $script, @$postargs]); +} + +sub run_perl_command { + # XXX Maybe we should accept @args instead of $args? Must resolve + # this before documenting. + my ($self, $args) = @_; + $args = [ $self->split_like_shell($args) ] unless ref($args); + my $perl = ref($self) ? $self->perl : $self->find_perl_interpreter; + + # Make sure our local additions to @INC are propagated to the subprocess + local $ENV{PERL5LIB} = join $self->config('path_sep'), $self->_added_to_INC; + + return $self->do_system($perl, @$args); +} + +# Infer various data from the path of the input filename +# that is needed to create output files. +# The input filename is expected to be of the form: +# lib/Module/Name.ext or Module/Name.ext +sub _infer_xs_spec { + my $self = shift; + my $file = shift; + + my $cf = $self->{config}; + + my %spec; + + my( $v, $d, $f ) = File::Spec->splitpath( $file ); + my @d = File::Spec->splitdir( $d ); + (my $file_base = $f) =~ s/\.[^.]+$//i; + + $spec{base_name} = $file_base; + + $spec{src_dir} = File::Spec->catpath( $v, $d, '' ); + + # the module name + shift( @d ) while @d && ($d[0] eq 'lib' || $d[0] eq ''); + pop( @d ) while @d && $d[-1] eq ''; + $spec{module_name} = join( '::', (@d, $file_base) ); + + $spec{archdir} = File::Spec->catdir($self->blib, 'arch', 'auto', + @d, $file_base); + + $spec{c_file} = File::Spec->catfile( $spec{src_dir}, + "${file_base}.c" ); + + $spec{obj_file} = File::Spec->catfile( $spec{src_dir}, + "${file_base}".$cf->get('obj_ext') ); + + require DynaLoader; + my $modfname = defined &DynaLoader::mod2fname ? DynaLoader::mod2fname([@d, $file_base]) : $file_base; + + $spec{bs_file} = File::Spec->catfile($spec{archdir}, "$modfname.bs"); + + $spec{lib_file} = File::Spec->catfile($spec{archdir}, "$modfname.".$cf->get('dlext')); + + return \%spec; +} + +sub process_xs { + my ($self, $file) = @_; + + my $spec = $self->_infer_xs_spec($file); + + # File name, minus the suffix + (my $file_base = $file) =~ s/\.[^.]+$//; + + # .xs -> .c + $self->add_to_cleanup($spec->{c_file}); + + unless ($self->up_to_date($file, $spec->{c_file})) { + $self->compile_xs($file, outfile => $spec->{c_file}); + } + + # .c -> .o + my $v = $self->dist_version; + $self->compile_c($spec->{c_file}, + defines => {VERSION => qq{"$v"}, XS_VERSION => qq{"$v"}}); + + # archdir + File::Path::mkpath($spec->{archdir}, 0, oct(777)) unless -d $spec->{archdir}; + + # .xs -> .bs + $self->add_to_cleanup($spec->{bs_file}); + unless ($self->up_to_date($file, $spec->{bs_file})) { + require ExtUtils::Mkbootstrap; + $self->log_info("ExtUtils::Mkbootstrap::Mkbootstrap('$spec->{bs_file}')\n"); + ExtUtils::Mkbootstrap::Mkbootstrap($spec->{bs_file}); # Original had $BSLOADLIBS - what's that? + open(my $fh, '>>', $spec->{bs_file}); # create + utime((time)x2, $spec->{bs_file}); # touch + } + + # .o -> .(a|bundle) + $self->link_c($spec); +} + +sub do_system { + my ($self, @cmd) = @_; + $self->log_verbose("@cmd\n"); + + # Some systems proliferate huge PERL5LIBs, try to ameliorate: + my %seen; + my $sep = $self->config('path_sep'); + local $ENV{PERL5LIB} = + ( !exists($ENV{PERL5LIB}) ? '' : + length($ENV{PERL5LIB}) < 500 + ? $ENV{PERL5LIB} + : join $sep, grep { ! $seen{$_}++ and -d $_ } split($sep, $ENV{PERL5LIB}) + ); + + my $status = system(@cmd); + if ($status and $! =~ /Argument list too long/i) { + my $env_entries = ''; + foreach (sort keys %ENV) { $env_entries .= "$_=>".length($ENV{$_})."; " } + warn "'Argument list' was 'too long', env lengths are $env_entries"; + } + return !$status; +} + +sub copy_if_modified { + my $self = shift; + my %args = (@_ > 3 + ? ( @_ ) + : ( from => shift, to_dir => shift, flatten => shift ) + ); + $args{verbose} = !$self->quiet + unless exists $args{verbose}; + + my $file = $args{from}; + unless (defined $file and length $file) { + die "No 'from' parameter given to copy_if_modified"; + } + + # makes no sense to replicate an absolute path, so assume flatten + $args{flatten} = 1 if File::Spec->file_name_is_absolute( $file ); + + my $to_path; + if (defined $args{to} and length $args{to}) { + $to_path = $args{to}; + } elsif (defined $args{to_dir} and length $args{to_dir}) { + $to_path = File::Spec->catfile( $args{to_dir}, $args{flatten} + ? File::Basename::basename($file) + : $file ); + } else { + die "No 'to' or 'to_dir' parameter given to copy_if_modified"; + } + + return if $self->up_to_date($file, $to_path); # Already fresh + + { + local $self->{properties}{quiet} = 1; + $self->delete_filetree($to_path); # delete destination if exists + } + + # Create parent directories + File::Path::mkpath(File::Basename::dirname($to_path), 0, oct(777)); + + $self->log_verbose("Copying $file -> $to_path\n"); + + if ($^O eq 'os2') {# copy will not overwrite; 0x1 = overwrite + chmod 0666, $to_path; + File::Copy::syscopy($file, $to_path, 0x1) or die "Can't copy('$file', '$to_path'): $!"; + } else { + File::Copy::copy($file, $to_path) or die "Can't copy('$file', '$to_path'): $!"; + } + + # mode is read-only + (executable if source is executable) + my $mode = oct(444) | ( $self->is_executable($file) ? oct(111) : 0 ); + chmod( $mode, $to_path ); + + return $to_path; +} + +sub up_to_date { + my ($self, $source, $derived) = @_; + $source = [$source] unless ref $source; + $derived = [$derived] unless ref $derived; + + # empty $derived means $source should always run + return 0 if @$source && !@$derived || grep {not -e} @$derived; + + my $most_recent_source = time / (24*60*60); + foreach my $file (@$source) { + unless (-e $file) { + $self->log_warn("Can't find source file $file for up-to-date check"); + next; + } + $most_recent_source = -M _ if -M _ < $most_recent_source; + } + + foreach my $derived (@$derived) { + return 0 if -M $derived > $most_recent_source; + } + return 1; +} + +sub dir_contains { + my ($self, $first, $second) = @_; + # File::Spec doesn't have an easy way to check whether one directory + # is inside another, unfortunately. + + ($first, $second) = map File::Spec->canonpath($_), ($first, $second); + my @first_dirs = File::Spec->splitdir($first); + my @second_dirs = File::Spec->splitdir($second); + + return 0 if @second_dirs < @first_dirs; + + my $is_same = ( $self->_case_tolerant + ? sub {lc(shift()) eq lc(shift())} + : sub {shift() eq shift()} ); + + while (@first_dirs) { + return 0 unless $is_same->(shift @first_dirs, shift @second_dirs); + } + + return 1; +} + +1; +__END__ + + +=head1 NAME + +Module::Build::Base - Default methods for Module::Build + +=head1 SYNOPSIS + + Please see the Module::Build documentation. + +=head1 DESCRIPTION + +The C<Module::Build::Base> module defines the core functionality of +C<Module::Build>. Its methods may be overridden by any of the +platform-dependent modules in the C<Module::Build::Platform::> +namespace, but the intention here is to make this base module as +platform-neutral as possible. Nicely enough, Perl has several core +tools available in the C<File::> namespace for doing this, so the task +isn't very difficult. + +Please see the C<Module::Build> documentation for more details. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + +=head1 SEE ALSO + +perl(1), Module::Build(3) + +=cut diff --git a/lib/Module/Build/Bundling.pod b/lib/Module/Build/Bundling.pod new file mode 100644 index 0000000..98f2de3 --- /dev/null +++ b/lib/Module/Build/Bundling.pod @@ -0,0 +1,147 @@ +=head1 NAME + +Module::Build::Bundling - How to bundle Module::Build with a distribution + +=head1 SYNOPSIS + + # Build.PL + use inc::latest 'Module::Build'; + + Module::Build->new( + module_name => 'Foo::Bar', + license => 'perl', + )->create_build_script; + +=head1 DESCRIPTION + +B<WARNING -- THIS IS AN EXPERIMENTAL FEATURE> + +In order to install a distribution using Module::Build, users must +have Module::Build available on their systems. There are two ways +to do this. The first way is to include Module::Build in the +C<configure_requires> metadata field. This field is supported by +recent versions L<CPAN> and L<CPANPLUS> and is a standard feature +in the Perl core as of Perl 5.10.1. Module::Build now adds itself +to C<configure_requires> by default. + +The second way supports older Perls that have not upgraded CPAN or +CPANPLUS and involves bundling an entire copy of Module::Build +into the distribution's C<inc/> directory. This is the same approach +used by L<Module::Install>, a modern wrapper around ExtUtils::MakeMaker +for Makefile.PL based distributions. + +The "trick" to making this work for Module::Build is making sure the +highest version Module::Build is used, whether this is in C<inc/> or +already installed on the user's system. This ensures that all necessary +features are available as well as any new bug fixes. This is done using +the experimental L<inc::latest> module, available on CPAN. + +A "normal" Build.PL looks like this (with only the minimum required +fields): + + use Module::Build; + + Module::Build->new( + module_name => 'Foo::Bar', + license => 'perl', + )->create_build_script; + +A "bundling" Build.PL replaces the initial "use" line with a nearly +transparent replacement: + + use inc::latest 'Module::Build'; + + Module::Build->new( + module_name => 'Foo::Bar', + license => 'perl', + )->create_build_script; + +For I<authors>, when "Build dist" is run, Module::Build will be +automatically bundled into C<inc> according to the rules for +L<inc::latest>. + +For I<users>, inc::latest will load the latest Module::Build, whether +installed or bundled in C<inc/>. + +=head1 BUNDLING OTHER CONFIGURATION DEPENDENCIES + +The same approach works for other configuration dependencies -- modules +that I<must> be available for Build.PL to run. All other dependencies can +be specified as usual in the Build.PL and CPAN or CPANPLUS will install +them after Build.PL finishes. + +For example, to bundle the L<Devel::AssertOS::Unix> module (which ensures a +"Unix-like" operating system), one could do this: + + use inc::latest 'Devel::AssertOS::Unix'; + use inc::latest 'Module::Build'; + + Module::Build->new( + module_name => 'Foo::Bar', + license => 'perl', + )->create_build_script; + +The C<inc::latest> module creates bundled directories based on the packlist +file of an installed distribution. Even though C<inc::latest> takes module +name arguments, it is better to think of it as bundling and making +available entire I<distributions>. When a module is loaded through +C<inc::latest>, it looks in all bundled distributions in C<inc/> for a +newer module than can be found in the existing C<@INC> array. + +Thus, the module-name provided should usually be the "top-level" module +name of a distribution, though this is not strictly required. For example, +L<Module::Build> has a number of heuristics to map module names to +packlists, allowing users to do things like this: + + use inc::latest 'Devel::AssertOS::Unix'; + +even though Devel::AssertOS::Unix is contained within the Devel-CheckOS +distribution. + +At the current time, packlists are required. Thus, bundling dual-core +modules, I<including Module::Build>, may require a 'forced install' over +versions in the latest version of perl in order to create the necessary +packlist for bundling. This limitation will hopefully be addressed in a +future version of Module::Build. + +=head2 WARNING -- How to Manage Dependency Chains + +Before bundling a distribution you must ensure that all prerequisites are +also bundled and load in the correct order. For Module::Build itself, this +should not be necessary, but it is necessary for any other distribution. +(A future release of Module::Build will hopefully address this deficiency.) + +For example, if you need C<Wibble>, but C<Wibble> depends on C<Wobble>, +your Build.PL might look like this: + + use inc::latest 'Wobble'; + use inc::latest 'Wibble'; + use inc::latest 'Module::Build'; + + Module::Build->new( + module_name => 'Foo::Bar', + license => 'perl', + )->create_build_script; + +Authors are strongly suggested to limit the bundling of additional +dependencies if at all possible and to carefully test their distribution +tarballs on older versions of Perl before uploading to CPAN. + +=head1 AUTHOR + +David Golden <dagolden@cpan.org> + +Development questions, bug reports, and patches should be sent to the +Module-Build mailing list at <module-build@perl.org>. + +Bug reports are also welcome at +<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Module-Build>. + +=head1 SEE ALSO + +perl(1), L<inc::latest>, L<Module::Build>(3), L<Module::Build::API>(3), +L<Module::Build::Cookbook>(3), + +=cut + +# vim: tw=75 diff --git a/lib/Module/Build/Compat.pm b/lib/Module/Build/Compat.pm new file mode 100644 index 0000000..25924fd --- /dev/null +++ b/lib/Module/Build/Compat.pm @@ -0,0 +1,632 @@ +package Module::Build::Compat; + +use strict; +use warnings; +our $VERSION = '0.4214'; + +use File::Basename (); +use File::Spec; +use Config; +use Module::Build; +use Module::Metadata; +use version; +use Data::Dumper; + +my %convert_installdirs = ( + PERL => 'core', + SITE => 'site', + VENDOR => 'vendor', +); + +my %makefile_to_build = + ( + TEST_VERBOSE => 'verbose', + VERBINST => 'verbose', + INC => sub { map {(extra_compiler_flags => $_)} Module::Build->split_like_shell(shift) }, + POLLUTE => sub { (extra_compiler_flags => '-DPERL_POLLUTE') }, + INSTALLDIRS => sub { (installdirs => $convert_installdirs{uc shift()}) }, + LIB => sub { + my $lib = shift; + my %config = ( + installprivlib => $lib, + installsitelib => $lib, + installarchlib => "$lib/$Config{archname}", + installsitearch => "$lib/$Config{archname}" + ); + return map { (config => "$_=$config{$_}") } keys %config; + }, + + # Convert INSTALLVENDORLIB and friends. + ( + map { + my $name = $_; + $name => sub { + my @ret = (config => lc($name) . "=" . shift ); + print STDERR "# Converted to @ret\n"; + + return @ret; + } + } qw( + INSTALLARCHLIB INSTALLSITEARCH INSTALLVENDORARCH + INSTALLPRIVLIB INSTALLSITELIB INSTALLVENDORLIB + INSTALLBIN INSTALLSITEBIN INSTALLVENDORBIN + INSTALLSCRIPT INSTALLSITESCRIPT INSTALLVENDORSCRIPT + INSTALLMAN1DIR INSTALLSITEMAN1DIR INSTALLVENDORMAN1DIR + INSTALLMAN3DIR INSTALLSITEMAN3DIR INSTALLVENDORMAN3DIR + ) + ), + + # Some names they have in common + map {$_, lc($_)} qw(DESTDIR PREFIX INSTALL_BASE UNINST), + ); + +my %macro_to_build = %makefile_to_build; +# "LIB=foo make" is not the same as "perl Makefile.PL LIB=foo" +delete $macro_to_build{LIB}; + +sub _merge_prereq { + my ($req, $breq) = @_; + $req ||= {}; + $breq ||= {}; + + # validate formats + for my $p ( $req, $breq ) { + for my $k (keys %$p) { + next if $k eq 'perl'; + + my $v_obj = eval { version->new($p->{$k}) }; + if ( ! defined $v_obj ) { + die "A prereq of the form '$p->{$k}' for '$k' is not supported by Module::Build::Compat ( use a simpler version like '0.05' or 'v1.4.25' )\n"; + } + + # It seems like a lot of people trip over "0.1.2" stuff, so we help them here... + if ( $v_obj->is_qv ) { + my $proper_ver = $v_obj->numify; + warn "Dotted-decimal prereq '$p->{$k}' for '$k' is not portable - converting it to '$proper_ver'\n"; + $p->{$k} = $proper_ver; + } + } + } + # merge + my $merge = { %$req }; + for my $k ( keys %$breq ) { + my $v1 = $merge->{$k} || 0; + my $v2 = $breq->{$k}; + $merge->{$k} = $v1 > $v2 ? $v1 : $v2; + } + return %$merge; +} + + +sub create_makefile_pl { + my ($package, $type, $build, %args) = @_; + + die "Don't know how to build Makefile.PL of type '$type'" + unless $type =~ /^(small|passthrough|traditional)$/; + + if ($type eq 'passthrough') { + $build->log_warn(<<"HERE"); + +IMPORTANT NOTE: The '$type' style of Makefile.PL is deprecated and +may be removed in a future version of Module::Build in favor of the +'configure_requires' property. See Module::Build::Compat +documentation for details. + +HERE + } + + my $fh; + if ($args{fh}) { + $fh = $args{fh}; + } else { + $args{file} ||= 'Makefile.PL'; + local $build->{properties}{quiet} = 1; + $build->delete_filetree($args{file}); + open($fh, '>', "$args{file}") or die "Can't write $args{file}: $!"; + } + + print {$fh} "# Note: this file was auto-generated by ", __PACKAGE__, " version $VERSION\n"; + + # Minimum perl version should be specified as "require 5.XXXXXX" in + # Makefile.PL + my $requires = $build->requires; + if ( my $minimum_perl = $requires->{perl} ) { + my $min_ver = version->new($minimum_perl)->numify; + print {$fh} "require $min_ver;\n"; + } + + # If a *bundled* custom subclass is being used, make sure we add its + # directory to @INC. Also, lib.pm always needs paths in Unix format. + my $subclass_load = ''; + if (ref($build) ne "Module::Build") { + my $subclass_dir = $package->subclass_dir($build); + + if (File::Spec->file_name_is_absolute($subclass_dir)) { + my $base_dir = $build->base_dir; + + if ($build->dir_contains($base_dir, $subclass_dir)) { + $subclass_dir = File::Spec->abs2rel($subclass_dir, $base_dir); + $subclass_dir = $package->unixify_dir($subclass_dir); + $subclass_load = "use lib '$subclass_dir';"; + } + # Otherwise, leave it the empty string + + } else { + $subclass_dir = $package->unixify_dir($subclass_dir); + $subclass_load = "use lib '$subclass_dir';"; + } + } + + if ($type eq 'small') { + printf {$fh} <<'EOF', $subclass_load, ref($build), ref($build); + use Module::Build::Compat 0.02; + %s + Module::Build::Compat->run_build_pl(args => \@ARGV); + require %s; + Module::Build::Compat->write_makefile(build_class => '%s'); +EOF + + } elsif ($type eq 'passthrough') { + printf {$fh} <<'EOF', $subclass_load, ref($build), ref($build); + + unless (eval "use Module::Build::Compat 0.02; 1" ) { + print "This module requires Module::Build to install itself.\n"; + + require ExtUtils::MakeMaker; + my $yn = ExtUtils::MakeMaker::prompt + (' Install Module::Build now from CPAN?', 'y'); + + unless ($yn =~ /^y/i) { + die " *** Cannot install without Module::Build. Exiting ...\n"; + } + + require Cwd; + require File::Spec; + require CPAN; + + # Save this 'cause CPAN will chdir all over the place. + my $cwd = Cwd::cwd(); + + CPAN::Shell->install('Module::Build::Compat'); + CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate + or die "Couldn't install Module::Build, giving up.\n"; + + chdir $cwd or die "Cannot chdir() back to $cwd: $!"; + } + eval "use Module::Build::Compat 0.02; 1" or die $@; + %s + Module::Build::Compat->run_build_pl(args => \@ARGV); + my $build_script = 'Build'; + $build_script .= '.com' if $^O eq 'VMS'; + exit(0) unless(-e $build_script); # cpantesters convention + require %s; + Module::Build::Compat->write_makefile(build_class => '%s'); +EOF + + } elsif ($type eq 'traditional') { + + my (%MM_Args, %prereq); + if (eval "use Tie::IxHash 1.2; 1") { + tie %MM_Args, 'Tie::IxHash'; # Don't care if it fails here + tie %prereq, 'Tie::IxHash'; # Don't care if it fails here + } + + my %name = ($build->module_name + ? (NAME => $build->module_name) + : (DISTNAME => $build->dist_name)); + + my %version = ($build->dist_version_from + ? (VERSION_FROM => $build->dist_version_from) + : (VERSION => $build->dist_version) + ); + %MM_Args = (%name, %version); + + %prereq = _merge_prereq( $build->requires, $build->build_requires ); + %prereq = map {$_, $prereq{$_}} sort keys %prereq; + + delete $prereq{perl}; + $MM_Args{PREREQ_PM} = \%prereq; + + $MM_Args{INSTALLDIRS} = $build->installdirs eq 'core' ? 'perl' : $build->installdirs; + + $MM_Args{EXE_FILES} = [ sort keys %{$build->script_files} ] if $build->script_files; + + $MM_Args{PL_FILES} = $build->PL_files || {}; + + if ($build->recursive_test_files) { + $MM_Args{test} = { TESTS => join q{ }, $package->_test_globs($build) }; + } + + local $Data::Dumper::Terse = 1; + my $args = Data::Dumper::Dumper(\%MM_Args); + $args =~ s/\{(.*)\}/($1)/s; + + print $fh <<"EOF"; +use ExtUtils::MakeMaker; +WriteMakefile +$args; +EOF + } +} + +sub _test_globs { + my ($self, $build) = @_; + + return map { File::Spec->catfile($_, '*.t') } + @{$build->rscan_dir('t', sub { -d $File::Find::name })}; +} + +sub subclass_dir { + my ($self, $build) = @_; + + return (Module::Metadata->find_module_dir_by_name(ref $build) + || File::Spec->catdir($build->config_dir, 'lib')); +} + +sub unixify_dir { + my ($self, $path) = @_; + return join '/', File::Spec->splitdir($path); +} + +sub makefile_to_build_args { + my $class = shift; + my @out; + foreach my $arg (@_) { + next if $arg eq ''; + + my ($key, $val) = ($arg =~ /^(\w+)=(.+)/ ? ($1, $2) : + die "Malformed argument '$arg'"); + + # Do tilde-expansion if it looks like a tilde prefixed path + ( $val ) = Module::Build->_detildefy( $val ) if $val =~ /^~/; + + if (exists $makefile_to_build{$key}) { + my $trans = $makefile_to_build{$key}; + push @out, $class->_argvify( ref($trans) ? $trans->($val) : ($trans => $val) ); + } elsif (exists $Config{lc($key)}) { + push @out, $class->_argvify( config => lc($key) . "=$val" ); + } else { + # Assume M::B can handle it in lowercase form + push @out, $class->_argvify("\L$key" => $val); + } + } + return @out; +} + +sub _argvify { + my ($self, @pairs) = @_; + my @out; + while (@pairs) { + my ($k, $v) = splice @pairs, 0, 2; + push @out, ("--$k", $v); + } + return @out; +} + +sub makefile_to_build_macros { + my @out; + my %config; # must accumulate and return as a hashref + while (my ($macro, $trans) = each %macro_to_build) { + # On some platforms (e.g. Cygwin with 'make'), the mere presence + # of "EXPORT: FOO" in the Makefile will make $ENV{FOO} defined. + # Therefore we check length() too. + next unless exists $ENV{$macro} && length $ENV{$macro}; + my $val = $ENV{$macro}; + my @args = ref($trans) ? $trans->($val) : ($trans => $val); + while (@args) { + my ($k, $v) = splice(@args, 0, 2); + if ( $k eq 'config' ) { + if ( $v =~ /^([^=]+)=(.*)$/ ) { + $config{$1} = $2; + } + else { + warn "Couldn't parse config '$v'\n"; + } + } + else { + push @out, ($k => $v); + } + } + } + push @out, (config => \%config) if %config; + return @out; +} + +sub run_build_pl { + my ($pack, %in) = @_; + $in{script} ||= 'Build.PL'; + my @args = $in{args} ? $pack->makefile_to_build_args(@{$in{args}}) : (); + print "# running $in{script} @args\n"; + Module::Build->run_perl_script($in{script}, [], \@args) or die "Couldn't run $in{script}: $!"; +} + +sub fake_makefile { + my ($self, %args) = @_; + unless (exists $args{build_class}) { + warn "Unknown 'build_class', defaulting to 'Module::Build'\n"; + $args{build_class} = 'Module::Build'; + } + my $class = $args{build_class}; + + my $perl = $class->find_perl_interpreter; + + # VMS MMS/MMK need to use MCR to run the Perl image. + $perl = 'MCR ' . $perl if $self->_is_vms_mms; + + my $noop = ($class->is_windowsish ? 'rem>nul' : + $self->_is_vms_mms ? 'Continue' : + 'true'); + + my $filetype = $class->is_vmsish ? '.COM' : ''; + + my $Build = 'Build' . $filetype . ' --makefile_env_macros 1'; + my $unlink = $class->oneliner('1 while unlink $ARGV[0]', [], [$args{makefile}]); + $unlink =~ s/\$/\$\$/g unless $class->is_vmsish; + + my $maketext = ($^O eq 'os2' ? "SHELL = sh\n\n" : ''); + + $maketext .= <<"EOF"; +all : force_do_it + $perl $Build +realclean : force_do_it + $perl $Build realclean + $unlink +distclean : force_do_it + $perl $Build distclean + $unlink + + +force_do_it : + @ $noop +EOF + + foreach my $action ($class->known_actions) { + next if $action =~ /^(all|distclean|realclean|force_do_it)$/; # Don't double-define + $maketext .= <<"EOF"; +$action : force_do_it + $perl $Build $action +EOF + } + + if ($self->_is_vms_mms) { + # Roll our own .EXPORT as MMS/MMK don't honor that directive. + $maketext .= "\n.FIRST\n\t\@ $noop\n"; + for my $macro (keys %macro_to_build) { + $maketext .= ".IFDEF $macro\n\tDEFINE $macro \"\$($macro)\"\n.ENDIF\n"; + } + $maketext .= "\n"; + } + else { + $maketext .= "\n.EXPORT : " . join(' ', keys %macro_to_build) . "\n\n"; + } + + return $maketext; +} + +sub fake_prereqs { + my $file = File::Spec->catfile('_build', 'prereqs'); + open(my $fh, '<', "$file") or die "Can't read $file: $!"; + my $prereqs = eval do {local $/; <$fh>}; + close $fh; + + my %merged = _merge_prereq( $prereqs->{requires}, $prereqs->{build_requires} ); + my @prereq; + foreach (sort keys %merged) { + next if $_ eq 'perl'; + push @prereq, "$_=>q[$merged{$_}]"; + } + return unless @prereq; + return "# PREREQ_PM => { " . join(", ", @prereq) . " }\n\n"; +} + + +sub write_makefile { + my ($pack, %in) = @_; + + unless (exists $in{build_class}) { + warn "Unknown 'build_class', defaulting to 'Module::Build'\n"; + $in{build_class} = 'Module::Build'; + } + my $class = $in{build_class}; + $in{makefile} ||= $pack->_is_vms_mms ? 'Descrip.MMS' : 'Makefile'; + + open MAKE, "> $in{makefile}" or die "Cannot write $in{makefile}: $!"; + print MAKE $pack->fake_prereqs; + print MAKE $pack->fake_makefile(%in); + close MAKE; +} + +sub _is_vms_mms { + return Module::Build->is_vmsish && ($Config{make} =~ m/MM[SK]/i); +} + +1; +__END__ + +=for :stopwords passthrough + +=head1 NAME + +Module::Build::Compat - Compatibility with ExtUtils::MakeMaker + +=head1 SYNOPSIS + + # In a Build.PL : + use Module::Build; + my $build = Module::Build->new + ( module_name => 'Foo::Bar', + license => 'perl', + create_makefile_pl => 'traditional' ); + ... + + +=head1 DESCRIPTION + +Because C<ExtUtils::MakeMaker> has been the standard way to distribute +modules for a long time, many tools (CPAN.pm, or your system +administrator) may expect to find a working F<Makefile.PL> in every +distribution they download from CPAN. If you want to throw them a +bone, you can use C<Module::Build::Compat> to automatically generate a +F<Makefile.PL> for you, in one of several different styles. + +C<Module::Build::Compat> also provides some code that helps out the +F<Makefile.PL> at runtime. + + +=head1 METHODS + +=over 4 + +=item create_makefile_pl($style, $build) + +Creates a F<Makefile.PL> in the current directory in one of several +styles, based on the supplied C<Module::Build> object C<$build>. This is +typically controlled by passing the desired style as the +C<create_makefile_pl> parameter to C<Module::Build>'s C<new()> method; +the F<Makefile.PL> will then be automatically created during the +C<distdir> action. + +The currently supported styles are: + +=over 4 + +=item traditional + +A F<Makefile.PL> will be created in the "traditional" style, i.e. it will +use C<ExtUtils::MakeMaker> and won't rely on C<Module::Build> at all. +In order to create the F<Makefile.PL>, we'll include the C<requires> and +C<build_requires> dependencies as the C<PREREQ_PM> parameter. + +You don't want to use this style if during the C<perl Build.PL> stage +you ask the user questions, or do some auto-sensing about the user's +environment, or if you subclass C<Module::Build> to do some +customization, because the vanilla F<Makefile.PL> won't do any of that. + +=item small + +A small F<Makefile.PL> will be created that passes all functionality +through to the F<Build.PL> script in the same directory. The user must +already have C<Module::Build> installed in order to use this, or else +they'll get a module-not-found error. + +=item passthrough (DEPRECATED) + +This is just like the C<small> option above, but if C<Module::Build> is +not already installed on the user's system, the script will offer to +use C<CPAN.pm> to download it and install it before continuing with +the build. + +This option has been deprecated and may be removed in a future version +of Module::Build. Modern CPAN.pm and CPANPLUS will recognize the +C<configure_requires> metadata property and install Module::Build before +running Build.PL if Module::Build is listed and Module::Build now +adds itself to configure_requires by default. + +Perl 5.10.1 includes C<configure_requires> support. In the future, when +C<configure_requires> support is deemed sufficiently widespread, the +C<passthrough> style will be removed. + +=back + +=item run_build_pl(args => \@ARGV) + +This method runs the F<Build.PL> script, passing it any arguments the +user may have supplied to the C<perl Makefile.PL> command. Because +C<ExtUtils::MakeMaker> and C<Module::Build> accept different arguments, this +method also performs some translation between the two. + +C<run_build_pl()> accepts the following named parameters: + +=over 4 + +=item args + +The C<args> parameter specifies the parameters that would usually +appear on the command line of the C<perl Makefile.PL> command - +typically you'll just pass a reference to C<@ARGV>. + +=item script + +This is the filename of the script to run - it defaults to C<Build.PL>. + +=back + +=item write_makefile() + +This method writes a 'dummy' F<Makefile> that will pass all commands +through to the corresponding C<Module::Build> actions. + +C<write_makefile()> accepts the following named parameters: + +=over 4 + +=item makefile + +The name of the file to write - defaults to the string C<Makefile>. + +=back + +=back + + +=head1 SCENARIOS + +So, some common scenarios are: + +=over 4 + +=item 1. + +Just include a F<Build.PL> script (without a F<Makefile.PL> +script), and give installation directions in a F<README> or F<INSTALL> +document explaining how to install the module. In particular, explain +that the user must install C<Module::Build> before installing your +module. + +Note that if you do this, you may make things easier for yourself, but +harder for people with older versions of CPAN or CPANPLUS on their +system, because those tools generally only understand the +F<Makefile.PL>/C<ExtUtils::MakeMaker> way of doing things. + +=item 2. + +Include a F<Build.PL> script and a "traditional" F<Makefile.PL>, +created either manually or with C<create_makefile_pl()>. Users won't +ever have to install C<Module::Build> if they use the F<Makefile.PL>, but +they won't get to take advantage of C<Module::Build>'s extra features +either. + +For good measure, of course, test both the F<Makefile.PL> and the +F<Build.PL> before shipping. + +=item 3. + +Include a F<Build.PL> script and a "pass-through" F<Makefile.PL> +built using C<Module::Build::Compat>. This will mean that people can +continue to use the "old" installation commands, and they may never +notice that it's actually doing something else behind the scenes. It +will also mean that your installation process is compatible with older +versions of tools like CPAN and CPANPLUS. + +=back + + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + + +=head1 SEE ALSO + +L<Module::Build>(3), L<ExtUtils::MakeMaker>(3) + + +=cut diff --git a/lib/Module/Build/Config.pm b/lib/Module/Build/Config.pm new file mode 100644 index 0000000..2977680 --- /dev/null +++ b/lib/Module/Build/Config.pm @@ -0,0 +1,59 @@ +package Module::Build::Config; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Config; + +sub new { + my ($pack, %args) = @_; + return bless { + stack => {}, + values => $args{values} || {}, + }, $pack; +} + +sub get { + my ($self, $key) = @_; + return $self->{values}{$key} if ref($self) && exists $self->{values}{$key}; + return $Config{$key}; +} + +sub set { + my ($self, $key, $val) = @_; + $self->{values}{$key} = $val; +} + +sub push { + my ($self, $key, $val) = @_; + push @{$self->{stack}{$key}}, $self->{values}{$key} + if exists $self->{values}{$key}; + $self->{values}{$key} = $val; +} + +sub pop { + my ($self, $key) = @_; + + my $val = delete $self->{values}{$key}; + if ( exists $self->{stack}{$key} ) { + $self->{values}{$key} = pop @{$self->{stack}{$key}}; + delete $self->{stack}{$key} unless @{$self->{stack}{$key}}; + } + + return $val; +} + +sub values_set { + my $self = shift; + return undef unless ref($self); + return $self->{values}; +} + +sub all_config { + my $self = shift; + my $v = ref($self) ? $self->{values} : {}; + return {%Config, %$v}; +} + +1; diff --git a/lib/Module/Build/Cookbook.pm b/lib/Module/Build/Cookbook.pm new file mode 100644 index 0000000..75b5179 --- /dev/null +++ b/lib/Module/Build/Cookbook.pm @@ -0,0 +1,529 @@ +package Module::Build::Cookbook; +use strict; +use warnings; +our $VERSION = '0.4214'; + + +=head1 NAME + +Module::Build::Cookbook - Examples of Module::Build Usage + +=head1 DESCRIPTION + +C<Module::Build> isn't conceptually very complicated, but examples are +always helpful. The following recipes should help developers and/or +installers put together the pieces from the other parts of the +documentation. + + +=head1 BASIC RECIPES + + +=head2 Installing modules that use Module::Build + +In most cases, you can just issue the following commands: + + perl Build.PL + ./Build + ./Build test + ./Build install + +There's nothing complicated here - first you're running a script +called F<Build.PL>, then you're running a (newly-generated) script +called F<Build> and passing it various arguments. + +The exact commands may vary a bit depending on how you invoke perl +scripts on your system. For instance, if you have multiple versions +of perl installed, you can install to one particular perl's library +directories like so: + + /usr/bin/perl5.8.1 Build.PL + ./Build + ./Build test + ./Build install + +If you're on Windows where the current directory is always searched +first for scripts, you'll probably do something like this: + + perl Build.PL + Build + Build test + Build install + +On the old Mac OS (version 9 or lower) using MacPerl, you can +double-click on the F<Build.PL> script to create the F<Build> script, +then double-click on the F<Build> script to run its C<build>, C<test>, +and C<install> actions. + +The F<Build> script knows what perl was used to run F<Build.PL>, so +you don't need to re-invoke the F<Build> script with the complete perl +path each time. If you invoke it with the I<wrong> perl path, you'll +get a warning or a fatal error. + +=head2 Modifying Config.pm values + +C<Module::Build> relies heavily on various values from perl's +C<Config.pm> to do its work. For example, default installation paths +are given by C<installsitelib> and C<installvendorman3dir> and +friends, C linker & compiler settings are given by C<ld>, +C<lddlflags>, C<cc>, C<ccflags>, and so on. I<If you're pretty sure +you know what you're doing>, you can tell C<Module::Build> to pretend +there are different values in F<Config.pm> than what's really there, +by passing arguments for the C<--config> parameter on the command +line: + + perl Build.PL --config cc=gcc --config ld=gcc + +Inside the C<Build.PL> script the same thing can be accomplished by +passing values for the C<config> parameter to C<new()>: + + my $build = Module::Build->new + ( + ... + config => { cc => 'gcc', ld => 'gcc' }, + ... + ); + +In custom build code, the same thing can be accomplished by calling +the L<Module::Build/config> method: + + $build->config( cc => 'gcc' ); # Set + $build->config( ld => 'gcc' ); # Set + ... + my $linker = $build->config('ld'); # Get + + +=head2 Installing modules using the programmatic interface + +If you need to build, test, and/or install modules from within some +other perl code (as opposed to having the user type installation +commands at the shell), you can use the programmatic interface. +Create a Module::Build object (or an object of a custom Module::Build +subclass) and then invoke its C<dispatch()> method to run various +actions. + + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + license => 'perl', + requires => { 'Some::Module' => '1.23' }, + ); + $build->dispatch('build'); + $build->dispatch('test', verbose => 1); + $build->dispatch('install'); + +The first argument to C<dispatch()> is the name of the action, and any +following arguments are named parameters. + +This is the interface we use to test Module::Build itself in the +regression tests. + + +=head2 Installing to a temporary directory + +To create packages for package managers like RedHat's C<rpm> or +Debian's C<deb>, you may need to install to a temporary directory +first and then create the package from that temporary installation. +To do this, specify the C<destdir> parameter to the C<install> action: + + ./Build install --destdir /tmp/my-package-1.003 + +This essentially just prepends all the installation paths with the +F</tmp/my-package-1.003> directory. + + +=head2 Installing to a non-standard directory + +To install to a non-standard directory (for example, if you don't have +permission to install in the system-wide directories), you can use the +C<install_base> or C<prefix> parameters: + + ./Build install --install_base /foo/bar + +See L<Module::Build/"INSTALL PATHS"> for a much more complete +discussion of how installation paths are determined. + + +=head2 Installing in the same location as ExtUtils::MakeMaker + +With the introduction of C<--prefix> in Module::Build 0.28 and +C<INSTALL_BASE> in C<ExtUtils::MakeMaker> 6.31 its easy to get them both +to install to the same locations. + +First, ensure you have at least version 0.28 of Module::Build +installed and 6.31 of C<ExtUtils::MakeMaker>. Prior versions have +differing (and in some cases quite strange) installation behaviors. + +The following installation flags are equivalent between +C<ExtUtils::MakeMaker> and C<Module::Build>. + + MakeMaker Module::Build + PREFIX=... --prefix ... + INSTALL_BASE=... --install_base ... + DESTDIR=... --destdir ... + LIB=... --install_path lib=... + INSTALLDIRS=... --installdirs ... + INSTALLDIRS=perl --installdirs core + UNINST=... --uninst ... + INC=... --extra_compiler_flags ... + POLLUTE=1 --extra_compiler_flags -DPERL_POLLUTE + +For example, if you are currently installing C<MakeMaker> modules with +this command: + + perl Makefile.PL PREFIX=~ + make test + make install UNINST=1 + +You can install into the same location with Module::Build using this: + + perl Build.PL --prefix ~ + ./Build test + ./Build install --uninst 1 + +=head3 C<prefix> vs C<install_base> + +The behavior of C<prefix> is complicated and depends on +how your Perl is configured. The resulting installation locations +will vary from machine to machine and even different installations of +Perl on the same machine. Because of this, it's difficult to document +where C<prefix> will place your modules. + +In contrast, C<install_base> has predictable, easy to explain +installation locations. Now that C<Module::Build> and C<MakeMaker> both +have C<install_base> there is little reason to use C<prefix> other +than to preserve your existing installation locations. If you are +starting a fresh Perl installation we encourage you to use +C<install_base>. If you have an existing installation installed via +C<prefix>, consider moving it to an installation structure matching +C<install_base> and using that instead. + + +=head2 Running a single test file + +C<Module::Build> supports running a single test, which enables you to +track down errors more quickly. Use the following format: + + ./Build test --test_files t/mytest.t + +In addition, you may want to run the test in verbose mode to get more +informative output: + + ./Build test --test_files t/mytest.t --verbose 1 + +I run this so frequently that I define the following shell alias: + + alias t './Build test --verbose 1 --test_files' + +So then I can just execute C<t t/mytest.t> to run a single test. + + +=head1 ADVANCED RECIPES + + +=head2 Making a CPAN.pm-compatible distribution + +New versions of CPAN.pm understand how to use a F<Build.PL> script, +but old versions don't. If authors want to help users who have old +versions, some form of F<Makefile.PL> should be supplied. The easiest +way to accomplish this is to use the C<create_makefile_pl> parameter to +C<< Module::Build->new() >> in the C<Build.PL> script, which can +create various flavors of F<Makefile.PL> during the C<dist> action. + +As a best practice, we recommend using the "traditional" style of +F<Makefile.PL> unless your distribution has needs that can't be +accomplished that way. + +The C<Module::Build::Compat> module, which is part of +C<Module::Build>'s distribution, is responsible for creating these +F<Makefile.PL>s. Please see L<Module::Build::Compat> for the details. + + +=head2 Changing the order of the build process + +The C<build_elements> property specifies the steps C<Module::Build> +will take when building a distribution. To change the build order, +change the order of the entries in that property: + + # Process pod files first + my @e = @{$build->build_elements}; + my ($i) = grep {$e[$_] eq 'pod'} 0..$#e; + unshift @e, splice @e, $i, 1; + +Currently, C<build_elements> has the following default value: + + [qw( PL support pm xs pod script )] + +Do take care when altering this property, since there may be +non-obvious (and non-documented!) ordering dependencies in the +C<Module::Build> code. + + +=head2 Adding new file types to the build process + +Sometimes you might have extra types of files that you want to install +alongside the standard types like F<.pm> and F<.pod> files. For +instance, you might have a F<Bar.dat> file containing some data +related to the C<Foo::Bar> module and you'd like for it to end up as +F<Foo/Bar.dat> somewhere in perl's C<@INC> path so C<Foo::Bar> can +access it easily at runtime. The following code from a sample +C<Build.PL> file demonstrates how to accomplish this: + + use Module::Build; + my $build = Module::Build->new + ( + module_name => 'Foo::Bar', + ...other stuff here... + ); + $build->add_build_element('dat'); + $build->create_build_script; + +This will find all F<.dat> files in the F<lib/> directory, copy them +to the F<blib/lib/> directory during the C<build> action, and install +them during the C<install> action. + +If your extra files aren't located in the C<lib/> directory in your +distribution, you can explicitly say where they are, just as you'd do +with F<.pm> or F<.pod> files: + + use Module::Build; + my $build = new Module::Build + ( + module_name => 'Foo::Bar', + dat_files => {'some/dir/Bar.dat' => 'lib/Foo/Bar.dat'}, + ...other stuff here... + ); + $build->add_build_element('dat'); + $build->create_build_script; + +If your extra files actually need to be created on the user's machine, +or if they need some other kind of special processing, you'll probably +want to subclass C<Module::Build> and create a special method to +process them, named C<process_${kind}_files()>: + + use Module::Build; + my $class = Module::Build->subclass(code => <<'EOF'); + sub process_dat_files { + my $self = shift; + ... locate and process *.dat files, + ... and create something in blib/lib/ + } + EOF + my $build = $class->new + ( + module_name => 'Foo::Bar', + ...other stuff here... + ); + $build->add_build_element('dat'); + $build->create_build_script; + +If your extra files don't go in F<lib/> but in some other place, see +L<"Adding new elements to the install process"> for how to actually +get them installed. + +Please note that these examples use some capabilities of Module::Build +that first appeared in version 0.26. Before that it could +still be done, but the simple cases took a bit more work. + + +=head2 Adding new elements to the install process + +By default, Module::Build creates seven subdirectories of the F<blib> +directory during the build process: F<lib>, F<arch>, F<bin>, +F<script>, F<bindoc>, F<libdoc>, and F<html> (some of these may be +missing or empty if there's nothing to go in them). Anything copied +to these directories during the build will eventually be installed +during the C<install> action (see L<Module::Build/"INSTALL PATHS">. + +If you need to create a new custom type of installable element, e.g. C<conf>, +then you need to tell Module::Build where things in F<blib/conf/> +should be installed. To do this, use the C<install_path> parameter to +the C<new()> method: + + my $build = Module::Build->new + ( + ...other stuff here... + install_path => { conf => $installation_path } + ); + +Or you can call the C<install_path()> method later: + + $build->install_path(conf => $installation_path); + +The user may also specify the path on the command line: + + perl Build.PL --install_path conf=/foo/path/etc + +The important part, though, is that I<somehow> the install path needs +to be set, or else nothing in the F<blib/conf/> directory will get +installed, and a runtime error during the C<install> action will +result. + +See also L<"Adding new file types to the build process"> for how to +create the stuff in F<blib/conf/> in the first place. + + +=head1 EXAMPLES ON CPAN + +Several distributions on CPAN are making good use of various features +of Module::Build. They can serve as real-world examples for others. + + +=head2 SVN-Notify-Mirror + +L<http://search.cpan.org/~jpeacock/SVN-Notify-Mirror/> + +John Peacock, author of the C<SVN-Notify-Mirror> distribution, says: + +=over 4 + +=item 1. Using C<auto_features>, I check to see whether two optional +modules are available - SVN::Notify::Config and Net::SSH; + +=item 2. If the S::N::Config module is loaded, I automatically +generate test files for it during Build (using the C<PL_files> +property). + +=item 3. If the C<ssh_feature> is available, I ask if the user wishes +to perform the ssh tests (since it requires a little preliminary +setup); + +=item 4. Only if the user has C<ssh_feature> and answers yes to the +testing, do I generate a test file. + +I'm sure I could not have handled this complexity with EU::MM, but it +was very easy to do with M::B. + +=back + + +=head2 Modifying an action + +Sometimes you might need an to have an action, say C<./Build install>, +do something unusual. For instance, you might need to change the +ownership of a file or do something else peculiar to your application. + +You can subclass C<Module::Build> on the fly using the C<subclass()> +method and override the methods that perform the actions. You may +need to read through C<Module::Build::Authoring> and +C<Module::Build::API> to find the methods you want to override. All +"action" methods are implemented by a method called "ACTION_" followed +by the action's name, so here's an example of how it would work for +the C<install> action: + + # Build.PL + use Module::Build; + my $class = Module::Build->subclass( + class => "Module::Build::Custom", + code => <<'SUBCLASS' ); + + sub ACTION_install { + my $self = shift; + # YOUR CODE HERE + $self->SUPER::ACTION_install; + } + SUBCLASS + + $class->new( + module_name => 'Your::Module', + # rest of the usual Module::Build parameters + )->create_build_script; + + +=head2 Adding an action + +You can add a new C<./Build> action simply by writing the method for +it in your subclass. Use C<depends_on> to declare that another action +must have been run before your action. + +For example, let's say you wanted to be able to write C<./Build +commit> to test your code and commit it to Subversion. + + # Build.PL + use Module::Build; + my $class = Module::Build->subclass( + class => "Module::Build::Custom", + code => <<'SUBCLASS' ); + + sub ACTION_commit { + my $self = shift; + + $self->depends_on("test"); + $self->do_system(qw(svn commit)); + } + SUBCLASS + + +=head2 Bundling Module::Build + +Note: This section probably needs an update as the technology improves +(see contrib/bundle.pl in the distribution). + +Suppose you want to use some new-ish features of Module::Build, +e.g. newer than the version of Module::Build your users are likely to +already have installed on their systems. The first thing you should +do is set C<configure_requires> to your minimum version of +Module::Build. See L<Module::Build::Authoring>. + +But not every build system honors C<configure_requires> yet. Here's +how you can ship a copy of Module::Build, but still use a newer +installed version to take advantage of any bug fixes and upgrades. + +First, install Module::Build into F<Your-Project/inc/Module-Build>. +CPAN will not index anything in the F<inc> directory so this copy will +not show up in CPAN searches. + + cd Module-Build + perl Build.PL --install_base /path/to/Your-Project/inc/Module-Build + ./Build test + ./Build install + +You should now have all the Module::Build .pm files in +F<Your-Project/inc/Module-Build/lib/perl5>. + +Next, add this to the top of your F<Build.PL>. + + my $Bundled_MB = 0.30; # or whatever version it was. + + # Find out what version of Module::Build is installed or fail quietly. + # This should be cross-platform. + my $Installed_MB = + `$^X -e "eval q{require Module::Build; print Module::Build->VERSION} or exit 1"; + + # some operating systems put a newline at the end of every print. + chomp $Installed_MB; + + $Installed_MB = 0 if $?; + + # Use our bundled copy of Module::Build if it's newer than the installed. + unshift @INC, "inc/Module-Build/lib/perl5" if $Bundled_MB > $Installed_MB; + + require Module::Build; + +And write the rest of your F<Build.PL> normally. Module::Build will +remember your change to C<@INC> and use it when you run F<./Build>. + +In the future, we hope to provide a more automated solution for this +scenario; see C<inc/latest.pm> in the Module::Build distribution for +one indication of the direction we're moving. + + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + + +=head1 COPYRIGHT + +Copyright (c) 2001-2008 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + + +=head1 SEE ALSO + +perl(1), L<Module::Build>(3), L<Module::Build::Authoring>(3), +L<Module::Build::API>(3) + +=cut diff --git a/lib/Module/Build/Dumper.pm b/lib/Module/Build/Dumper.pm new file mode 100644 index 0000000..af4994f --- /dev/null +++ b/lib/Module/Build/Dumper.pm @@ -0,0 +1,19 @@ +package Module::Build::Dumper; +use strict; +use warnings; +our $VERSION = '0.4214'; + +# This is just a split-out of a wrapper function to do Data::Dumper +# stuff "the right way". See: +# http://groups.google.com/group/perl.module.build/browse_thread/thread/c8065052b2e0d741 + +use Data::Dumper; + +sub _data_dump { + my ($self, $data) = @_; + return ("do{ my " + . Data::Dumper->new([$data],['x'])->Purity(1)->Terse(0)->Sortkeys(1)->Dump() + . '$x; }') +} + +1; diff --git a/lib/Module/Build/Notes.pm b/lib/Module/Build/Notes.pm new file mode 100644 index 0000000..e55a26d --- /dev/null +++ b/lib/Module/Build/Notes.pm @@ -0,0 +1,332 @@ +package Module::Build::Notes; + +# A class for persistent hashes + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Data::Dumper; +use Module::Build::Dumper; + +sub new { + my ($class, %args) = @_; + my $file = delete $args{file} or die "Missing required parameter 'file' to new()"; + my $self = bless { + disk => {}, + new => {}, + file => $file, + %args, + }, $class; +} + +sub restore { + my $self = shift; + + open(my $fh, '<', $self->{file}) or die "Can't read $self->{file}: $!"; + $self->{disk} = eval do {local $/; <$fh>}; + die $@ if $@; + close $fh; + $self->{new} = {}; +} + +sub access { + my $self = shift; + return $self->read() unless @_; + + my $key = shift; + return $self->read($key) unless @_; + + my $value = shift; + $self->write({ $key => $value }); + return $self->read($key); +} + +sub has_data { + my $self = shift; + return keys %{$self->read()} > 0; +} + +sub exists { + my ($self, $key) = @_; + return exists($self->{new}{$key}) || exists($self->{disk}{$key}); +} + +sub read { + my $self = shift; + + if (@_) { + # Return 1 key as a scalar + my $key = shift; + return $self->{new}{$key} if exists $self->{new}{$key}; + return $self->{disk}{$key}; + } + + # Return all data + my $out = (keys %{$self->{new}} + ? {%{$self->{disk}}, %{$self->{new}}} + : $self->{disk}); + return wantarray ? %$out : $out; +} + +sub _same { + my ($self, $x, $y) = @_; + return 1 if !defined($x) and !defined($y); + return 0 if !defined($x) or !defined($y); + return $x eq $y; +} + +sub write { + my ($self, $href) = @_; + $href ||= {}; + + @{$self->{new}}{ keys %$href } = values %$href; # Merge + + # Do some optimization to avoid unnecessary writes + foreach my $key (keys %{ $self->{new} }) { + next if ref $self->{new}{$key}; + next if ref $self->{disk}{$key} or !exists $self->{disk}{$key}; + delete $self->{new}{$key} if $self->_same($self->{new}{$key}, $self->{disk}{$key}); + } + + if (my $file = $self->{file}) { + my ($vol, $dir, $base) = File::Spec->splitpath($file); + $dir = File::Spec->catpath($vol, $dir, ''); + return unless -e $dir && -d $dir; # The user needs to arrange for this + + return if -e $file and !keys %{ $self->{new} }; # Nothing to do + + @{$self->{disk}}{ keys %{$self->{new}} } = values %{$self->{new}}; # Merge + $self->_dump($file, $self->{disk}); + + $self->{new} = {}; + } + return $self->read; +} + +sub _dump { + my ($self, $file, $data) = @_; + + open(my $fh, '>', $file) or die "Can't create '$file': $!"; + print {$fh} Module::Build::Dumper->_data_dump($data); + close $fh; +} + +my $orig_template = do { local $/; <DATA> }; +close DATA; + +sub write_config_data { + my ($self, %args) = @_; + + my $template = $orig_template; + $template =~ s/NOTES_NAME/$args{config_module}/g; + $template =~ s/MODULE_NAME/$args{module}/g; + $template =~ s/=begin private\n//; + $template =~ s/=end private/=cut/; + + # strip out private POD markers we use to keep pod from being + # recognized for *this* source file + $template =~ s{$_\n}{} for '=begin private', '=end private'; + + open(my $fh, '>', $args{file}) or die "Can't create '$args{file}': $!"; + print {$fh} $template; + print {$fh} "\n__DATA__\n"; + print {$fh} Module::Build::Dumper->_data_dump([$args{config_data}, $args{feature}, $args{auto_features}]); + close $fh; +} + +1; + + +=head1 NAME + +Module::Build::Notes - Create persistent distribution configuration modules + +=head1 DESCRIPTION + +This module is used internally by Module::Build to create persistent +configuration files that can be installed with a distribution. See +L<Module::Build::ConfigData> for an example. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + +=head1 SEE ALSO + +perl(1), L<Module::Build>(3) + +=cut + +__DATA__ +package NOTES_NAME; +use strict; +my $arrayref = eval do {local $/; <DATA>} + or die "Couldn't load ConfigData data: $@"; +close DATA; +my ($config, $features, $auto_features) = @$arrayref; + +sub config { $config->{$_[1]} } + +sub set_config { $config->{$_[1]} = $_[2] } +sub set_feature { $features->{$_[1]} = 0+!!$_[2] } # Constrain to 1 or 0 + +sub auto_feature_names { grep !exists $features->{$_}, keys %$auto_features } + +sub feature_names { + my @features = (keys %$features, auto_feature_names()); + @features; +} + +sub config_names { keys %$config } + +sub write { + my $me = __FILE__; + + # Can't use Module::Build::Dumper here because M::B is only a + # build-time prereq of this module + require Data::Dumper; + + my $mode_orig = (stat $me)[2] & 07777; + chmod($mode_orig | 0222, $me); # Make it writeable + open(my $fh, '+<', $me) or die "Can't rewrite $me: $!"; + seek($fh, 0, 0); + while (<$fh>) { + last if /^__DATA__$/; + } + die "Couldn't find __DATA__ token in $me" if eof($fh); + + seek($fh, tell($fh), 0); + my $data = [$config, $features, $auto_features]; + print($fh 'do{ my ' + . Data::Dumper->new([$data],['x'])->Purity(1)->Dump() + . '$x; }' ); + truncate($fh, tell($fh)); + close $fh; + + chmod($mode_orig, $me) + or warn "Couldn't restore permissions on $me: $!"; +} + +sub feature { + my ($package, $key) = @_; + return $features->{$key} if exists $features->{$key}; + + my $info = $auto_features->{$key} or return 0; + + # Under perl 5.005, each(%$foo) isn't working correctly when $foo + # was reanimated with Data::Dumper and eval(). Not sure why, but + # copying to a new hash seems to solve it. + my %info = %$info; + + require Module::Build; # XXX should get rid of this + while (my ($type, $prereqs) = each %info) { + next if $type eq 'description' || $type eq 'recommends'; + + my %p = %$prereqs; # Ditto here. + while (my ($modname, $spec) = each %p) { + my $status = Module::Build->check_installed_status($modname, $spec); + if ((!$status->{ok}) xor ($type =~ /conflicts$/)) { return 0; } + if ( ! eval "require $modname; 1" ) { return 0; } + } + } + return 1; +} + +=begin private + +=head1 NAME + +NOTES_NAME - Configuration for MODULE_NAME + +=head1 SYNOPSIS + + use NOTES_NAME; + $value = NOTES_NAME->config('foo'); + $value = NOTES_NAME->feature('bar'); + + @names = NOTES_NAME->config_names; + @names = NOTES_NAME->feature_names; + + NOTES_NAME->set_config(foo => $new_value); + NOTES_NAME->set_feature(bar => $new_value); + NOTES_NAME->write; # Save changes + + +=head1 DESCRIPTION + +This module holds the configuration data for the C<MODULE_NAME> +module. It also provides a programmatic interface for getting or +setting that configuration data. Note that in order to actually make +changes, you'll have to have write access to the C<NOTES_NAME> +module, and you should attempt to understand the repercussions of your +actions. + + +=head1 METHODS + +=over 4 + +=item config($name) + +Given a string argument, returns the value of the configuration item +by that name, or C<undef> if no such item exists. + +=item feature($name) + +Given a string argument, returns the value of the feature by that +name, or C<undef> if no such feature exists. + +=item set_config($name, $value) + +Sets the configuration item with the given name to the given value. +The value may be any Perl scalar that will serialize correctly using +C<Data::Dumper>. This includes references, objects (usually), and +complex data structures. It probably does not include transient +things like filehandles or sockets. + +=item set_feature($name, $value) + +Sets the feature with the given name to the given boolean value. The +value will be converted to 0 or 1 automatically. + +=item config_names() + +Returns a list of all the names of config items currently defined in +C<NOTES_NAME>, or in scalar context the number of items. + +=item feature_names() + +Returns a list of all the names of features currently defined in +C<NOTES_NAME>, or in scalar context the number of features. + +=item auto_feature_names() + +Returns a list of all the names of features whose availability is +dynamically determined, or in scalar context the number of such +features. Does not include such features that have later been set to +a fixed value. + +=item write() + +Commits any changes from C<set_config()> and C<set_feature()> to disk. +Requires write access to the C<NOTES_NAME> module. + +=back + + +=head1 AUTHOR + +C<NOTES_NAME> was automatically created using C<Module::Build>. +C<Module::Build> was written by Ken Williams, but he holds no +authorship claim or copyright claim to the contents of C<NOTES_NAME>. + +=end private + diff --git a/lib/Module/Build/PPMMaker.pm b/lib/Module/Build/PPMMaker.pm new file mode 100644 index 0000000..2e6941c --- /dev/null +++ b/lib/Module/Build/PPMMaker.pm @@ -0,0 +1,186 @@ +package Module::Build::PPMMaker; + +use strict; +use warnings; +use Config; + +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; + +# This code is mostly borrowed from ExtUtils::MM_Unix 6.10_03, with a +# few tweaks based on the PPD spec at +# http://www.xav.com/perl/site/lib/XML/PPD.html + +# The PPD spec is based on <http://www.w3.org/TR/NOTE-OSD> + +sub new { + my $package = shift; + return bless {@_}, $package; +} + +sub make_ppd { + my ($self, %args) = @_; + my $build = delete $args{build}; + + my @codebase; + if (exists $args{codebase}) { + @codebase = ref $args{codebase} ? @{$args{codebase}} : ($args{codebase}); + } else { + my $distfile = $build->ppm_name . '.tar.gz'; + print "Using default codebase '$distfile'\n"; + @codebase = ($distfile); + } + + my %dist; + foreach my $info (qw(name author abstract version)) { + my $method = "dist_$info"; + $dist{$info} = $build->$method() or die "Can't determine distribution's $info\n"; + } + + $self->_simple_xml_escape($_) foreach $dist{abstract}, @{$dist{author}}; + + # TODO: could add <LICENSE HREF=...> tag if we knew what the URLs were for + # various licenses + my $ppd = <<"PPD"; +<SOFTPKG NAME=\"$dist{name}\" VERSION=\"$dist{version}\"> + <ABSTRACT>$dist{abstract}</ABSTRACT> +@{[ join "\n", map " <AUTHOR>$_</AUTHOR>", @{$dist{author}} ]} + <IMPLEMENTATION> +PPD + + # We don't include recommended dependencies because PPD has no way + # to distinguish them from normal dependencies. We don't include + # build_requires dependencies because the PPM installer doesn't + # build or test before installing. And obviously we don't include + # conflicts either. + + foreach my $type (qw(requires)) { + my $prereq = $build->$type(); + while (my ($modname, $spec) = each %$prereq) { + next if $modname eq 'perl'; + + my $min_version = '0.0'; + foreach my $c ($build->_parse_conditions($spec)) { + my ($op, $version) = $c =~ /^\s* (<=?|>=?|==|!=) \s* ([\w.]+) \s*$/x; + + # This is a nasty hack because it fails if there is no >= op + if ($op eq '>=') { + $min_version = $version; + last; + } + } + + # PPM4 spec requires a '::' for top level modules + $modname .= '::' unless $modname =~ /::/; + + $ppd .= qq! <REQUIRE NAME="$modname" VERSION="$min_version" />\n!; + } + } + + # We only include these tags if this module involves XS, on the + # assumption that pure Perl modules will work on any OS. + if (keys %{$build->find_xs_files}) { + my $perl_version = $self->_ppd_version($build->perl_version); + $ppd .= sprintf(<<'EOF', $self->_varchname($build->config) ); + <ARCHITECTURE NAME="%s" /> +EOF + } + + foreach my $codebase (@codebase) { + $self->_simple_xml_escape($codebase); + $ppd .= sprintf(<<'EOF', $codebase); + <CODEBASE HREF="%s" /> +EOF + } + + $ppd .= <<'EOF'; + </IMPLEMENTATION> +</SOFTPKG> +EOF + + my $ppd_file = "$dist{name}.ppd"; + open(my $fh, '>', $ppd_file) + or die "Cannot write to $ppd_file: $!"; + + binmode($fh, ":utf8") + if $] >= 5.008 && $Config{useperlio}; + print $fh $ppd; + close $fh; + + return $ppd_file; +} + +sub _ppd_version { + my ($self, $version) = @_; + + # generates something like "0,18,0,0" + return join ',', (split(/\./, $version), (0)x4)[0..3]; +} + +sub _varchname { # Copied from PPM.pm + my ($self, $config) = @_; + my $varchname = $config->{archname}; + # Append "-5.8" to architecture name for Perl 5.8 and later + if ($] >= 5.008) { + my $vstring = sprintf "%vd", $^V; + $vstring =~ s/\.\d+$//; + $varchname .= "-$vstring"; + } + return $varchname; +} + +{ + my %escapes = ( + "\n" => "\\n", + '"' => '"', + '&' => '&', + '>' => '>', + '<' => '<', + ); + my $rx = join '|', keys %escapes; + + sub _simple_xml_escape { + $_[1] =~ s/($rx)/$escapes{$1}/go; + } +} + +1; +__END__ + + +=head1 NAME + +Module::Build::PPMMaker - Perl Package Manager file creation + +=head1 SYNOPSIS + + On the command line, builds a .ppd file: + ./Build ppd + + +=head1 DESCRIPTION + +This package contains the code that builds F<.ppd> "Perl Package +Description" files, in support of ActiveState's "Perl Package +Manager". Details are here: +L<http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/> + + +=head1 AUTHOR + +Dave Rolsky <autarch@urth.org>, Ken Williams <kwilliams@cpan.org> + + +=head1 COPYRIGHT + +Copyright (c) 2001-2006 Ken Williams. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the same terms as Perl itself. + + +=head1 SEE ALSO + +perl(1), Module::Build(3) + +=cut diff --git a/lib/Module/Build/Platform/Default.pm b/lib/Module/Build/Platform/Default.pm new file mode 100644 index 0000000..562420b --- /dev/null +++ b/lib/Module/Build/Platform/Default.pm @@ -0,0 +1,32 @@ +package Module::Build::Platform::Default; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Base; + +our @ISA = qw(Module::Build::Base); + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::Default - Stub class for unknown platforms + +=head1 DESCRIPTION + +The sole purpose of this module is to inherit from +C<Module::Build::Base>. Please see the L<Module::Build> for the docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/MacOS.pm b/lib/Module/Build/Platform/MacOS.pm new file mode 100644 index 0000000..55d73f5 --- /dev/null +++ b/lib/Module/Build/Platform/MacOS.pm @@ -0,0 +1,151 @@ +package Module::Build::Platform::MacOS; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Base; +our @ISA = qw(Module::Build::Base); + +use ExtUtils::Install; + +sub have_forkpipe { 0 } + +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + + # $Config{sitelib} and $Config{sitearch} are, unfortunately, missing. + foreach ('sitelib', 'sitearch') { + $self->config($_ => $self->config("install$_")) + unless $self->config($_); + } + + # For some reason $Config{startperl} is filled with a bunch of crap. + (my $sp = $self->config('startperl')) =~ s/.*Exit \{Status\}\s//; + $self->config(startperl => $sp); + + return $self; +} + +sub make_executable { + my $self = shift; + require MacPerl; + foreach (@_) { + MacPerl::SetFileInfo('McPL', 'TEXT', $_); + } +} + +sub dispatch { + my $self = shift; + + if( !@_ and !@ARGV ) { + require MacPerl; + + # What comes first in the action list. + my @action_list = qw(build test install); + my %actions = map {+($_, 1)} $self->known_actions; + delete @actions{@action_list}; + push @action_list, sort { $a cmp $b } keys %actions; + + my %toolserver = map {+$_ => 1} qw(test disttest diff testdb); + foreach (@action_list) { + $_ .= ' *' if $toolserver{$_}; + } + + my $cmd = MacPerl::Pick("What build command? ('*' requires ToolServer)", @action_list); + return unless defined $cmd; + $cmd =~ s/ \*$//; + $ARGV[0] = ($cmd); + + my $args = MacPerl::Ask('Any extra arguments? (ie. verbose=1)', ''); + return unless defined $args; + push @ARGV, $self->split_like_shell($args); + } + + $self->SUPER::dispatch(@_); +} + +sub ACTION_realclean { + my $self = shift; + chmod 0666, $self->{properties}{build_script}; + $self->SUPER::ACTION_realclean; +} + +# ExtUtils::Install has a hard-coded '.' directory in versions less +# than 1.30. We use a sneaky trick to turn that into ':'. +# +# Note that we do it here in a cross-platform way, so this code could +# actually go in Module::Build::Base. But we put it here to be less +# intrusive for other platforms. + +sub ACTION_install { + my $self = shift; + + return $self->SUPER::ACTION_install(@_) + if eval {ExtUtils::Install->VERSION('1.30'); 1}; + + local $^W = 0; # Avoid a 'redefine' warning + local *ExtUtils::Install::find = sub { + my ($code, @dirs) = @_; + + @dirs = map { $_ eq '.' ? File::Spec->curdir : $_ } @dirs; + + return File::Find::find($code, @dirs); + }; + + return $self->SUPER::ACTION_install(@_); +} + +1; +__END__ + +=head1 NAME + +Module::Build::Platform::MacOS - Builder class for MacOS platforms + +=head1 DESCRIPTION + +The sole purpose of this module is to inherit from +C<Module::Build::Base> and override a few methods. Please see +L<Module::Build> for the docs. + +=head2 Overridden Methods + +=over 4 + +=item new() + +MacPerl doesn't define $Config{sitelib} or $Config{sitearch} for some +reason, but $Config{installsitelib} and $Config{installsitearch} are +there. So we copy the install variables to the other location + +=item make_executable() + +On MacOS we set the file type and creator to MacPerl so it will run +with a double-click. + +=item dispatch() + +Because there's no easy way to say "./Build test" on MacOS, if +dispatch is called with no arguments and no @ARGV a dialog box will +pop up asking what action to take and any extra arguments. + +Default action is "test". + +=item ACTION_realclean() + +Need to unlock the Build program before deleting. + +=back + +=head1 AUTHOR + +Michael G Schwern <schwern@pobox.com> + + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/Unix.pm b/lib/Module/Build/Platform/Unix.pm new file mode 100644 index 0000000..f3cc511 --- /dev/null +++ b/lib/Module/Build/Platform/Unix.pm @@ -0,0 +1,72 @@ +package Module::Build::Platform::Unix; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Base; + +our @ISA = qw(Module::Build::Base); + +sub is_executable { + # We consider the owner bit to be authoritative on a file, because + # -x will always return true if the user is root and *any* + # executable bit is set. The -x test seems to try to answer the + # question "can I execute this file", but I think we want "is this + # file executable". + + my ($self, $file) = @_; + return +(stat $file)[2] & 0100; +} + +sub _startperl { "#! " . shift()->perl } + +sub _construct { + my $self = shift()->SUPER::_construct(@_); + + # perl 5.8.1-RC[1-3] had some broken %Config entries, and + # unfortunately Red Hat 9 shipped it like that. Fix 'em up here. + my $c = $self->{config}; + for (qw(siteman1 siteman3 vendorman1 vendorman3)) { + $c->{"install${_}dir"} ||= $c->{"install${_}"}; + } + + return $self; +} + +# Open group says username should be portable filename characters, +# but some Unix OS working with ActiveDirectory wind up with user-names +# with back-slashes in the name. The new code below is very liberal +# in what it accepts. +sub _detildefy { + my ($self, $value) = @_; + $value =~ s[^~([^/]+)?(?=/|$)] # tilde with optional username + [$1 ? + (eval{(getpwnam $1)[7]} || "~$1") : + ($ENV{HOME} || eval{(getpwuid $>)[7]} || glob("~")) + ]ex; + return $value; +} + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::Unix - Builder class for Unix platforms + +=head1 DESCRIPTION + +The sole purpose of this module is to inherit from +C<Module::Build::Base>. Please see the L<Module::Build> for the docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/VMS.pm b/lib/Module/Build/Platform/VMS.pm new file mode 100644 index 0000000..ebe8c6c --- /dev/null +++ b/lib/Module/Build/Platform/VMS.pm @@ -0,0 +1,522 @@ +package Module::Build::Platform::VMS; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Base; +use Config; + +our @ISA = qw(Module::Build::Base); + + + +=head1 NAME + +Module::Build::Platform::VMS - Builder class for VMS platforms + +=head1 DESCRIPTION + +This module inherits from C<Module::Build::Base> and alters a few +minor details of its functionality. Please see L<Module::Build> for +the general docs. + +=head2 Overridden Methods + +=over 4 + +=item _set_defaults + +Change $self->{build_script} to 'Build.com' so @Build works. + +=cut + +sub _set_defaults { + my $self = shift; + $self->SUPER::_set_defaults(@_); + + $self->{properties}{build_script} = 'Build.com'; +} + + +=item cull_args + +'@Build foo' on VMS will not preserve the case of 'foo'. Rather than forcing +people to write '@Build "foo"' we'll dispatch case-insensitively. + +=cut + +sub cull_args { + my $self = shift; + my($action, $args) = $self->SUPER::cull_args(@_); + my @possible_actions = grep { lc $_ eq lc $action } $self->known_actions; + + die "Ambiguous action '$action'. Could be one of @possible_actions" + if @possible_actions > 1; + + return ($possible_actions[0], $args); +} + + +=item manpage_separator + +Use '__' instead of '::'. + +=cut + +sub manpage_separator { + return '__'; +} + + +=item prefixify + +Prefixify taking into account VMS' filepath syntax. + +=cut + +# Translated from ExtUtils::MM_VMS::prefixify() + +sub _catprefix { + my($self, $rprefix, $default) = @_; + + my($rvol, $rdirs) = File::Spec->splitpath($rprefix); + if( $rvol ) { + return File::Spec->catpath($rvol, + File::Spec->catdir($rdirs, $default), + '' + ) + } + else { + return File::Spec->catdir($rdirs, $default); + } +} + + +sub _prefixify { + my($self, $path, $sprefix, $type) = @_; + my $rprefix = $self->prefix; + + return '' unless defined $path; + + $self->log_verbose(" prefixify $path from $sprefix to $rprefix\n"); + + # Translate $(PERLPREFIX) to a real path. + $rprefix = VMS::Filespec::vmspath($rprefix) if $rprefix; + $sprefix = VMS::Filespec::vmspath($sprefix) if $sprefix; + + $self->log_verbose(" rprefix translated to $rprefix\n". + " sprefix translated to $sprefix\n"); + + if( length($path) == 0 ) { + $self->log_verbose(" no path to prefixify.\n") + } + elsif( !File::Spec->file_name_is_absolute($path) ) { + $self->log_verbose(" path is relative, not prefixifying.\n"); + } + elsif( $sprefix eq $rprefix ) { + $self->log_verbose(" no new prefix.\n"); + } + else { + my($path_vol, $path_dirs) = File::Spec->splitpath( $path ); + my $vms_prefix = $self->config('vms_prefix'); + if( $path_vol eq $vms_prefix.':' ) { + $self->log_verbose(" $vms_prefix: seen\n"); + + $path_dirs =~ s{^\[}{\[.} unless $path_dirs =~ m{^\[\.}; + $path = $self->_catprefix($rprefix, $path_dirs); + } + else { + $self->log_verbose(" cannot prefixify.\n"); + return $self->prefix_relpaths($self->installdirs, $type); + } + } + + $self->log_verbose(" now $path\n"); + + return $path; +} + +=item _quote_args + +Command-line arguments (but not the command itself) must be quoted +to ensure case preservation. + +=cut + +sub _quote_args { + # Returns a string that can become [part of] a command line with + # proper quoting so that the subprocess sees this same list of args, + # or if we get a single arg that is an array reference, quote the + # elements of it and return the reference. + my ($self, @args) = @_; + my $got_arrayref = (scalar(@args) == 1 + && ref $args[0] eq 'ARRAY') + ? 1 + : 0; + + # Do not quote qualifiers that begin with '/'. + map { if (!/^\//) { + $_ =~ s/\"/""/g; # escape C<"> by doubling + $_ = q(").$_.q("); + } + } + ($got_arrayref ? @{$args[0]} + : @args + ); + + return $got_arrayref ? $args[0] + : join(' ', @args); +} + +=item have_forkpipe + +There is no native fork(), so some constructs depending on it are not +available. + +=cut + +sub have_forkpipe { 0 } + +=item _backticks + +Override to ensure that we quote the arguments but not the command. + +=cut + +sub _backticks { + # The command must not be quoted but the arguments to it must be. + my ($self, @cmd) = @_; + my $cmd = shift @cmd; + my $args = $self->_quote_args(@cmd); + return `$cmd $args`; +} + +=item find_command + +Local an executable program + +=cut + +sub find_command { + my ($self, $command) = @_; + + # a lot of VMS executables have a symbol defined + # check those first + if ( $^O eq 'VMS' ) { + require VMS::DCLsym; + my $syms = VMS::DCLsym->new; + return $command if scalar $syms->getsym( uc $command ); + } + + $self->SUPER::find_command($command); +} + +# _maybe_command copied from ExtUtils::MM_VMS::maybe_command + +=item _maybe_command (override) + +Follows VMS naming conventions for executable files. +If the name passed in doesn't exactly match an executable file, +appends F<.Exe> (or equivalent) to check for executable image, and F<.Com> +to check for DCL procedure. If this fails, checks directories in DCL$PATH +and finally F<Sys$System:> for an executable file having the name specified, +with or without the F<.Exe>-equivalent suffix. + +=cut + +sub _maybe_command { + my($self,$file) = @_; + return $file if -x $file && ! -d _; + my(@dirs) = (''); + my(@exts) = ('',$Config{'exe_ext'},'.exe','.com'); + + if ($file !~ m![/:>\]]!) { + for (my $i = 0; defined $ENV{"DCL\$PATH;$i"}; $i++) { + my $dir = $ENV{"DCL\$PATH;$i"}; + $dir .= ':' unless $dir =~ m%[\]:]$%; + push(@dirs,$dir); + } + push(@dirs,'Sys$System:'); + foreach my $dir (@dirs) { + my $sysfile = "$dir$file"; + foreach my $ext (@exts) { + return $file if -x "$sysfile$ext" && ! -d _; + } + } + } + return; +} + +=item do_system + +Override to ensure that we quote the arguments but not the command. + +=cut + +sub do_system { + # The command must not be quoted but the arguments to it must be. + my ($self, @cmd) = @_; + $self->log_verbose("@cmd\n"); + my $cmd = shift @cmd; + my $args = $self->_quote_args(@cmd); + return !system("$cmd $args"); +} + +=item oneliner + +Override to ensure that we do not quote the command. + +=cut + +sub oneliner { + my $self = shift; + my $oneliner = $self->SUPER::oneliner(@_); + + $oneliner =~ s/^\"\S+\"//; + + return "MCR $^X $oneliner"; +} + +=item rscan_dir + +Inherit the standard version but remove dots at end of name. +If the extended character set is in effect, do not remove dots from filenames +with Unix path delimiters. + +=cut + +sub rscan_dir { + my ($self, $dir, $pattern) = @_; + + my $result = $self->SUPER::rscan_dir( $dir, $pattern ); + + for my $file (@$result) { + if (!_efs() && ($file =~ m#/#)) { + $file =~ s/\.$//; + } + } + return $result; +} + +=item dist_dir + +Inherit the standard version but replace embedded dots with underscores because +a dot is the directory delimiter on VMS. + +=cut + +sub dist_dir { + my $self = shift; + + my $dist_dir = $self->SUPER::dist_dir; + $dist_dir =~ s/\./_/g unless _efs(); + return $dist_dir; +} + +=item man3page_name + +Inherit the standard version but chop the extra manpage delimiter off the front if +there is one. The VMS version of splitdir('[.foo]') returns '', 'foo'. + +=cut + +sub man3page_name { + my $self = shift; + + my $mpname = $self->SUPER::man3page_name( shift ); + my $sep = $self->manpage_separator; + $mpname =~ s/^$sep//; + return $mpname; +} + +=item expand_test_dir + +Inherit the standard version but relativize the paths as the native glob() doesn't +do that for us. + +=cut + +sub expand_test_dir { + my ($self, $dir) = @_; + + my @reldirs = $self->SUPER::expand_test_dir( $dir ); + + for my $eachdir (@reldirs) { + my ($v,$d,$f) = File::Spec->splitpath( $eachdir ); + my $reldir = File::Spec->abs2rel( File::Spec->catpath( $v, $d, '' ) ); + $eachdir = File::Spec->catfile( $reldir, $f ); + } + return @reldirs; +} + +=item _detildefy + +The home-grown glob() does not currently handle tildes, so provide limited support +here. Expect only UNIX format file specifications for now. + +=cut + +sub _detildefy { + my ($self, $arg) = @_; + + # Apparently double ~ are not translated. + return $arg if ($arg =~ /^~~/); + + # Apparently ~ followed by whitespace are not translated. + return $arg if ($arg =~ /^~ /); + + if ($arg =~ /^~/) { + my $spec = $arg; + + # Remove the tilde + $spec =~ s/^~//; + + # Remove any slash following the tilde if present. + $spec =~ s#^/##; + + # break up the paths for the merge + my $home = VMS::Filespec::unixify($ENV{HOME}); + + # In the default VMS mode, the trailing slash is present. + # In Unix report mode it is not. The parsing logic assumes that + # it is present. + $home .= '/' unless $home =~ m#/$#; + + # Trivial case of just ~ by it self + if ($spec eq '') { + $home =~ s#/$##; + return $home; + } + + my ($hvol, $hdir, $hfile) = File::Spec::Unix->splitpath($home); + if ($hdir eq '') { + # Someone has tampered with $ENV{HOME} + # So hfile is probably the directory since this should be + # a path. + $hdir = $hfile; + } + + my ($vol, $dir, $file) = File::Spec::Unix->splitpath($spec); + + my @hdirs = File::Spec::Unix->splitdir($hdir); + my @dirs = File::Spec::Unix->splitdir($dir); + + unless ($arg =~ m#^~/#) { + # There is a home directory after the tilde, but it will already + # be present in in @hdirs so we need to remove it by from @dirs. + + shift @dirs; + } + my $newdirs = File::Spec::Unix->catdir(@hdirs, @dirs); + + $arg = File::Spec::Unix->catpath($hvol, $newdirs, $file); + } + return $arg; + +} + +=item find_perl_interpreter + +On VMS, $^X returns the fully qualified absolute path including version +number. It's logically impossible to improve on it for getting the perl +we're currently running, and attempting to manipulate it is usually +lossy. + +=cut + +sub find_perl_interpreter { + return VMS::Filespec::vmsify($^X); +} + +=item localize_file_path + +Convert the file path to the local syntax + +=cut + +sub localize_file_path { + my ($self, $path) = @_; + $path = VMS::Filespec::vmsify($path); + $path =~ s/\.\z//; + return $path; +} + +=item localize_dir_path + +Convert the directory path to the local syntax + +=cut + +sub localize_dir_path { + my ($self, $path) = @_; + return VMS::Filespec::vmspath($path); +} + +=item ACTION_clean + +The home-grown glob() expands a bit too aggressively when given a bare name, +so default in a zero-length extension. + +=cut + +sub ACTION_clean { + my ($self) = @_; + foreach my $item (map glob(VMS::Filespec::rmsexpand($_, '.;0')), $self->cleanup) { + $self->delete_filetree($item); + } +} + + +# Need to look up the feature settings. The preferred way is to use the +# VMS::Feature module, but that may not be available to dual life modules. + +my $use_feature; +BEGIN { + if (eval { local $SIG{__DIE__}; require VMS::Feature; }) { + $use_feature = 1; + } +} + +# Need to look up the UNIX report mode. This may become a dynamic mode +# in the future. +sub _unix_rpt { + my $unix_rpt; + if ($use_feature) { + $unix_rpt = VMS::Feature::current("filename_unix_report"); + } else { + my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; + $unix_rpt = $env_unix_rpt =~ /^[ET1]/i; + } + return $unix_rpt; +} + +# Need to look up the EFS character set mode. This may become a dynamic +# mode in the future. +sub _efs { + my $efs; + if ($use_feature) { + $efs = VMS::Feature::current("efs_charset"); + } else { + my $env_efs = $ENV{'DECC$EFS_CHARSET'} || ''; + $efs = $env_efs =~ /^[ET1]/i; + } + return $efs; +} + +=back + +=head1 AUTHOR + +Michael G Schwern <schwern@pobox.com> +Ken Williams <kwilliams@cpan.org> +Craig A. Berry <craigberry@mac.com> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut + +1; +__END__ diff --git a/lib/Module/Build/Platform/VOS.pm b/lib/Module/Build/Platform/VOS.pm new file mode 100644 index 0000000..786073a --- /dev/null +++ b/lib/Module/Build/Platform/VOS.pm @@ -0,0 +1,33 @@ +package Module::Build::Platform::VOS; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Base; + +our @ISA = qw(Module::Build::Base); + + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::VOS - Builder class for VOS platforms + +=head1 DESCRIPTION + +The sole purpose of this module is to inherit from +C<Module::Build::Base>. Please see the L<Module::Build> for the docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/Windows.pm b/lib/Module/Build/Platform/Windows.pm new file mode 100644 index 0000000..4f65507 --- /dev/null +++ b/lib/Module/Build/Platform/Windows.pm @@ -0,0 +1,318 @@ +package Module::Build::Platform::Windows; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; + +use Config; +use File::Basename; +use File::Spec; + +use Module::Build::Base; + +our @ISA = qw(Module::Build::Base); + + +sub manpage_separator { + return '.'; +} + +sub have_forkpipe { 0 } + +sub _detildefy { + my ($self, $value) = @_; + $value =~ s,^~(?= [/\\] | $ ),$ENV{HOME},x + if $ENV{HOME}; + return $value; +} + +sub ACTION_realclean { + my ($self) = @_; + + $self->SUPER::ACTION_realclean(); + + my $basename = basename($0); + $basename =~ s/(?:\.bat)?$//i; + + if ( lc $basename eq lc $self->build_script ) { + if ( $self->build_bat ) { + $self->log_verbose("Deleting $basename.bat\n"); + my $full_progname = $0; + $full_progname =~ s/(?:\.bat)?$/.bat/i; + + # Voodoo required to have a batch file delete itself without error; + # Syntax differs between 9x & NT: the later requires a null arg (???) + require Win32; + my $null_arg = (Win32::IsWinNT()) ? '""' : ''; + my $cmd = qq(start $null_arg /min "\%comspec\%" /c del "$full_progname"); + + open(my $fh, '>>', "$basename.bat") + or die "Can't create $basename.bat: $!"; + print $fh $cmd; + close $fh ; + } else { + $self->delete_filetree($self->build_script . '.bat'); + } + } +} + +sub make_executable { + my $self = shift; + + $self->SUPER::make_executable(@_); + + foreach my $script (@_) { + + # Native batch script + if ( $script =~ /\.(bat|cmd)$/ ) { + $self->SUPER::make_executable($script); + next; + + # Perl script that needs to be wrapped in a batch script + } else { + my %opts = (); + if ( $script eq $self->build_script ) { + $opts{ntargs} = q(-x -S %0 --build_bat %*); + $opts{otherargs} = q(-x -S "%0" --build_bat %1 %2 %3 %4 %5 %6 %7 %8 %9); + } + + my $out = eval {$self->pl2bat(in => $script, update => 1, %opts)}; + if ( $@ ) { + $self->log_warn("WARNING: Unable to convert file '$script' to an executable script:\n$@"); + } else { + $self->SUPER::make_executable($out); + } + } + } +} + +# This routine was copied almost verbatim from the 'pl2bat' utility +# distributed with perl. It requires too much voodoo with shell quoting +# differences and shortcomings between the various flavors of Windows +# to reliably shell out +sub pl2bat { + my $self = shift; + my %opts = @_; + + # NOTE: %0 is already enclosed in doublequotes by cmd.exe, as appropriate + $opts{ntargs} = '-x -S %0 %*' unless exists $opts{ntargs}; + $opts{otherargs} = '-x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9' unless exists $opts{otherargs}; + + $opts{stripsuffix} = '/\\.plx?/' unless exists $opts{stripsuffix}; + $opts{stripsuffix} = ($opts{stripsuffix} =~ m{^/([^/]*[^/\$]|)\$?/?$} ? $1 : "\Q$opts{stripsuffix}\E"); + + unless (exists $opts{out}) { + $opts{out} = $opts{in}; + $opts{out} =~ s/$opts{stripsuffix}$//oi; + $opts{out} .= '.bat' unless $opts{in} =~ /\.bat$/i or $opts{in} =~ /^-$/; + } + + my $head = <<EOT; + \@rem = '--*-Perl-*-- + \@echo off + if "%OS%" == "Windows_NT" goto WinNT + perl $opts{otherargs} + goto endofperl + :WinNT + perl $opts{ntargs} + if NOT "%COMSPEC%" == "%SystemRoot%\\system32\\cmd.exe" goto endofperl + if %errorlevel% == 9009 echo You do not have Perl in your PATH. + if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul + goto endofperl + \@rem '; +EOT + + $head =~ s/^\s+//gm; + my $headlines = 2 + ($head =~ tr/\n/\n/); + my $tail = "\n__END__\n:endofperl\n"; + + my $linedone = 0; + my $taildone = 0; + my $linenum = 0; + my $skiplines = 0; + + my $start = $Config{startperl}; + $start = "#!perl" unless $start =~ /^#!.*perl/; + + open(my $in, '<', "$opts{in}") or die "Can't open $opts{in}: $!"; + my @file = <$in>; + close($in); + + foreach my $line ( @file ) { + $linenum++; + if ( $line =~ /^:endofperl\b/ ) { + if (!exists $opts{update}) { + warn "$opts{in} has already been converted to a batch file!\n"; + return; + } + $taildone++; + } + if ( not $linedone and $line =~ /^#!.*perl/ ) { + if (exists $opts{update}) { + $skiplines = $linenum - 1; + $line .= "#line ".(1+$headlines)."\n"; + } else { + $line .= "#line ".($linenum+$headlines)."\n"; + } + $linedone++; + } + if ( $line =~ /^#\s*line\b/ and $linenum == 2 + $skiplines ) { + $line = ""; + } + } + + open(my $out, '>', "$opts{out}") or die "Can't open $opts{out}: $!"; + print $out $head; + print $out $start, ( $opts{usewarnings} ? " -w" : "" ), + "\n#line ", ($headlines+1), "\n" unless $linedone; + print $out @file[$skiplines..$#file]; + print $out $tail unless $taildone; + close($out); + + return $opts{out}; +} + + +sub _quote_args { + # Returns a string that can become [part of] a command line with + # proper quoting so that the subprocess sees this same list of args. + my ($self, @args) = @_; + + my @quoted; + + for (@args) { + if ( /^[^\s*?!\$<>;|'"\[\]\{\}]+$/ ) { + # Looks pretty safe + push @quoted, $_; + } else { + # XXX this will obviously have to improve - is there already a + # core module lying around that does proper quoting? + s/"/\\"/g; + push @quoted, qq("$_"); + } + } + + return join " ", @quoted; +} + + +sub split_like_shell { + # As it turns out, Windows command-parsing is very different from + # Unix command-parsing. Double-quotes mean different things, + # backslashes don't necessarily mean escapes, and so on. So we + # can't use Text::ParseWords::shellwords() to break a command string + # into words. The algorithm below was bashed out by Randy and Ken + # (mostly Randy), and there are a lot of regression tests, so we + # should feel free to adjust if desired. + + (my $self, local $_) = @_; + + return @$_ if defined() && ref() eq 'ARRAY'; + + my @argv; + return @argv unless defined() && length(); + + my $arg = ''; + my( $i, $quote_mode ) = ( 0, 0 ); + + while ( $i < length() ) { + + my $ch = substr( $_, $i , 1 ); + my $next_ch = substr( $_, $i+1, 1 ); + + if ( $ch eq '\\' && $next_ch eq '"' ) { + $arg .= '"'; + $i++; + } elsif ( $ch eq '\\' && $next_ch eq '\\' ) { + $arg .= '\\'; + $i++; + } elsif ( $ch eq '"' && $next_ch eq '"' && $quote_mode ) { + $quote_mode = !$quote_mode; + $arg .= '"'; + $i++; + } elsif ( $ch eq '"' && $next_ch eq '"' && !$quote_mode && + ( $i + 2 == length() || + substr( $_, $i + 2, 1 ) eq ' ' ) + ) { # for cases like: a"" => [ 'a' ] + push( @argv, $arg ); + $arg = ''; + $i += 2; + } elsif ( $ch eq '"' ) { + $quote_mode = !$quote_mode; + } elsif ( $ch eq ' ' && !$quote_mode ) { + push( @argv, $arg ) if $arg; + $arg = ''; + ++$i while substr( $_, $i + 1, 1 ) eq ' '; + } else { + $arg .= $ch; + } + + $i++; + } + + push( @argv, $arg ) if defined( $arg ) && length( $arg ); + return @argv; +} + + +# system(@cmd) does not like having double-quotes in it on Windows. +# So we quote them and run it as a single command. +sub do_system { + my ($self, @cmd) = @_; + + my $cmd = $self->_quote_args(@cmd); + my $status = system($cmd); + if ($status and $! =~ /Argument list too long/i) { + my $env_entries = ''; + foreach (sort keys %ENV) { $env_entries .= "$_=>".length($ENV{$_})."; " } + warn "'Argument list' was 'too long', env lengths are $env_entries"; + } + return !$status; +} + +# Copied from ExtUtils::MM_Win32 +sub _maybe_command { + my($self,$file) = @_; + my @e = exists($ENV{'PATHEXT'}) + ? split(/;/, $ENV{PATHEXT}) + : qw(.com .exe .bat .cmd); + my $e = ''; + for (@e) { $e .= "\Q$_\E|" } + chop $e; + # see if file ends in one of the known extensions + if ($file =~ /($e)$/i) { + return $file if -e $file; + } + else { + for (@e) { + return "$file$_" if -e "$file$_"; + } + } + return; +} + + +1; + +__END__ + +=head1 NAME + +Module::Build::Platform::Windows - Builder class for Windows platforms + +=head1 DESCRIPTION + +The sole purpose of this module is to inherit from +C<Module::Build::Base> and override a few methods. Please see +L<Module::Build> for the docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org>, Randy W. Sims <RandyS@ThePierianSpring.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3) + +=cut diff --git a/lib/Module/Build/Platform/aix.pm b/lib/Module/Build/Platform/aix.pm new file mode 100644 index 0000000..28eeb1a --- /dev/null +++ b/lib/Module/Build/Platform/aix.pm @@ -0,0 +1,39 @@ +package Module::Build::Platform::aix; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Platform::Unix; + +our @ISA = qw(Module::Build::Platform::Unix); + +# This class isn't necessary anymore, but we can't delete it, because +# some people might still have the old copy in their @INC, containing +# code we don't want to execute, so we have to make sure an upgrade +# will replace it with this empty subclass. + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::aix - Builder class for AIX platform + +=head1 DESCRIPTION + +This module provides some routines very specific to the AIX +platform. + +Please see the L<Module::Build> for the general docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/cygwin.pm b/lib/Module/Build/Platform/cygwin.pm new file mode 100644 index 0000000..034b9e1 --- /dev/null +++ b/lib/Module/Build/Platform/cygwin.pm @@ -0,0 +1,54 @@ +package Module::Build::Platform::cygwin; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Platform::Unix; + +our @ISA = qw(Module::Build::Platform::Unix); + +sub manpage_separator { + '.' +} + +# Copied from ExtUtils::MM_Cygwin::maybe_command() +# If our path begins with F</cygdrive/> then we use the Windows version +# to determine if it may be a command. Otherwise we use the tests +# from C<ExtUtils::MM_Unix>. + +sub _maybe_command { + my ($self, $file) = @_; + + if ($file =~ m{^/cygdrive/}i) { + require Module::Build::Platform::Windows; + return Module::Build::Platform::Windows->_maybe_command($file); + } + + return $self->SUPER::_maybe_command($file); +} + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::cygwin - Builder class for Cygwin platform + +=head1 DESCRIPTION + +This module provides some routines very specific to the cygwin +platform. + +Please see the L<Module::Build> for the general docs. + +=head1 AUTHOR + +Initial stub by Yitzchak Scott-Thoennes <sthoenna@efn.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/darwin.pm b/lib/Module/Build/Platform/darwin.pm new file mode 100644 index 0000000..204ed18 --- /dev/null +++ b/lib/Module/Build/Platform/darwin.pm @@ -0,0 +1,39 @@ +package Module::Build::Platform::darwin; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Platform::Unix; + +our @ISA = qw(Module::Build::Platform::Unix); + +# This class isn't necessary anymore, but we can't delete it, because +# some people might still have the old copy in their @INC, containing +# code we don't want to execute, so we have to make sure an upgrade +# will replace it with this empty subclass. + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::darwin - Builder class for Mac OS X platform + +=head1 DESCRIPTION + +This module provides some routines very specific to the Mac OS X +platform. + +Please see the L<Module::Build> for the general docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/Platform/os2.pm b/lib/Module/Build/Platform/os2.pm new file mode 100644 index 0000000..69fdf8e --- /dev/null +++ b/lib/Module/Build/Platform/os2.pm @@ -0,0 +1,48 @@ +package Module::Build::Platform::os2; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; +use Module::Build::Platform::Unix; + +our @ISA = qw(Module::Build::Platform::Unix); + +sub manpage_separator { '.' } + +sub have_forkpipe { 0 } + +# Copied from ExtUtils::MM_OS2::maybe_command +sub _maybe_command { + my($self,$file) = @_; + $file =~ s,[/\\]+,/,g; + return $file if -x $file && ! -d _; + return "$file.exe" if -x "$file.exe" && ! -d _; + return "$file.cmd" if -x "$file.cmd" && ! -d _; + return; +} + +1; +__END__ + + +=head1 NAME + +Module::Build::Platform::os2 - Builder class for OS/2 platform + +=head1 DESCRIPTION + +This module provides some routines very specific to the OS/2 +platform. + +Please see the L<Module::Build> for the general docs. + +=head1 AUTHOR + +Ken Williams <kwilliams@cpan.org> + +=head1 SEE ALSO + +perl(1), Module::Build(3), ExtUtils::MakeMaker(3) + +=cut diff --git a/lib/Module/Build/PodParser.pm b/lib/Module/Build/PodParser.pm new file mode 100644 index 0000000..277ee59 --- /dev/null +++ b/lib/Module/Build/PodParser.pm @@ -0,0 +1,63 @@ +package Module::Build::PodParser; + +use strict; +use warnings; +our $VERSION = '0.4214'; +$VERSION = eval $VERSION; + +sub new { + # Perl is so fun. + my $package = shift; + + my $self; + $self = bless {have_pod_parser => 0, @_}, $package; + + unless ($self->{fh}) { + die "No 'file' or 'fh' parameter given" unless $self->{file}; + open($self->{fh}, '<', $self->{file}) or die "Couldn't open $self->{file}: $!"; + } + + return $self; +} + +sub parse_from_filehandle { + my ($self, $fh) = @_; + + local $_; + while (<$fh>) { + next unless /^=(?!cut)/ .. /^=cut/; # in POD + # Accept Name - abstract or C<Name> - abstract + last if ($self->{abstract}) = /^ (?: [a-z_0-9:]+ | [BCIF] < [a-z_0-9:]+ > ) \s+ - \s+ (.*\S) /ix; + } + + my @author; + while (<$fh>) { + next unless /^=head1\s+AUTHORS?/i ... /^=/; + next if /^=/; + push @author, $_ if /\@/; + } + return unless @author; + s/^\s+|\s+$//g foreach @author; + + $self->{author} = \@author; + + return; +} + +sub get_abstract { + my $self = shift; + return $self->{abstract} if defined $self->{abstract}; + + $self->parse_from_filehandle($self->{fh}); + + return $self->{abstract}; +} + +sub get_author { + my $self = shift; + return $self->{author} if defined $self->{author}; + + $self->parse_from_filehandle($self->{fh}); + + return $self->{author} || []; +} diff --git a/t/00-compile.t b/t/00-compile.t new file mode 100644 index 0000000..21bae84 --- /dev/null +++ b/t/00-compile.t @@ -0,0 +1,17 @@ +use strict; +use warnings; +use lib 't/lib'; +use MBTest; +use File::Find qw/find/; + +my @files; +find( sub { -f && /\.pm$/ && push @files, $File::Find::name }, 'lib' ); + +plan tests => scalar @files; + +for my $f ( sort @files ) { + my $ec; + my $output = stdout_stderr_of( sub { $ec = system( $^X, '-c', $f ) } ); + ok( ! $ec, "compiling $f" ) or diag $output; +} + diff --git a/t/PL_files.t b/t/PL_files.t new file mode 100644 index 0000000..68614c8 --- /dev/null +++ b/t/PL_files.t @@ -0,0 +1,86 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 8; +use DistGen; +blib_load('Module::Build'); + +my $dist; + +# Test that PL files don't get installed even in bin or lib +{ + $dist = DistGen->new( dir => MBTest->tmpdir ); + $dist->regen; + $dist->chdir_in; + + my $distname = $dist->name; + $dist->change_build_pl({ + module_name => $distname, + PL_files => { + 'bin/foo.PL' => 'bin/foo', + 'lib/Bar.pm.PL' => 'lib/Bar.pm', + }, + }); + + $dist->add_file("bin/foo.PL", <<'END'); +open my $fh, ">", $ARGV[0] or die $!; +print $fh "foo\n"; +END + + $dist->add_file("lib/Bar.pm.PL", <<'END'); +open my $fh, ">", $ARGV[0] or die $!; +print $fh "bar\n"; +END + + $dist->regen; + + my $mb = Module::Build->new_from_context( install_base => "test_install" ); + $mb->dispatch("install"); + + ok -e "test_install/bin/foo", "Generated PL_files installed from bin"; + ok -e "test_install/lib/perl5/Bar.pm", " and from lib"; + + ok !-e "test_install/bin/foo.PL", "PL_files not installed from bin"; + ok !-e "test_install/lib/perl5/Bar.pm.PL", " nor from lib"; + + is slurp("test_install/bin/foo"), "foo\n", "Generated bin contains correct content"; + is slurp("test_install/lib/perl5/Bar.pm"), "bar\n", " so does the lib"; + + $dist->chdir_original if $dist->did_chdir; +} + +# Test an empty PL target list runs the PL but doesn't +# add it to MANIFEST or cleanup +{ + $dist = DistGen->new( dir => MBTest->tmpdir ); + $dist->regen; + $dist->chdir_in; + + my $distname = $dist->name; + $dist->change_build_pl({ + module_name => $distname, + PL_files => { + 'Special.PL' => [], + }, + }); + + $dist->add_file("Special.PL", <<'END'); +open my $fh, ">", "foo" or die $!; +print $fh "foo\n"; +END + + $dist->regen; + + my $mb = Module::Build->new_from_context(); + $mb->dispatch("code"); + + ok( -f "foo", "special PL file ran" ); + + my $cleanup = $mb->cleanup; + + my %cleanup = map { $_ => 1 } $mb->cleanup; + is($cleanup{foo}, undef, "generated special file not added to cleanup"); + + $dist->chdir_original if $dist->did_chdir; +} diff --git a/t/README.pod b/t/README.pod new file mode 100644 index 0000000..b2d0579 --- /dev/null +++ b/t/README.pod @@ -0,0 +1,94 @@ +=head1 A GUIDE TO WRITING TESTS FOR MODULE::BUILD + +This document provides tips on writing new tests for Module::Build. Please +note that many existing tests were written prior to these guidelines and +have many different styles. Please don't copy/paste old tests by rote without +considering better ways to test. See C<sample.t> for a starter test file. + +=head1 TEST FILE PREAMBLE + +Every Module::Build test should begin with the same preamble to ensure that the +test library is set properly and that the correct version of Module::Build is +being tested. + + use strict; + use lib 't/lib'; + use MBTest tests => 2; # or 'no_plan' + + blib_load('Module::Build'); + +The C<MBTest> module is in C<t/lib/> and subclasses Test::More. When loaded +it cleans up several environment variables that could cause problems, +tweaks C<@INC> and exports several helper functions. See that module for +details. + +=head1 CREATING A TEST DISTRIBUTION + +The C<DistGen> module in C<t/lib/> should be used to create sample +distributions for testing. It provides numerous helpful methods to +create a skeleton distribution, add files, change files, and so on. +Run C<perldoc> on C<t/lib/DistGen.pm> to see the documentation. + + # CREATE A TEST DISTRIBUTION + + use DistGen; + + # create dist object in a temp directory + my $dist = DistGen->new; + + # enter the test distribution directory before further testing + $dist->chdir_in; + + # generate the skeleton files + $dist->regen; + + +=head1 GETTING A MODULE::BUILD OBJECT + +From inside the test distribution, you can get the Module::Build object +configured in Build.PL using the C<new_from_context> method on the +dist object. This is just like Module::Build's C<new_from_context> except +it passes C<< quiet => 1 >> to avoid sending output to the terminal. +Use the Module::Build object to test the programmatic API. + + my $mb = $dist->new_from_context( quiet => 1 ); + isa_ok( $mb, "Module::Build" ); + is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); + +=head1 TESTING THE COMMAND LINE API + +The command line API is tested by running subprocesses, not via a Module::Build +object. The C<DistGen> object has helper methods for running C<Build.PL> and +C<Build> and passing arguments on the command line. + + $dist->run_build_pl( '--quiet' ); + $dist->run_build( 'test' ); + +=head1 TYPICAL TESTING CYCLE + +The typical testing cycle is to generate or modify a test distribution, either +through the C<DistGen> object or directly in the filesystem, then regenerate +the distribution and test it (or run command line tests and observe the +result.) + + # Modify the distribution + + $dist->change_build_pl( + { + module_name => $dist->name, + license => 'artistic', + } + ); + $dist->regen; + + # Get a new build object and test it + + $mb = $dist->new_from_context; + is( $mb->license, "artistic", "saw 'artistic' license" ); + + +=head1 COPYRIGHT + +This documentation is Copyright (C) 2009 by David Golden. You can redistribute +it and/or modify it under the same terms as Perl 5.10.0. + diff --git a/t/actions/installdeps.t b/t/actions/installdeps.t new file mode 100644 index 0000000..3bd74bc --- /dev/null +++ b/t/actions/installdeps.t @@ -0,0 +1,45 @@ +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 6; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in; + +$dist->change_build_pl( + module_name => $dist->name, + requires => { + 'File::Spec' => 9999, + }, + build_requires => { + 'Getopt::Long' => 9998, + }, + cpan_client => qq{"$^X"} . ' -le print($_)for($^X,@ARGV)', +)->regen; + +# get a Module::Build object and test with it +my $mb; +stdout_stderr_of( sub { $mb = $dist->new_from_context('verbose' => 1) } ); +isa_ok( $mb, "Module::Build" ); +like( $mb->cpan_client, qr/^"\Q$^X\E"/, "cpan_client is mocked with perl" ); + +my $retval; +my $out = stdout_of( sub { + $retval = $mb->dispatch('installdeps') +}); +ok( $retval, "ran mocked Build installdeps"); +like( $out, qr/File::Spec/, "saw File::Spec prereq" ); +like( $out, qr/Getopt::Long/, "saw Getopt::Long prereq" ); + +$out = stdout_stderr_of( sub { + $retval = $mb->dispatch('installdeps', cpan_client => 'ADLKASJDFLASDJ'); +}); +ok( !$retval, "Build installdeps with bad cpan_client fails" ); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/actions/manifest_skip.t b/t/actions/manifest_skip.t new file mode 100644 index 0000000..a3677dd --- /dev/null +++ b/t/actions/manifest_skip.t @@ -0,0 +1,54 @@ +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 7; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in; +$dist->change_build_pl( + module_name => $dist->name, + requires => { + 'File::Spec' => 9999, + }, + build_requires => { + 'Getopt::Long' => 9998, + }, + cpan_client => $^X . ' -le print($_)for($^X,@ARGV)', +)->regen; + +ok( ! -e 'MANIFEST.SKIP', "MANIFEST.SKIP doesn't exist at start" ); + +# get a Module::Build object and test with it +my $mb; +stdout_stderr_of( sub { $mb = $dist->new_from_context('verbose' => 1) } ); +isa_ok( $mb, "Module::Build" ); + +my ($out, $err) = stdout_stderr_of( sub { + $dist->run_build('manifest_skip') +}); +ok( -e 'MANIFEST.SKIP', "'Build manifest_skip' creates MANIFEST.SKIP" ); +like( $out, qr/Creating a new MANIFEST.SKIP file/, "Saw creation message"); + +# shouldn't overwrite +my $old_mtime = -M 'MANIFEST.SKIP'; +($out, $err) = stdout_stderr_of( sub { + $dist->run_build('manifest_skip') +}); +like( $err, qr/MANIFEST.SKIP already exists/, + "Running it again warns about pre-existing MANIFEST.SKIP" +); +is( -M 'MANIFEST.SKIP', $old_mtime, "File does not appear modified" ); + +# cleanup +($out, $err) = stdout_stderr_of( sub { + $dist->run_build('distclean') +}); +ok( -e 'MANIFEST.SKIP', "MANIFEST.SKIP still exists after distclean" ); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/add_property.t b/t/add_property.t new file mode 100644 index 0000000..e0b25ae --- /dev/null +++ b/t/add_property.t @@ -0,0 +1,94 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 27; +#use MBTest 'no_plan'; +use DistGen; + +blib_load 'Module::Build'; + +my $tmp = MBTest->tmpdir; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; +$dist->chdir_in; + +ADDPROP: { + package My::Build::Prop; + use base 'Module::Build'; + __PACKAGE__->add_property( 'foo' ); + __PACKAGE__->add_property( 'bar', 'howdy' ); + __PACKAGE__->add_property( 'baz', default => 'howdy' ); + __PACKAGE__->add_property( 'code', default => sub { 'yay' } ); + __PACKAGE__->add_property( + 'check', + default => sub { 'howdy' }, + check => sub { + return 1 if $_ eq 'howdy'; + shift->property_error(qq{"$_" is invalid}); + return 0; + }, + ); + __PACKAGE__->add_property( + 'hash', + default => { foo => 1 }, + check => sub { + return 1 if !defined $_ or exists $_->{foo}; + shift->property_error(qq{hash is invalid}); + return 0; + }, + ); +} + +ok my $build = My::Build::Prop->new( + 'module_name' => 'Simple', + quiet => 1, +), 'Create new build object'; + +is $build->foo, undef, 'Property "foo" should be undef'; +ok $build->foo(42), 'Set "foo"'; +is $build->foo, 42, 'Now "foo" should have new value'; + +is $build->bar, 'howdy', 'Property "bar" should be its default'; +ok $build->bar('yo'), 'Set "bar"'; +is $build->bar, 'yo', 'Now "bar" should have new value'; + +is $build->check, 'howdy', 'Property "check" should be its default'; + +eval { $build->check('yo') }; +ok my $err = $@, 'Should get an error for an invalid value'; +like $err, qr/^ERROR: "yo" is invalid/, 'It should be the correct error'; + +is $build->code, 'yay', 'Property "code" should have its code value'; + +is_deeply $build->hash, { foo => 1 }, 'Property "hash" should be default'; +is $build->hash('foo'), 1, 'Should be able to get key in hash'; +ok $build->hash( bar => 3 ), 'Add a key to the hash prop'; +is_deeply $build->hash, { foo => 1, bar => 3 }, 'New key should be in hash'; + +eval { $build->hash({ bar => 3 }) }; +ok $err = $@, 'Should get exception for assigning invalid hash'; +like $err, qr/^ERROR: hash is invalid/, 'It should be the correct error'; + +eval { $build->hash( []) }; +ok $err = $@, 'Should get exception for assigning an array for a hash'; +like $err, qr/^Unexpected arguments for property 'hash'/, + 'It should be the proper error'; +is $build->hash(undef), undef, 'Should be able to set hash to undef'; + +# Check core properties. +is $build->installdirs, 'site', 'Property "installdirs" should be default'; +ok $build->installdirs('core'), 'Set "installdirst" to "core"'; +is $build->installdirs, 'core', 'Now "installdirs" should be "core"'; + +eval { $build->installdirs('perl') }; +ok $err = $@, 'Should have caught exception setting "installdirs" to "perl"'; +like $err, qr/^ERROR: Perhaps you meant installdirs to be "core" rather than "perl"\?/, + 'And it should suggest "core" in the error message'; + +eval { $build->installdirs('foo') }; +ok $err = $@, 'Should catch exception for invalid "installdirs" value'; +like $err, qr/ERROR: installdirs must be one of "core", "site", or "vendor"/, + 'And it should suggest the proper values in the error message'; + +$dist->chdir_original if $dist->did_chdir; diff --git a/t/add_property_array.t b/t/add_property_array.t new file mode 100644 index 0000000..3b405cb --- /dev/null +++ b/t/add_property_array.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 1; + +blib_load 'Module::Build'; + +ADDPROP: { + package My::Build::Prop; + use base 'Module::Build'; + __PACKAGE__->add_property( 'list_property' => []); +} + +ok grep { $_ eq 'bundle_inc' } My::Build::Prop->array_properties, "has bundle_inc even after adding another array property"; + diff --git a/t/add_property_hash.t b/t/add_property_hash.t new file mode 100644 index 0000000..afd71f8 --- /dev/null +++ b/t/add_property_hash.t @@ -0,0 +1,16 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 1; + +blib_load 'Module::Build'; + +ADDPROP: { + package My::Build::Prop; + use base 'Module::Build'; + __PACKAGE__->add_property( 'hash_property' => {}); +} + +ok grep { $_ eq 'install_path' } My::Build::Prop->hash_properties, "has install_path even after adding another hash property"; + diff --git a/t/basic.t b/t/basic.t new file mode 100644 index 0000000..e26847e --- /dev/null +++ b/t/basic.t @@ -0,0 +1,234 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 58; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + +######################### + + +# Test object creation +{ + my $mb = Module::Build->new( module_name => $dist->name ); + ok $mb; + is $mb->module_name, $dist->name; + is $mb->build_class, 'Module::Build'; + is $mb->dist_name, $dist->name; + + $mb = Module::Build->new( dist_name => $dist->name, dist_version => 7 ); + ok $mb; + ok $mb->module_name; # Set via heuristics + is $mb->dist_name, $dist->name; +} + +# Make sure actions are defined, and known_actions works as class method +{ + my %actions = map {$_, 1} Module::Build->known_actions; + ok $actions{clean}; + ok $actions{distdir}; +} + +# Test prerequisite checking +{ + local @INC = (File::Spec->catdir( $dist->dirname, 'lib' ), @INC); + my $flagged = 0; + local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /@{[$dist->name]}/}; + my $mb = Module::Build->new( + module_name => $dist->name, + requires => {$dist->name => 0}, + ); + ok ! $flagged; + ok ! $mb->prereq_failures; + $mb->dispatch('realclean'); + $dist->clean; + + $flagged = 0; + $mb = Module::Build->new( + module_name => $dist->name, + requires => {$dist->name => 3.14159265}, + ); + ok $flagged; + ok $mb->prereq_failures; + ok $mb->prereq_failures->{requires}{$dist->name}; + is $mb->prereq_failures->{requires}{$dist->name}{have}, "0.01"; + is $mb->prereq_failures->{requires}{$dist->name}{need}, "3.14159265"; + + $mb->dispatch('realclean'); + $dist->clean; + + # Make sure check_installed_status() works as a class method + my $info = Module::Build->check_installed_status('File::Spec', 0); + ok $info->{ok}; + is $info->{have}, $File::Spec::VERSION; + + # Make sure check_installed_status() works with an advanced spec + $info = Module::Build->check_installed_status('File::Spec', '> 0'); + ok $info->{ok}; + + # Use 2 lines for this, to avoid a "used only once" warning + local $Foo::Module::VERSION; + $Foo::Module::VERSION = '1.01_02'; + + $info = Module::Build->check_installed_status('Foo::Module', '1.01_02'); + ok $info->{ok} or diag($info->{message}); +} + +{ + # Make sure the correct warning message is generated when an + # optional prereq isn't installed + my $flagged = 0; + local $SIG{__WARN__} = sub { $flagged = 1 if $_[0] =~ /ModuleBuildNonExistent is not installed/}; + + my $mb = Module::Build->new( + module_name => $dist->name, + recommends => {ModuleBuildNonExistent => 3}, + ); + ok $flagged; + $dist->clean; +} + +# Test verbosity +{ + my $mb = Module::Build->new(module_name => $dist->name); + + $mb->add_to_cleanup('save_out'); + # Use uc() so we don't confuse the current test output + like uc(stdout_of( sub {$mb->dispatch('test', verbose => 1)} )), qr/^OK \d/m; + like uc(stdout_of( sub {$mb->dispatch('test', verbose => 0)} )), qr/\.\. ?OK/; + + $mb->dispatch('realclean'); + $dist->clean; +} + +# Make sure 'config' entries are respected on the command line, and that +# Getopt::Long specs work as expected. +{ + use Config; + $dist->change_build_pl + ({ + module_name => @{[$dist->name]}, + license => 'perl', + get_options => { foo => {}, + bar => { type => '+' }, + bat => { type => '=s' }, + dee => { type => '=s', + default => 'goo' + }, + } + }); + + $dist->regen; + eval {Module::Build->run_perl_script('Build.PL', [], ['--nouse-rcfile', '--config', "foocakes=barcakes", '--foo', '--bar', '--bar', '-bat=hello', 'gee=whiz', '--any', 'hey', '--destdir', 'yo', '--verbose', '1'])}; + is $@, ''; + + my $mb = Module::Build->resume; + ok $mb->valid_property('config'); + + is $mb->config('cc'), $Config{cc}; + is $mb->config('foocakes'), 'barcakes'; + + # Test args(). + is $mb->args('foo'), 1; + is $mb->args('bar'), 2, 'bar'; + is $mb->args('bat'), 'hello', 'bat'; + is $mb->args('gee'), 'whiz'; + is $mb->args('any'), 'hey'; + is $mb->args('dee'), 'goo'; + is $mb->destdir, 'yo'; + my %runtime = $mb->runtime_params; + is_deeply \%runtime, + { + verbose => 1, + destdir => 'yo', + use_rcfile => 0, + config => { foocakes => 'barcakes' }, + }; + + ok my $argsref = $mb->args; + is $argsref->{foo}, 1; + $argsref->{doo} = 'hee'; + is $mb->args('doo'), 'hee'; + ok my %args = $mb->args; + is $args{foo}, 1; + + # revert test distribution to pristine state because we modified a file + $dist->regen( clean => 1 ); +} + +# Test author stuff +{ + my $mb = Module::Build->new( + module_name => $dist->name, + dist_author => 'Foo Meister <foo@example.com>', + build_class => 'My::Big::Fat::Builder', + ); + ok $mb; + ok ref($mb->dist_author), 'dist_author converted to array if simple string'; + is $mb->dist_author->[0], 'Foo Meister <foo@example.com>'; + is $mb->build_class, 'My::Big::Fat::Builder'; +} + +# Test conversion of shell strings +{ + my $mb = Module::Build->new( + module_name => $dist->name, + dist_author => 'Foo Meister <foo@example.com>', + extra_compiler_flags => '-I/foo -I/bar', + extra_linker_flags => '-L/foo -L/bar', + ); + ok $mb; + is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list"; + is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list"; + + # Try again with command-line args + eval {Module::Build->run_perl_script('Build.PL', [], ['--extra_compiler_flags', '-I/foo -I/bar', + '--extra_linker_flags', '-L/foo -L/bar'])}; + $mb = Module::Build->resume; + ok $mb; + is_deeply $mb->extra_compiler_flags, ['-I/foo', '-I/bar'], "Should split shell string into list"; + is_deeply $mb->extra_linker_flags, ['-L/foo', '-L/bar'], "Should split shell string into list"; +} + +# Test include_dirs. +{ + ok my $mb = Module::Build->new( + module_name => $dist->name, + include_dirs => [qw(/foo /bar)], + ); + is_deeply $mb->include_dirs, ['/foo', '/bar'], 'Should have include dirs'; + + # Try a string. + ok $mb = Module::Build->new( + module_name => $dist->name, + include_dirs => '/foo', + ); + is_deeply $mb->include_dirs, ['/foo'], 'Should have string include dir'; + + # Try again with command-line args + eval { Module::Build->run_perl_script( + 'Build.PL', [], + ['--include_dirs', '/foo', '--include_dirs', '/bar' ], + ) }; + + ok $mb = Module::Build->resume; + is_deeply $mb->include_dirs, ['/foo', '/bar'], 'Should have include dirs'; + + eval { Module::Build->run_perl_script( + 'Build.PL', [], + ['--include_dirs', '/foo' ], + ) }; + + ok $mb = Module::Build->resume; + is_deeply $mb->include_dirs, ['/foo'], 'Should have single include dir'; +} + diff --git a/t/bundle_inc.t b/t/bundle_inc.t new file mode 100644 index 0000000..00dcf47 --- /dev/null +++ b/t/bundle_inc.t @@ -0,0 +1,222 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; # or 'no_plan' +use DistGen; +use Config; +use File::Spec; +use ExtUtils::Packlist; +use ExtUtils::Installed; +use File::Path; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +if ( $ENV{PERL_CORE} ) { + plan skip_all => 'bundle_inc tests will never succeed in PERL_CORE'; +} +elsif ( ! $ENV{MB_TEST_EXPERIMENTAL} ) { + plan skip_all => '$ENV{MB_TEST_EXPERIMENTAL} is not set'; +} +elsif ( ! MBTest::check_EUI() ) { + plan skip_all => 'ExtUtils::Installed takes too long on your system'; +} +elsif ( Module::Build::ConfigData->feature('inc_bundling_support') ) { + plan tests => 19; +} else { + plan skip_all => 'inc_bundling_support feature is not enabled'; +} + +# need to do a temp install of M::B being tested to ensure a packlist +# is available for bundling + +my $current_mb = Module::Build->resume(); +my $temp_install = MBTest->tmpdir(); +my $arch = $Config{archname}; +my $lib_path = File::Spec->catdir($temp_install,qw/lib perl5/); +my $arch_path = File::Spec->catdir( $lib_path, $arch ); +mkpath ( $arch_path ); +ok( -d $arch_path, "created temporary M::B pseudo-install directory"); + +unshift @INC, $lib_path, $arch_path; +local $ENV{PERL5LIB} = join( $Config{path_sep}, + $lib_path, ($ENV{PERL5LIB} ? $ENV{PERL5LIB} : () ) +); + +# must uninst=0 so we don't try to remove an installed M::B! +stdout_of( sub { $current_mb->dispatch( + 'install', install_base => $temp_install, uninst => 0 + ) + } +); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new( inc => 1 )->chdir_in->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); +is_deeply( $mb->bundle_inc, [ 'Module::Build' ], + "Module::Build is flagged for bundling" +); + +# bundle stuff into distdir +stdout_stderr_of( sub { $mb->dispatch('distdir') } ); + +my $dist_inc = File::Spec->catdir($mb->dist_dir, 'inc'); +ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ), + "dist_dir/inc/latest.pm created" +); + +ok( -d File::Spec->catdir( $dist_inc, 'inc_Module-Build' ), + "dist_dir/inc/inc_Module_Build created" +); + +my $mb_file = + File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build.pm/ ); + +ok( -e $mb_file, + "dist_dir/inc/inc_Module_Build/Module/Build.pm created" +); + +ok( -e File::Spec->catfile( $dist_inc, qw/inc_Module-Build Module Build Base.pm/ ), + "dist_dir/inc/inc_Module_Build/Module/Build/Base.pm created" +); + +# Force bundled M::B to a higher version so it gets loaded +# This has failed on Win32 for no known reason, so we'll skip if +# we can't edit the file. + +eval { + chmod 0666, $mb_file; + open(my $fh, '<', $mb_file) or die "Could not read $mb_file: $!"; + my $mb_code = do { local $/; <$fh> }; + $mb_code =~ s{\$VERSION\s+=\s+\S+}{\$VERSION = 9999;}; + close $fh; + open($fh, '>', $mb_file) or die "Could not write $mb_file: $!"; + print {$fh} $mb_code; + close $fh; +}; + +my $err = $@; +diag $@ if $@; +SKIP: { + skip "Couldn't adjust \$VERSION in bundled M::B for testing", 10 + if $err; + + # test the bundling in dist_dir + chdir $mb->dist_dir; + + stdout_of( sub { Module::Build->run_perl_script('Build.PL',[],[]) } ); + ok( -e 'MYMETA.yml', 'MYMETA was created' ); + + open(my $meta, '<', 'MYMETA.yml'); + ok( $meta, "opened MYMETA.yml" ); + ok( scalar( grep { /generated_by:.*9999/ } <$meta> ), + "dist_dir Build.PL loaded bundled Module::Build" + ); + close $meta; + + #--------------------------------------------------------------------------# + # test identification of dependencies + #--------------------------------------------------------------------------# + + $dist->chdir_in; + + $dist->add_file( 'mylib/Foo.pm', << 'HERE' ); +package Foo; +our $VERSION = 1; +1; +HERE + + $dist->add_file( 'mylib/Bar.pm', << 'HERE' ); +package Bar; +use Foo; +our $VERSION = 42; +1; +HERE + + $dist->change_file( 'Build.PL', << "HERE" ); +use inc::latest 'Module::Build'; +use inc::latest 'Foo'; + +Module::Build->new( + module_name => '$dist->{name}', + license => 'perl', +)->create_build_script; +HERE + + $dist->regen( clean => 1 ); + + make_packlist($_,'mylib') for qw/Foo Bar/; + + # get a Module::Build object and test with it + my $abs_mylib = File::Spec->rel2abs('mylib'); + + + unshift @INC, $abs_mylib; + $mb = $dist->new_from_context(); # quiet by default + isa_ok( $mb, "Module::Build" ); + is_deeply( [sort @{$mb->bundle_inc}], [ 'Foo', 'Module::Build' ], + "Module::Build and Foo are flagged for bundling" + ); + + my $output = stdout_stderr_of( sub { $mb->dispatch('distdir') } ); + + ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ), + "./inc/latest.pm created" + ); + + ok( -d File::Spec->catdir( $dist_inc, 'inc_Foo' ), + "dist_dir/inc/inc_Foo created" + ); + + $dist->change_file( 'Build.PL', << "HERE" ); +use inc::latest 'Module::Build'; +use inc::latest 'Bar'; + +Module::Build->new( + module_name => '$dist->{name}', + license => 'perl', +)->create_build_script; +HERE + + $dist->regen( clean => 1 ); + make_packlist($_,'mylib') for qw/Foo Bar/; + + $mb = $dist->new_from_context(); # quiet by default + isa_ok( $mb, "Module::Build" ); + is_deeply( [sort @{$mb->bundle_inc}], [ 'Bar', 'Module::Build' ], + "Module::Build and Bar are flagged for bundling" + ); + + $output = stdout_stderr_of( sub { $mb->dispatch('distdir') } ); + + ok( -e File::Spec->catfile( $dist_inc, 'latest.pm' ), + "./inc/latest.pm created" + ); + + ok( -d File::Spec->catdir( $dist_inc, 'inc_Bar' ), + "dist_dir/inc/inc_Bar created" + ); +} + + +sub make_packlist { + my ($mod, $lib) = @_; + my $arch = $Config{archname}; + (my $mod_path = $mod) =~ s{::}{/}g; + my $mod_file = File::Spec->catfile( $lib, "$mod_path\.pm" ); + my $abs = File::Spec->rel2abs($mod_file); + my $packlist_path = File::Spec->catdir($lib, $arch, 'auto', $mod_path); + mkpath $packlist_path; + my $packlist = ExtUtils::Packlist->new; + $packlist->{$abs}++; + $packlist->write( File::Spec->catfile( $packlist_path, '.packlist' )); +} + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/bundled/Software/License.pm b/t/bundled/Software/License.pm new file mode 100644 index 0000000..6457ab6 --- /dev/null +++ b/t/bundled/Software/License.pm @@ -0,0 +1,56 @@ +# Modified from the original as a "mock" version for testing +use strict; +use warnings; +use 5.006; # warnings +package Software::License; +our $VERSION = 9999; + +sub new { + my ($class, $arg) = @_; + + # XXX changed from Carp::croak to die + die "no copyright holder specified" unless $arg->{holder}; + + bless $arg => $class; +} + + +sub year { defined $_[0]->{year} ? $_[0]->{year} : (localtime)[5]+1900 } +sub holder { $_[0]->{holder} } + +sub version { + my ($self) = @_; + my $pkg = ref $self ? ref $self : $self; + $pkg =~ s/.+:://; + my (undef, @vparts) = split /_/, $pkg; + + return unless @vparts; + return join '.', @vparts; +} + + +# sub meta1_name { return undef; } # sort this out later, should be easy +sub meta_name { return undef; } +sub meta_yml_name { $_[0]->meta_name } + +sub meta2_name { + my ($self) = @_; + my $meta1 = $self->meta_name; + + return undef unless defined $meta1; + + return $meta1 + if $meta1 =~ /\A(?:open_source|restricted|unrestricted|unknown)\z/; + + return undef; +} + +# XXX these are trivial mocks of the real thing +sub notice { 'NOTICE' } +sub license { 'LICENSE' } +sub fulltext { 'FULLTEXT' } + +1; + + + diff --git a/t/bundled/Tie/CPHash.pm b/t/bundled/Tie/CPHash.pm new file mode 100644 index 0000000..b167622 --- /dev/null +++ b/t/bundled/Tie/CPHash.pm @@ -0,0 +1,194 @@ +#--------------------------------------------------------------------- +package Tie::CPHash; +# +# Copyright 1997 Christopher J. Madsen +# +# Author: Christopher J. Madsen <cjm@pobox.com> +# Created: 08 Nov 1997 +# $Revision$ $Date$ +# +# This program is free software; you can redistribute it and/or modify +# it under the same terms as Perl itself. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the +# GNU General Public License or the Artistic License for more details. +# +# Case preserving but case insensitive hash +#--------------------------------------------------------------------- + +require 5.000; +use strict; +use vars qw(@ISA $VERSION); + +@ISA = qw(); + +#===================================================================== +# Package Global Variables: + +$VERSION = '1.02'; + +#===================================================================== +# Tied Methods: +#--------------------------------------------------------------------- +# TIEHASH classname +# The method invoked by the command `tie %hash, classname'. +# Associates a new hash instance with the specified class. + +sub TIEHASH +{ + bless {}, $_[0]; +} # end TIEHASH + +#--------------------------------------------------------------------- +# STORE this, key, value +# Store datum *value* into *key* for the tied hash *this*. + +sub STORE +{ + $_[0]->{lc $_[1]} = [ $_[1], $_[2] ]; +} # end STORE + +#--------------------------------------------------------------------- +# FETCH this, key +# Retrieve the datum in *key* for the tied hash *this*. + +sub FETCH +{ + my $v = $_[0]->{lc $_[1]}; + ($v ? $v->[1] : undef); +} # end FETCH + +#--------------------------------------------------------------------- +# FIRSTKEY this +# Return the (key, value) pair for the first key in the hash. + +sub FIRSTKEY +{ + my $a = scalar keys %{$_[0]}; + &NEXTKEY; +} # end FIRSTKEY + +#--------------------------------------------------------------------- +# NEXTKEY this, lastkey +# Return the next (key, value) pair for the hash. + +sub NEXTKEY +{ + my $v = (each %{$_[0]})[1]; + ($v ? $v->[0] : undef ); +} # end NEXTKEY + +#--------------------------------------------------------------------- +# SCALAR this +# Return bucket usage information for the hash (0 if empty). + +sub SCALAR +{ + scalar %{$_[0]}; +} # end SCALAR + +#--------------------------------------------------------------------- +# EXISTS this, key +# Verify that *key* exists with the tied hash *this*. + +sub EXISTS +{ + exists $_[0]->{lc $_[1]}; +} # end EXISTS + +#--------------------------------------------------------------------- +# DELETE this, key +# Delete the key *key* from the tied hash *this*. +# Returns the old value, or undef if it didn't exist. + +sub DELETE +{ + my $v = delete $_[0]->{lc $_[1]}; + ($v ? $v->[1] : undef); +} # end DELETE + +#--------------------------------------------------------------------- +# CLEAR this +# Clear all values from the tied hash *this*. + +sub CLEAR +{ + %{$_[0]} = (); +} # end CLEAR + +#===================================================================== +# Other Methods: +#--------------------------------------------------------------------- +# Return the case of KEY. + +sub key +{ + my $v = $_[0]->{lc $_[1]}; + ($v ? $v->[0] : undef); +} + +#===================================================================== +# Package Return Value: + +1; + +__END__ + +=head1 NAME + +Tie::CPHash - Case preserving but case insensitive hash table + +=head1 SYNOPSIS + + require Tie::CPHash; + tie %cphash, 'Tie::CPHash'; + + $cphash{'Hello World'} = 'Hi there!'; + printf("The key `%s' was used to store `%s'.\n", + tied(%cphash)->key('HELLO WORLD'), + $cphash{'HELLO world'}); + +=head1 DESCRIPTION + +The B<Tie::CPHash> module provides a hash table that is case +preserving but case insensitive. This means that + + $cphash{KEY} $cphash{key} + $cphash{Key} $cphash{keY} + +all refer to the same entry. Also, the hash remembers which form of +the key was last used to store the entry. The C<keys> and C<each> +functions will return the key that was used to set the value. + +An example should make this clear: + + tie %h, 'Tie::CPHash'; + $h{Hello} = 'World'; + print $h{HELLO}; # Prints 'World' + print keys(%h); # Prints 'Hello' + $h{HELLO} = 'WORLD'; + print $h{hello}; # Prints 'WORLD' + print keys(%h); # Prints 'HELLO' + +The additional C<key> method lets you fetch the case of a specific key: + + # When run after the previous example, this prints 'HELLO': + print tied(%h)->key('Hello'); + +(The C<tied> function returns the object that C<%h> is tied to.) + +If you need a case insensitive hash, but don't need to preserve case, +just use C<$hash{lc $key}> instead of C<$hash{$key}>. This has a lot +less overhead than B<Tie::CPHash>. + +=head1 AUTHOR + +Christopher J. Madsen E<lt>F<cjm@pobox.com>E<gt> + +=cut + +# Local Variables: +# tmtrack-file-task: "Tie::CPHash.pm" +# End: diff --git a/t/compat.t b/t/compat.t new file mode 100644 index 0000000..101f573 --- /dev/null +++ b/t/compat.t @@ -0,0 +1,563 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use File::Spec; +use Config; + +# Don't let our own verbosity/test_file get mixed up with our subprocess's +my @makefile_keys = qw(TEST_VERBOSE HARNESS_VERBOSE TEST_FILES MAKEFLAGS); +local @ENV{@makefile_keys}; +delete @ENV{@makefile_keys}; + +my @makefile_types = qw(small passthrough traditional); +my $tests_per_type = 15; + +#find_in_path does not understand VMS. + +if ( $Config{make} && $^O ne 'VMS' ? find_in_path($Config{make}) : 1 ) { + plan 'no_plan'; +} else { + plan skip_all => "Don't know how to invoke 'make'"; +} + +my $is_vms_mms = ($^O eq 'VMS') && ($Config{make} =~ /MM[SK]/i); + +blib_load('Module::Build'); + + +######################### + +my $tmp = MBTest->tmpdir; + +# Create test distribution; set requires and build_requires +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + + +######################### + +blib_load('Module::Build'); +blib_load('Module::Build::Compat'); + +use Carp; $SIG{__WARN__} = \&Carp::cluck; + +my @make = $Config{make} eq 'nmake' ? ('nmake', '-nologo') : ($Config{make}); + +my $makefile = 'Makefile'; + +# VMS MMK/MMS by convention use Descrip.MMS +if ($is_vms_mms) { + $makefile = 'Descrip.MMS'; +} + + +######################### + +# Test without requires + +test_makefile_types(); + +# Test with requires and PL_files + +my $distname = $dist->name; +$dist->change_build_pl({ + module_name => $distname, + license => 'perl', + requires => { + 'perl' => $], + 'File::Spec' => 0.2, + }, + build_requires => { + 'Test::More' => 0, + 'File::Spec' => 0, + }, + PL_files => { 'foo.PL' => 'foo' }, +}); + +$dist->add_file("foo.PL", <<'END'); +open my $fh, ">$ARGV[0]" or die $!; +print $fh "foo\n"; +END + +$dist->regen; + +test_makefile_types( + requires => { + 'perl' => $], + 'File::Spec' => 0.2, + }, + build_requires => { + 'Test::More' => 0, + 'File::Spec' => 0, + }, + PL_files => { + 'foo.PL' => 'foo', + }, +); + +###################### + +$dist->change_build_pl({ + module_name => $distname, + license => 'perl', +}); +$dist->regen; + +# Create M::B instance but don't pollute STDOUT +my $mb; +stdout_stderr_of( sub { + $mb = Module::Build->new_from_context; +}); +ok $mb, "Module::Build->new_from_context"; + + +{ + # Make sure fake_makefile() can run without 'build_class', as it may be + # in older-generated Makefile.PLs + my $warning = ''; + local $SIG{__WARN__} = sub { $warning = shift; }; + + my $maketext = eval { Module::Build::Compat->fake_makefile(makefile => $makefile) }; + is $@, '', "fake_makefile lived"; + like $maketext, qr/^realclean/m, "found 'realclean' in fake_makefile output"; + like $warning, qr/build_class/, "saw warning about 'build_class'"; +} + +{ + # Make sure custom builder subclass is used in the created + # Makefile.PL - make sure it fails in the right way here. + local @Foo::Builder::ISA = qw(Module::Build); + my $foo_builder; + stdout_stderr_of( sub { + $foo_builder = Foo::Builder->new_from_context; + }); + foreach my $style ('passthrough', 'small') { + create_makefile_pl($style, $foo_builder); + + # Should fail with "can't find Foo/Builder.pm" + my $result; + my ($stdout, $stderr ) = stdout_stderr_of (sub { + $result = $mb->run_perl_script('Makefile.PL'); + }); + ok ! $result, "Makefile.PL failed"; + like $stderr, qr{Foo/Builder.pm}, "custom builder wasn't found"; + } + + # Now make sure it can actually work. + my $bar_builder; + stdout_stderr_of( sub { + $bar_builder = Module::Build->subclass( class => 'Bar::Builder' )->new_from_context; + }); + foreach my $style ('passthrough', 'small') { + create_makefile_pl($style, $bar_builder); + my $result; + stdout_stderr_of( sub { + $result = $mb->run_perl_script('Makefile.PL'); + }); + ok $result, "Makefile.PL ran without error"; + } +} + +{ + # Make sure various Makefile.PL arguments are supported + create_makefile_pl('passthrough', $mb); + + my $libdir = File::Spec->catdir( $tmp, 'libdir' ); + my $result; + stdout_stderr_of( sub { + $result = $mb->run_perl_script('Makefile.PL', [], + [ + "LIB=$libdir", + 'TEST_VERBOSE=1', + 'INSTALLDIRS=perl', + 'POLLUTE=1', + ] + ); + }); + ok $result, "passthrough Makefile.PL ran with arguments"; + ok -e 'Build.PL', "Build.PL generated"; + + my $new_build = Module::Build->resume(); + is $new_build->installdirs, 'core', "installdirs is core"; + is $new_build->verbose, 1, "tests set for verbose"; + is $new_build->install_destination('lib'), $libdir, "custom libdir"; + is $new_build->extra_compiler_flags->[0], '-DPERL_POLLUTE', "PERL_POLLUTE set"; + + # Make sure those switches actually had an effect + my ($ran_ok, $output); + $output = stdout_stderr_of( sub { $ran_ok = $new_build->do_system(@make, 'test') } ); + ok $ran_ok, "make test ran without error"; + $output =~ s/^/# /gm; # Don't confuse our own test output + like $output, qr/(?:# ok \d+\s+)+/, 'Should be verbose'; + + # Make sure various Makefile arguments are supported + my $make_macro = 'TEST_VERBOSE=0'; + + # VMS MMK/MMS macros use different syntax. + if ($is_vms_mms) { + $make_macro = '/macro=("' . $make_macro . '")'; + } + + $output = stdout_stderr_of( sub { + local $ENV{HARNESS_TIMER}; # RT#39635 - timer messes with output + $ran_ok = $mb->do_system(@make, 'test', $make_macro) + } ); + + ok $ran_ok, "make test without verbose ran ok"; + $output =~ s/^/# /gm; # Don't confuse our own test output + like $output, + qr/# .+basic(\.t)?[.\s#]+ok[.\s#]+All tests successful/, + 'Should be non-verbose'; + + (my $libdir2 = $libdir) =~ s/libdir/lbiidr/; + my $libarch2 = File::Spec->catdir($libdir2, 'arch'); + my $check_base = $libdir2; + $check_base =~ s/\]\z// if $^O eq 'VMS'; # trim trailing ] for appending other dirs + + SKIP: { + my @cases = ( + { + label => "INSTALLDIRS=vendor", + args => [ 'INSTALLDIRS=vendor', "INSTALLVENDORLIB=$libdir2", "INSTALLVENDORARCH=$libarch2"], + check => qr/\Q$check_base\E .* Simple\.pm/ix, + }, + { + label => "PREFIX=\$libdir2", + args => [ "PREFIX=$libdir2"], + check => qr/\Q$check_base\E .* Simple\.pm/ix, + }, + { + label => "PREFIX=\$libdir2 LIB=mylib", + args => [ "PREFIX=$libdir2", "LIB=mylib" ], + check => qr{\Q$check_base\E[/\\\.]mylib[/\\\]]Simple\.pm}ix, + }, + ); + + require ExtUtils::Install; + skip "Needs ExtUtils::Install 1.32 or later", 2 * @cases + if ExtUtils::Install->VERSION < 1.32; + + for my $c (@cases) { + my @make_args = @{$c->{args}}; + ($output) = stdout_stderr_of( + sub { + $result = $mb->run_perl_script('Makefile.PL', [], \@make_args); + $ran_ok = $mb->do_system(@make, 'fakeinstall'); + } + ); + + ok $ran_ok, "fakeinstall $c->{label} ran ok"; + $output =~ s/^/# /gm; # Don't confuse our own test output + like $output, $c->{check}, + "Saw destination directory for $c->{label}"; + } + } + + stdout_stderr_of( sub { $mb->do_system(@make, 'realclean'); } ); + ok ! -e $makefile, "$makefile shouldn't exist"; + + 1 while unlink 'Makefile.PL'; + ok ! -e 'Makefile.PL', "Makefile.PL cleaned up"; + + 1 while unlink $libdir, $libdir2; +} + +{ # Make sure tilde-expansion works + + # C<glob> on MSWin32 uses $ENV{HOME} if defined to do tilde-expansion + local $ENV{HOME} = 'C:/' if $^O =~ /MSWin/ && !exists( $ENV{HOME} ); + + create_makefile_pl('passthrough', $mb); + + stdout_stderr_of( sub { + $mb->run_perl_script('Makefile.PL', [], ['INSTALL_BASE=~/foo']); + }); + my $b2 = Module::Build->current; + ok $b2->install_base, "install_base set"; + unlike $b2->install_base, qr/^~/, "Tildes should be expanded"; + + stdout_stderr_of( sub { $mb->do_system(@make, 'realclean'); } ); + ok ! -e $makefile, "$makefile shouldn't exist"; + + 1 while unlink 'Makefile.PL'; + ok ! -e 'Makefile.PL', "Makefile.PL cleaned up"; +} + +{ + $dist->add_file('t/deep/foo.t', q{}); + $dist->regen; + + my $mb; + stdout_stderr_of( sub { + $mb = Module::Build->new_from_context( recursive_test_files => 1 ); + }); + + create_makefile_pl('traditional', $mb); + my $args = extract_writemakefile_args() || {}; + + if ( exists $args->{test}->{TESTS} ) { + is $args->{test}->{TESTS}, + join( q{ }, + File::Spec->catfile(qw(t *.t)), + File::Spec->catfile(qw(t deep *.t)) + ), + 'Makefile.PL has correct TESTS line for recursive test files'; + } else { + ok( ! exists $args->{TESTS}, 'Not using incorrect recursive tests key' ); + } + + 1 while unlink 'Makefile.PL'; + ok ! -e 'Makefile.PL', "Makefile.PL cleaned up"; +} + +{ + # make sure using prereq with '0.1.2' complains + $dist->change_build_pl({ + module_name => $distname, + license => 'perl', + requires => { + 'Foo::Frobnicate' => '0.1.2', + }, + create_makefile_pl => 'traditional', + }); + $dist->regen; + + my $mb; + stdout_stderr_of( sub { + $mb = Module::Build->new_from_context; + }); + + my $output = stdout_stderr_of( sub { $mb->do_create_makefile_pl } ); + ok -e 'Makefile.PL', "Makefile.PL created"; + like $output, qr/is not portable/, "Correctly complains and converts dotted-decimal"; + + my $file_contents = slurp 'Makefile.PL'; + like $file_contents, qr/Foo::Frobnicate.+0\.001002/, "Properly converted dotted-decimal"; + + 1 while unlink 'Makefile.PL'; + ok ! -e 'Makefile.PL', "Makefile.PL cleaned up"; +} + +{ + # make sure using invalid prereq blows up + $dist->change_build_pl({ + module_name => $distname, + license => 'perl', + requires => { + 'Foo::Frobnicate' => '3.5_2_7', + }, + create_makefile_pl => 'traditional', + }); + $dist->regen; + + ok ! -e 'Makefile.PL', "Makefile.PL doesn't exist before we start"; + + my $mb; + stdout_stderr_of( sub { + $mb = $dist->run_build_pl; + }); + + my ($output, $error) = stdout_stderr_of( sub { $dist->run_build('distmeta') } ); + like $error, qr/is not supported/ms, "Correctly dies when it encounters invalid prereq"; + ok ! -e 'Makefile.PL', "Makefile.PL NOT created"; + + 1 while unlink 'Makefile.PL'; + ok ! -e 'Makefile.PL', "Makefile.PL cleaned up"; +} + +######################################################### + +sub _merge_prereqs { + my ($first, $second) = @_; + my $new = { %$first }; + for my $k (keys %$second) { + if ( exists $new->{$k} ) { + my ($v1,$v2) = ($new->{$k},$second->{$k}); + $new->{$k} = ($v1 > $v2 ? $v1 : $v2); + } + else { + $new->{$k} = $second->{$k}; + } + } + return $new; +} + +sub test_makefile_types { + my %opts = @_; + $opts{requires} ||= {}; + $opts{build_requires} ||= {}; + $opts{PL_files} ||= {}; + + foreach my $type (@makefile_types) { + # Create M::B instance + my $mb; + stdout_stderr_of( sub { + $mb = Module::Build->new_from_context; + }); + ok $mb, "Module::Build->new_from_context"; + + # Create and test Makefile.PL + create_makefile_pl($type, $mb); + + test_makefile_pl_requires_perl( $opts{requires}{perl} ); + test_makefile_creation($mb); + test_makefile_prereq_pm( _merge_prereqs($opts{requires}, $opts{build_requires}) ); + test_makefile_pl_files( $opts{PL_files} ) if $type eq 'traditional'; + + my ($output,$success); + # Capture output to keep our STDOUT clean + $output = stdout_stderr_of( sub { + $success = $mb->do_system(@make); + }); + ok $success, "make ran without error"; + + for my $file (values %{ $opts{PL_files} }) { + ok -e $file, "PL_files generated - $file"; + } + + # Can't let 'test' STDOUT go to our STDOUT, or it'll confuse Test::Harness. + $output = stdout_stderr_of( sub { + $success = $mb->do_system(@make, 'test'); + }); + ok $success, "make test ran without error"; + like uc $output, qr{DONE\.|SUCCESS}, "make test output indicated success"; + + $output = stdout_stderr_of( sub { + $success = $mb->do_system(@make, 'realclean'); + }); + ok $success, "make realclean ran without error"; + + # Try again with some Makefile.PL arguments + test_makefile_creation($mb, [], 'INSTALLDIRS=vendor', 'realclean'); + + # Try again using distclean + test_makefile_creation($mb, [], '', 'distclean'); + + 1 while unlink 'Makefile.PL'; + ok ! -e 'Makefile.PL', "cleaned up Makefile"; + } +} + +sub test_makefile_creation { + my ($build, $preargs, $postargs, $cleanup) = @_; + + my ($output, $result); + # capture output to avoid polluting our test output + $output = stdout_stderr_of( sub { + $result = $build->run_perl_script('Makefile.PL', $preargs, $postargs); + }); + my $label = "Makefile.PL ran without error"; + if ( defined $postargs && length $postargs ) { + $label .= " (postargs: $postargs)"; + } + ok $result, $label; + ok -e $makefile, "$makefile exists"; + + if ($cleanup) { + # default to 'realclean' unless we recognize the clean method + $cleanup = 'realclean' unless $cleanup =~ /^(dist|real)clean$/; + my ($stdout, $stderr ) = stdout_stderr_of (sub { + $build->do_system(@make, $cleanup); + }); + ok ! -e $makefile, "$makefile cleaned up with $cleanup"; + } + else { + pass '(skipping cleanup)'; # keep test count constant + } +} + +sub test_makefile_prereq_pm { + my %requires = %{ $_[0] }; + delete $requires{perl}; # until EU::MM supports this + SKIP: { + skip "$makefile not found", 1 unless -e $makefile; + my $prereq_pm = find_params_in_makefile()->{PREREQ_PM} || {}; + is_deeply $prereq_pm, \%requires, + "$makefile has correct PREREQ_PM line"; + } +} + +sub test_makefile_pl_files { + my $expected = shift; + + SKIP: { + skip 1, 'Makefile.PL not found' unless -e 'Makefile.PL'; + my $args = extract_writemakefile_args() || {}; + is_deeply $args->{PL_FILES}, $expected, + "Makefile.PL has correct PL_FILES line"; + } +} + +sub test_makefile_pl_requires_perl { + my $perl_version = shift || q{}; + SKIP: { + skip 1, 'Makefile.PL not found' unless -e 'Makefile.PL'; + my $file_contents = slurp 'Makefile.PL'; + my $found_requires = $file_contents =~ m{^require $perl_version;}ms; + if (length $perl_version) { + ok $found_requires, "Makefile.PL has 'require $perl_version;'" + or diag "Makefile.PL:\n$file_contents"; + } + else { + ok ! $found_requires, "Makefile.PL does not require a perl version"; + } + } +} + +sub find_params_in_makefile { + open(my $fh, '<', $makefile ) + or die "Can't read $makefile: $!"; + local($/) = "\n"; + + my %params; + while (<$fh>) { + # Blank line after params. + last if keys %params and !/\S+/; + + next unless m{^\# \s+ ( [A-Z_]+ ) \s+ => \s+ ( .* )$}x; + + my($key, $val) = ($1, $2); + # extract keys and values + while ( $val =~ m/(?:\s)(\S+)=>(q\[.*?\]|undef),?/g ) { + my($m,$n) = ($1,$2); + if ($n =~ /^q\[(.*?)\]$/) { + $n = $1; + } + $params{$key}{$m} = $n; + } + } + + return \%params; +} + +sub extract_writemakefile_args { + SKIP: { + skip 1, 'Makefile.PL not found' unless -e 'Makefile.PL'; + my $file_contents = slurp 'Makefile.PL'; + my ($args) = $file_contents =~ m{^WriteMakefile\n\((.*)\).*;}ms; + ok $args, "Found WriteMakefile arguments" + or diag "Makefile.PL:\n$file_contents"; + my %args = eval $args or diag $args; ## no critic + return \%args; + } +} + +sub create_makefile_pl { + my @args = @_; + stdout_stderr_of( sub { Module::Build::Compat->create_makefile_pl(@args) } ); + my $ok = ok -e 'Makefile.PL', "$_[0] Makefile.PL created"; + + # Some really conservative make's, like HP/UX, assume files with the same + # timestamp are out of date. Send the Makefile.PL one second into the past + # so its older than the Makefile it will generate. + # See [rt.cpan.org 45700] + my $mtime = (stat("Makefile.PL"))[9]; + utime $mtime, $mtime - 1, "Makefile.PL"; + + return $ok; +} diff --git a/t/compat/exit.t b/t/compat/exit.t new file mode 100644 index 0000000..3672c93 --- /dev/null +++ b/t/compat/exit.t @@ -0,0 +1,53 @@ +#!/usr/bin/perl -w + +use strict; + +use lib 't/lib'; +use MBTest tests => 3; + +blib_load('Module::Build'); + +######################### + +my $tmp = MBTest->tmpdir; + +# Create test distribution; set requires and build_requires +use DistGen; +my $dist = DistGen->new( dir => $tmp ); + +$dist->regen; + +$dist->chdir_in; + +######################### + +my $mb; stdout_of(sub{ $mb = Module::Build->new_from_context}); + +blib_load('Module::Build::Compat'); + +$dist->regen; + +stdout_stderr_of( + sub{ Module::Build::Compat->create_makefile_pl('passthrough', $mb); } +); + +# as silly as all of this exit(0) business is, that is what the cpan +# testers have instructed everybody to do so... +$dist->change_file('Build.PL' => + "warn qq(you have no libthbbt\n); exit;\n" . $dist->get_file('Build.PL') +); + +$dist->regen; + +stdout_of(sub{ $mb->ACTION_realclean }); + +my $result; +my ($stdout, $stderr ) = stdout_stderr_of (sub { + $result = $mb->run_perl_script('Makefile.PL'); +}); +ok $result, "Makefile.PL exit"; +like $stdout, qr/running Build\.PL/; +like $stderr, qr/you have no libthbbt$/; +#warn "out: $stdout"; warn "err: $stderr"; + +# vim:ts=2:sw=2:et:sta diff --git a/t/debug.t b/t/debug.t new file mode 100644 index 0000000..e0b8f60 --- /dev/null +++ b/t/debug.t @@ -0,0 +1,27 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 1; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; +$dist->chdir_in; + +######################### + +# Test debug output +{ + my $output; + $output = stdout_of sub { $dist->run_build_pl }; + $output = stdout_of sub { $dist->run_build('--debug') }; + like($output, '/Starting ACTION_build.*?Starting ACTION_code.*?Finished ACTION_code.*?Finished ACTION_build/ms', + "found nested ACTION_* debug statements" + ); +} + diff --git a/t/destinations.t b/t/destinations.t new file mode 100644 index 0000000..2b9aba6 --- /dev/null +++ b/t/destinations.t @@ -0,0 +1,323 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 113; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + + +use Config; +use File::Spec::Functions qw( catdir splitdir splitpath ); + +######################### + +# We need to create a well defined environment to test install paths. +# We do this by setting up appropriate Config entries. + +my @installstyle = qw(lib perl5); +my $mb = Module::Build->new_from_context( + installdirs => 'site', + config => { + installstyle => catdir(@installstyle), + + installprivlib => catdir($tmp, @installstyle), + installarchlib => catdir($tmp, @installstyle, + @Config{qw(version archname)}), + installbin => catdir($tmp, 'bin'), + installscript => catdir($tmp, 'bin'), + installman1dir => catdir($tmp, 'man', 'man1'), + installman3dir => catdir($tmp, 'man', 'man3'), + installhtml1dir => catdir($tmp, 'html'), + installhtml3dir => catdir($tmp, 'html'), + + installsitelib => catdir($tmp, 'site', @installstyle, 'site_perl'), + installsitearch => catdir($tmp, 'site', @installstyle, 'site_perl', + @Config{qw(version archname)}), + installsitebin => catdir($tmp, 'site', 'bin'), + installsitescript => catdir($tmp, 'site', 'bin'), + installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'), + installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'), + installsitehtml1dir => catdir($tmp, 'site', 'html'), + installsitehtml3dir => catdir($tmp, 'site', 'html'), + } +); +isa_ok( $mb, 'Module::Build::Base' ); + +# Get us into a known state. +$mb->install_base(undef); +$mb->prefix(undef); + + +# Check install_path() accessor +{ + my( $map, $path ); + + $map = $mb->install_path(); + is_deeply( $map, {}, 'install_path() accessor' ); + + $path = $mb->install_path('elem' => '/foo/bar'); + is( $path, '/foo/bar', ' returns assigned path' ); + + $path = $mb->install_path('elem'); + is( $path, '/foo/bar', ' can read stored path' ); + + $map = $mb->install_path(); + is_deeply( $map, { 'elem' => '/foo/bar' }, ' can access map' ); + + $path = $mb->install_path('elem' => undef); + is( $path, undef, ' can delete a path element' ); + + $map = $mb->install_path(); + is_deeply( $map, {}, ' deletes path from map' ); +} + +# Check install_base_relpaths() accessor +{ + my( $map, $path ); + + $map = $mb->install_base_relpaths(); + is( ref($map), 'HASH', 'install_base_relpaths() accessor' ); + + eval{ $path = $mb->install_base_relpaths('elem' => '/foo/bar') }; + like( $@, qr/Value must be a relative path/, ' emits error if path not relative' ); + + $path = $mb->install_base_relpaths('elem' => 'foo/bar'); + is( $path, catdir(qw(foo bar)), ' returns assigned path' ); + + $path = $mb->install_base_relpaths('elem'); + is( $path, catdir(qw(foo/bar)), ' can read stored path' ); + + $map = $mb->install_base_relpaths(); + is_deeply( $map->{elem}, [qw(foo bar)], ' can access map' ); + + $path = $mb->install_base_relpaths('elem' => undef); + is( $path, undef, ' can delete a path element' ); + + $map = $mb->install_base_relpaths(); + is( $map->{elem}, undef, ' deletes path from map' ); +} + +# Check prefix_relpaths() accessor +{ + my( $map, $path ); + + $map = $mb->prefix_relpaths(); + is( ref($map), 'HASH', 'prefix_relpaths() accessor' ); + + is_deeply( $mb->prefix_relpaths(), $mb->prefix_relpaths('site'), + ' defaults to \'site\'' ); + + eval{ $path = $mb->prefix_relpaths('site', 'elem' => '/foo/bar') }; + like( $@, qr/Value must be a relative path/, ' emits error if path not relative' ); + + $path = $mb->prefix_relpaths('site', 'elem' => 'foo/bar'); + is( $path, catdir(qw(foo bar)), ' returns assigned path' ); + + $path = $mb->prefix_relpaths('site', 'elem'); + is( $path, catdir(qw(foo bar)), ' can read stored path' ); + + $map = $mb->prefix_relpaths(); + is_deeply( $map->{elem}, [qw(foo bar)], ' can access map' ); + + $path = $mb->prefix_relpaths('site', 'elem' => undef); + is( $path, undef, ' can delete a path element' ); + + $map = $mb->prefix_relpaths(); + is( $map->{elem}, undef, ' deletes path from map' ); +} + + +# Check that we install into the proper default locations. +{ + is( $mb->installdirs, 'site' ); + is( $mb->install_base, undef ); + is( $mb->prefix, undef ); + + test_install_destinations( $mb, { + lib => catdir($tmp, 'site', @installstyle, 'site_perl'), + arch => catdir($tmp, 'site', @installstyle, 'site_perl', + @Config{qw(version archname)}), + bin => catdir($tmp, 'site', 'bin'), + script => catdir($tmp, 'site', 'bin'), + bindoc => catdir($tmp, 'site', 'man', 'man1'), + libdoc => catdir($tmp, 'site', 'man', 'man3'), + binhtml => catdir($tmp, 'site', 'html'), + libhtml => catdir($tmp, 'site', 'html'), + }); +} + + +# Is installdirs honored? +{ + $mb->installdirs('core'); + is( $mb->installdirs, 'core' ); + + test_install_destinations( $mb, { + lib => catdir($tmp, @installstyle), + arch => catdir($tmp, @installstyle, @Config{qw(version archname)}), + bin => catdir($tmp, 'bin'), + script => catdir($tmp, 'bin'), + bindoc => catdir($tmp, 'man', 'man1'), + libdoc => catdir($tmp, 'man', 'man3'), + binhtml => catdir($tmp, 'html'), + libhtml => catdir($tmp, 'html'), + }); + + $mb->installdirs('site'); + is( $mb->installdirs, 'site' ); +} + + +# Check install_base() +{ + my $install_base = catdir( 'foo', 'bar' ); + $mb->install_base( $install_base ); + + is( $mb->prefix, undef ); + is( $mb->install_base, $install_base ); + + + test_install_destinations( $mb, { + lib => catdir( $install_base, 'lib', 'perl5' ), + arch => catdir( $install_base, 'lib', 'perl5', $Config{archname} ), + bin => catdir( $install_base, 'bin' ), + script => catdir( $install_base, 'bin' ), + bindoc => catdir( $install_base, 'man', 'man1'), + libdoc => catdir( $install_base, 'man', 'man3' ), + binhtml => catdir( $install_base, 'html' ), + libhtml => catdir( $install_base, 'html' ), + }); +} + + +# Basic prefix test. Ensure everything is under the prefix. +{ + $mb->install_base( undef ); + ok( !defined $mb->install_base ); + + my $prefix = catdir( qw( some prefix ) ); + $mb->prefix( $prefix ); + is( $mb->{properties}{prefix}, $prefix ); + + test_prefix($prefix, $mb->install_sets('site')); +} + + +# And now that prefix honors installdirs. +{ + $mb->installdirs('core'); + is( $mb->installdirs, 'core' ); + + my $prefix = catdir( qw( some prefix ) ); + test_prefix($prefix); + + $mb->installdirs('site'); + is( $mb->installdirs, 'site' ); +} + + +# Try a config setting which would result in installation locations outside +# the prefix. Ensure it doesn't. +{ + # Get the prefix defaults + my $defaults = $mb->prefix_relpaths('site'); + + # Create a configuration involving weird paths that are outside of + # the configured prefix. + my @prefixes = ( + [qw(foo bar)], + [qw(biz)], + [], + ); + + my %test_config; + foreach my $type (keys %$defaults) { + my $prefix = shift @prefixes || [qw(foo bar)]; + $test_config{$type} = catdir(File::Spec->rootdir, @$prefix, + @{$defaults->{$type}}); + } + + # Poke at the innards of MB to change the default install locations. + my $old = $mb->install_sets->{site}; + $mb->install_sets->{site} = \%test_config; + $mb->config(siteprefixexp => catdir(File::Spec->rootdir, + 'wierd', 'prefix')); + + my $prefix = catdir('another', 'prefix'); + $mb->prefix($prefix); + test_prefix($prefix, \%test_config); + $mb->install_sets->{site} = $old; +} + + +# Check that we can use install_base after setting prefix. +{ + my $install_base = catdir( 'foo', 'bar' ); + $mb->install_base( $install_base ); + + test_install_destinations( $mb, { + lib => catdir( $install_base, 'lib', 'perl5' ), + arch => catdir( $install_base, 'lib', 'perl5', $Config{archname} ), + bin => catdir( $install_base, 'bin' ), + script => catdir( $install_base, 'bin' ), + bindoc => catdir( $install_base, 'man', 'man1'), + libdoc => catdir( $install_base, 'man', 'man3' ), + binhtml => catdir( $install_base, 'html' ), + libhtml => catdir( $install_base, 'html' ), + }); +} + + +sub test_prefix { + my ($prefix, $test_config) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + foreach my $type (qw(lib arch bin script bindoc libdoc binhtml libhtml)) { + my $dest = $mb->install_destination( $type ); + ok $mb->dir_contains($prefix, $dest), "$type prefixed"; + + SKIP: { + skip( "'$type' not configured", 1 ) + unless $test_config && $test_config->{$type}; + + have_same_ending( $dest, $test_config->{$type}, + " suffix correctish " . + "($test_config->{$type} + $prefix = $dest)" ); + } + } +} + +sub have_same_ending { + my ($dir1, $dir2, $message) = @_; + + $dir1 =~ s{/$}{} if $^O eq 'cygwin'; # remove any trailing slash + my (undef, $dirs1, undef) = splitpath $dir1; + my @dir1 = splitdir $dirs1; + + $dir2 =~ s{/$}{} if $^O eq 'cygwin'; # remove any trailing slash + my (undef, $dirs2, undef) = splitpath $dir2; + my @dir2 = splitdir $dirs2; + + is $dir1[-1], $dir2[-1], $message; +} + +sub test_install_destinations { + my($build, $expect) = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + while( my($type, $expect) = each %$expect ) { + is( $build->install_destination($type), $expect, "$type destination" ); + } +} + @@ -0,0 +1,161 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; + +my @unix_splits = + ( + { q{one t'wo th'ree f"o\"ur " "five" } => [ 'one', 'two three', 'fo"ur ', 'five' ] }, + { q{ foo bar } => [ 'foo', 'bar' ] }, + { q{ D\'oh f\{g\'h\"i\]\* } => [ "D'oh", "f{g'h\"i]*" ] }, + { q{ D\$foo } => [ 'D$foo' ] }, + { qq{one\\\ntwo} => [ "one\ntwo" ] }, # TODO + ); + +my @win_splits = + ( + { 'a" "b\\c" "d' => [ 'a b\c d' ] }, + { '"a b\\c d"' => [ 'a b\c d' ] }, + { '"a b"\\"c d"' => [ 'a b"c', 'd' ] }, + { '"a b"\\\\"c d"' => [ 'a b\c d' ] }, + { '"a"\\"b" "a\\"b"' => [ 'a"b a"b' ] }, + { '"a"\\\\"b" "a\\\\"b"' => [ 'a\b', 'a\b' ] }, + { '"a"\\"b a\\"b"' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a"\\"b" "a\\"b' => [ 'a"b', 'a"b' ] }, + { 'a b' => [ 'a', 'b' ] }, + { 'a"\\"b a\\"b' => [ 'a"b a"b' ] }, + { '"a""b" "a"b"' => [ 'a"b ab' ] }, + { '\\"a\\"' => [ '"a"' ] }, + { '"a"" "b"' => [ 'a"', 'b' ] }, + { 'a"b' => [ 'ab' ] }, + { 'a""b' => [ 'ab' ] }, + { 'a"""b' => [ 'a"b' ] }, + { 'a""""b' => [ 'a"b' ] }, + { 'a"""""b' => [ 'a"b' ] }, + { 'a""""""b' => [ 'a""b' ] }, + { '"a"b"' => [ 'ab' ] }, + { '"a""b"' => [ 'a"b' ] }, + { '"a"""b"' => [ 'a"b' ] }, + { '"a""""b"' => [ 'a"b' ] }, + { '"a"""""b"' => [ 'a""b' ] }, + { '"a""""""b"' => [ 'a""b' ] }, + { '' => [ ] }, + { ' ' => [ ] }, + { '""' => [ '' ] }, + { '" "' => [ ' ' ] }, + { '""a' => [ 'a' ] }, + { '""a b' => [ 'a', 'b' ] }, + { 'a""' => [ 'a' ] }, + { 'a"" b' => [ 'a', 'b' ] }, + { '"" a' => [ '', 'a' ] }, + { 'a ""' => [ 'a', '' ] }, + { 'a "" b' => [ 'a', '', 'b' ] }, + { 'a " " b' => [ 'a', ' ', 'b' ] }, + { 'a " b " c' => [ 'a', ' b ', 'c' ] }, +); + +plan tests => 9 + 4*@unix_splits + 4*@win_splits; + +blib_load('Module::Build'); +blib_load('Module::Build::Platform::Unix'); +blib_load('Module::Build::Platform::Windows'); + +######################### + +# Should always return an array unscathed +foreach my $platform ('', '::Platform::Unix', '::Platform::Windows') { + my $pkg = "Module::Build$platform"; + my @result = $pkg->split_like_shell(['foo', 'bar', 'baz']); + is @result, 3, "Split using $pkg"; + is "@result", "foo bar baz", "Split using $pkg"; +} + +# I think 3.24 isn't actually the majik version, my 3.23 seems to pass... +my $low_TPW_version = Text::ParseWords->VERSION < 3.24; +foreach my $test (@unix_splits) { + # Text::ParseWords bug: + local $TODO = $low_TPW_version && ((keys %$test)[0] =~ m{\\\n}); + + do_split_tests('Module::Build::Platform::Unix', $test); +} + +foreach my $test (@win_splits) { + do_split_tests('Module::Build::Platform::Windows', $test); +} + + +{ + # Make sure read_args() functions properly as a class method + my @args = qw(foo=bar --food bard --foods=bards); + my ($args) = Module::Build->read_args(@args); + is_deeply($args, {foo => 'bar', food => 'bard', foods => 'bards', ARGV => []}); +} + +{ + # Make sure data can make a round-trip through unparse_args() and read_args() + my %args = (foo => 'bar', food => 'bard', config => {a => 1, b => 2}, ARGV => []); + my ($args) = Module::Build->read_args( Module::Build->unparse_args(\%args) ); + is_deeply($args, \%args); +} + +{ + # Make sure data can make a round-trip through an external perl + # process, which can involve the shell command line + + # silence the printing for easier matching + local *Module::Build::log_info = sub {}; + + my @data = map values(%$_), @unix_splits, @win_splits; + for my $d (@data) { + my $out = stdout_of + ( sub { + Module::Build->run_perl_script('-le', [], ['print join " ", map "{$_}", @ARGV', @$d]); + } ); + chomp $out; + is($out, join(' ', map "{$_}", @$d), "perl round trip for ".join('',map "{$_}", @$d)); + } +} + +{ + # Make sure data can make a round-trip through an external backtick + # process, which can involve the shell command line + + # silence the printing for easier matching + local *Module::Build::log_info = sub {}; + + my @data = map values(%$_), @unix_splits, @win_splits; + for my $d (@data) { + chomp(my $out = Module::Build->_backticks($^X, '-le', 'print join " ", map "{$_}", @ARGV', @$d)); + is($out, join(' ', map "{$_}", @$d), "backticks round trip for ".join('',map "{$_}", @$d)); + } +} + +{ + # Make sure run_perl_script() propagates @INC + my $dir = MBTest->tmpdir; + if ($^O eq 'VMS') { + # VMS can store INC paths in Unix format with out the trailing + # directory delimiter. + $dir = VMS::Filespec::unixify($dir); + $dir =~ s#/$##; + } + local @INC = ($dir, @INC); + my $output = stdout_of( sub { Module::Build->run_perl_script('-le', [], ['print for @INC']) } ); + like $output, qr{^\Q$dir\E}m; +} + +################################################################## +sub do_split_tests { + my ($package, $test) = @_; + + my ($string, $expected) = %$test; + my @result = $package->split_like_shell($string); + is( 0 + grep( !defined(), @result ), # all defined + 0, + "'$string' result all defined" ); + is_deeply(\@result, $expected) or + diag("$package split_like_shell error \n" . + ">$string< is not splitting as >" . join("|", @$expected) . '<'); +} diff --git a/t/extend.t b/t/extend.t new file mode 100644 index 0000000..ae30f8d --- /dev/null +++ b/t/extend.t @@ -0,0 +1,281 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 63; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + +######################### + +# Here we make sure actions are only called once per dispatch() +$::x = 0; +my $mb = Module::Build->subclass + ( + code => "sub ACTION_loop { die 'recursed' if \$::x++; shift->depends_on('loop'); }" + )->new( module_name => $dist->name ); +ok $mb; + +$mb->dispatch('loop'); +ok $::x; + +$mb->dispatch('realclean'); + +# Make sure the subclass can be subclassed +my $build2class = ref($mb)->subclass + ( + code => "sub ACTION_loop2 {}", + class => 'MBB', + ); +can_ok( $build2class, 'ACTION_loop' ); +can_ok( $build2class, 'ACTION_loop2' ); + + +{ # Make sure globbing works in filenames + $dist->add_file( 'script', <<'---' ); +#!perl -w +print "Hello, World!\n"; +--- + $dist->regen; + + $mb->test_files('*t*'); + my $files = $mb->test_files; + ok grep {$_ eq 'script'} @$files; + my $t_basic_t = File::Spec->catfile('t', 'basic.t'); + $t_basic_t = VMS::Filespec::vmsify($t_basic_t) if $^O eq 'VMS'; + ok grep {$_ eq $t_basic_t} @$files; + ok !grep {$_ eq 'Build.PL' } @$files; + + # Make sure order is preserved + $mb->test_files('foo', 'bar'); + $files = $mb->test_files; + is @$files, 2; + is $files->[0], 'foo'; + is $files->[1], 'bar'; + + $dist->remove_file( 'script' ); + $dist->regen( clean => 1 ); +} + + +{ + # Make sure we can add new kinds of stuff to the build sequence + + $dist->add_file( 'test.foo', "content\n" ); + $dist->regen; + + my $mb = Module::Build->new( module_name => $dist->name, + foo_files => {'test.foo', 'lib/test.foo'} ); + ok $mb; + + $mb->add_build_element('foo'); + $mb->add_build_element('foo'); + is_deeply $mb->build_elements, [qw(PL support pm xs share_dir pod script foo)], + 'The foo element should be in build_elements only once'; + + $mb->dispatch('build'); + ok -e File::Spec->catfile($mb->blib, 'lib', 'test.foo'); + + $mb->dispatch('realclean'); + + # revert distribution to a pristine state + $dist->remove_file( 'test.foo' ); + $dist->regen( clean => 1 ); +} + + +{ + package MBSub; + use Test::More; + use vars qw($VERSION @ISA); + @ISA = qw(Module::Build); + $VERSION = 0.01; + + # Add a new property. + ok(__PACKAGE__->add_property('foo')); + # Add a new property with a default value. + ok(__PACKAGE__->add_property('bar', 'hey')); + # Add a hash property. + ok(__PACKAGE__->add_property('hash', {})); + + + # Catch an exception adding an existing property. + eval { __PACKAGE__->add_property('module_name')}; + like "$@", qr/already exists/; +} + +{ + package MBSub2; + use Test::More; + use vars qw($VERSION @ISA); + @ISA = qw(Module::Build); + $VERSION = 0.01; + + # Add a new property with a different default value than MBSub has. + ok(__PACKAGE__->add_property('bar', 'yow')); +} + + +{ + ok my $mb = MBSub->new( module_name => $dist->name ); + isa_ok $mb, 'Module::Build'; + isa_ok $mb, 'MBSub'; + ok $mb->valid_property('foo'); + can_ok $mb, 'module_name'; + + # Check foo property. + can_ok $mb, 'foo'; + ok ! $mb->foo; + ok $mb->foo(1); + ok $mb->foo; + + # Check bar property. + can_ok $mb, 'bar'; + is $mb->bar, 'hey'; + ok $mb->bar('you'); + is $mb->bar, 'you'; + + # Check hash property. + ok $mb = MBSub->new( + module_name => $dist->name, + hash => { foo => 'bar', bin => 'foo'} + ); + + can_ok $mb, 'hash'; + isa_ok $mb->hash, 'HASH'; + is $mb->hash->{foo}, 'bar'; + is $mb->hash->{bin}, 'foo'; + + # Check hash property passed via the command-line. + { + local @ARGV = ( + '--hash', 'foo=bar', + '--hash', 'bin=foo', + ); + ok $mb = MBSub->new( module_name => $dist->name ); + } + + can_ok $mb, 'hash'; + isa_ok $mb->hash, 'HASH'; + is $mb->hash->{foo}, 'bar'; + is $mb->hash->{bin}, 'foo'; + + # Make sure that a different subclass with the same named property has a + # different default. + ok $mb = MBSub2->new( module_name => $dist->name ); + isa_ok $mb, 'Module::Build'; + isa_ok $mb, 'MBSub2'; + ok $mb->valid_property('bar'); + can_ok $mb, 'bar'; + is $mb->bar, 'yow'; +} + +{ + # Test the meta_add and meta_merge stuff + ok my $mb = Module::Build->new( + module_name => $dist->name, + license => 'perl', + meta_add => {keywords => ['bar']}, + conflicts => {'Foo::Barxx' => 0}, + ); + my $data = $mb->get_metadata; + is_deeply $data->{keywords}, ['bar']; + + $mb->meta_merge(keywords => ['baz']); + $data = $mb->get_metadata; + is_deeply $data->{keywords}, [qw/bar baz/]; + + $mb->meta_merge( + 'meta-spec' => { version => 2 }, + prereqs => { + test => { + requires => { + 'Foo::Fooxx' => 0, + } + } + } + ); + $data = $mb->get_metadata; + is_deeply $data->{prereqs}{test}{requires}, { 'Foo::Fooxx' => 0 } or diag explain $mb->meta_merge; + +} + +{ + # Test interactive prompting + + my $ans; + local $ENV{PERL_MM_USE_DEFAULT}; + + local $^W = 0; + local *{Module::Build::_readline} = sub { 'y' }; + + ok my $mb = Module::Build->new( + module_name => $dist->name, + license => 'perl', + ); + + eval{ $mb->prompt() }; + like $@, qr/called without a prompt/, 'prompt() requires a prompt'; + + eval{ $mb->y_n() }; + like $@, qr/called without a prompt/, 'y_n() requires a prompt'; + + eval{ $mb->y_n('Prompt?', 'invalid default') }; + like $@, qr/Invalid default/, "y_n() requires a default of 'y' or 'n'"; + + + $ENV{PERL_MM_USE_DEFAULT} = 1; + + eval{ $mb->y_n('Is this a question?') }; + print "\n"; # fake <enter> because the prompt prints before the checks + like $@, qr/ERROR:/, + 'Do not allow default-less y_n() for unattended builds'; + + eval{ $ans = $mb->prompt('Is this a question?') }; + print "\n"; # fake <enter> because the prompt prints before the checks + like $@, qr/ERROR:/, + 'Do not allow default-less prompt() for unattended builds'; + + + # When running Test::Smoke under a cron job, STDIN will be closed which + # will fool our _is_interactive() method causing various failures. + { + local *{Module::Build::_is_interactive} = sub { 1 }; + + $ENV{PERL_MM_USE_DEFAULT} = 0; + + $ans = $mb->prompt('Is this a question?'); + print "\n"; # fake <enter> after input + is $ans, 'y', "prompt() doesn't require default for interactive builds"; + + $ans = $mb->y_n('Say yes'); + print "\n"; # fake <enter> after input + ok $ans, "y_n() doesn't require default for interactive build"; + + + # Test Defaults + *{Module::Build::_readline} = sub { '' }; + + $ans = $mb->prompt("Is this a question"); + is $ans, '', "default for prompt() without a default is ''"; + + $ans = $mb->prompt("Is this a question", 'y'); + is $ans, 'y', " prompt() with a default"; + + $ans = $mb->y_n("Is this a question", 'y'); + ok $ans, " y_n() with a default"; + + my @ans = $mb->prompt("Is this a question", undef); + is_deeply([@ans], [undef], " prompt() with undef() default"); + } + +} + diff --git a/t/files.t b/t/files.t new file mode 100644 index 0000000..e951b80 --- /dev/null +++ b/t/files.t @@ -0,0 +1,46 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 4; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + +my $mb = Module::Build->new_from_context; + +{ + # Make sure copy_if_modified() can handle spaces in filenames + + my @tmp; + push @tmp, MBTest->tmpdir for (0 .. 1); + + my $filename = 'file with spaces.txt'; + + my $file = File::Spec->catfile($tmp[0], $filename); + open(my $fh, '>', $file) or die "Can't create $file: $!"; + print $fh "Foo\n"; + close $fh; + ok -e $file; + + + my $file2 = $mb->copy_if_modified(from => $file, to_dir => $tmp[1]); + ok $file2; + ok -e $file2; +} + +{ + # Try some dir_contains() combinations + my $first = File::Spec->catdir('', 'one', 'two'); + my $second = File::Spec->catdir('', 'one', 'two', 'three'); + + ok( Module::Build->dir_contains($first, $second) ); +} + diff --git a/t/help.t b/t/help.t new file mode 100644 index 0000000..0534c92 --- /dev/null +++ b/t/help.t @@ -0,0 +1,263 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 23; + +blib_load('Module::Build'); + +use DistGen; + +my $dist = DistGen->new; +$dist->regen; +$dist->chdir_in; + +my $restart = sub { + # we're redefining the same package as we go, so... + delete($::{'MyModuleBuilder::'}); + delete($INC{'MyModuleBuilder.pm'}); + $dist->regen( clean => 1 ); +}; + +######################################################################## +{ # check the =item style +my $mb = Module::Build->subclass( + code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---', + =head1 ACTIONS + + =over + + =item foo + + Does the foo thing. + + =item bar + + Does the bar thing. + + =item help + + Does the help thing. + + You should probably not be seeing this. That is, we haven't + overridden the help action, but we're able to override just the + docs? That almost seems reasonable, but is probably wrong. + + =back + + =cut + + sub ACTION_foo { die "fooey" } + sub ACTION_bar { die "barey" } + sub ACTION_baz { die "bazey" } + + # guess we can have extra pod later + + =over + + =item baz + + Does the baz thing. + + =back + + =cut + + --- + )->new( + module_name => $dist->name, + ); + +ok $mb; +can_ok($mb, 'ACTION_foo'); + +foreach my $action (qw(foo bar baz)) { # typical usage + my $doc = $mb->get_action_docs($action); + ok($doc, "got doc for '$action'"); + like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s, + 'got the right doc'); +} + +{ # user typo'd the action name + ok( ! eval {$mb->get_action_docs('batz'); 1}, 'slap'); + like($@, qr/No known action 'batz'/, 'informative error'); +} + +{ # XXX this one needs some thought + my $action = 'help'; + my $doc = $mb->get_action_docs($action); + ok($doc, "got doc for '$action'"); + 0 and warn "help doc >\n$doc<\n"; + TODO: { + local $TODO = 'Do we allow overrides on just docs?'; + unlike($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s, + 'got the right doc'); + } +} +} # end =item style +$restart->(); +######################################################################## +if(0) { # the =item style without spanning =head1 sections +my $mb = Module::Build->subclass( + code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---', + =head1 ACTIONS + + =over + + =item foo + + Does the foo thing. + + =item bar + + Does the bar thing. + + =back + + =head1 thbbt + + =over + + =item baz + + Should not see this. + + =back + + =cut + + sub ACTION_foo { die "fooey" } + sub ACTION_bar { die "barey" } + sub ACTION_baz { die "bazey" } + + --- + )->new( + module_name => $dist->name, + ); + +ok $mb; +can_ok($mb, 'ACTION_foo'); + +foreach my $action (qw(foo bar)) { # typical usage + my $doc = $mb->get_action_docs($action); + ok($doc, "got doc for '$action'"); + like($doc, qr/^=\w+ $action\n\nDoes the $action thing\./s, + 'got the right doc'); +} +is($mb->get_action_docs('baz'), undef, 'no jumping =head1 sections'); + +} # end =item style without spanning =head1's +$restart->(); +######################################################################## +TODO: { # the =item style with 'Actions' not 'ACTIONS' +local $TODO = 'Support capitalized Actions section'; +my $mb = Module::Build->subclass( + code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---', + =head1 Actions + + =over + + =item foo + + Does the foo thing. + + =item bar + + Does the bar thing. + + =back + + =cut + + sub ACTION_foo { die "fooey" } + sub ACTION_bar { die "barey" } + + --- + )->new( + module_name => $dist->name, + ); + +foreach my $action (qw(foo bar)) { # typical usage + my $doc = $mb->get_action_docs($action); + ok($doc, "got doc for '$action'"); + like($doc || 'undef', qr/^=\w+ $action\n\nDoes the $action thing\./s, + 'got the right doc'); +} + +} # end =item style with Actions +$restart->(); +######################################################################## +{ # check the =head2 style +my $mb = Module::Build->subclass( + code => join "\n", map {s/^ {4}//; $_} split /\n/, <<' ---', + =head1 ACTIONS + + =head2 foo + + Does the foo thing. + + =head2 bar + + Does the bar thing. + + =head3 bears + + Be careful with bears. + + =cut + + sub ACTION_foo { die "fooey" } + sub ACTION_bar { die "barey" } + sub ACTION_baz { die "bazey" } + sub ACTION_batz { die "batzey" } + + # guess we can have extra pod later + # Though, I do wonder whether we should allow them to mix... + # maybe everything should have to be head2? + + =head2 baz + + Does the baz thing. + + =head4 What's a baz? + + =head1 not this part + + This is level 1, so the stuff about baz is done. + + =head1 Thing + + =head2 batz + + This is not an action doc. + + =cut + + --- + )->new( + module_name => $dist->name, + ); + +my %also = ( + foo => '', + bar => "\n=head3 bears\n\nBe careful with bears.\n", + baz => "\n=head4 What's a baz\\?\n", +); + +foreach my $action (qw(foo bar baz)) { + my $doc = $mb->get_action_docs($action); + ok($doc, "got doc for '$action'"); + my $and = $also{$action}; + like($doc || 'undef', + qr/^=\w+ $action\n\nDoes the $action thing\.\n$and\n$/s, + 'got the right doc'); +} +is($mb->get_action_docs('batz'), undef, 'nothing after uplevel'); + +} # end =head2 style +######################################################################## + +# cleanup +$dist->clean(); + +# vim:ts=2:sw=2:et:sta diff --git a/t/install.t b/t/install.t new file mode 100644 index 0000000..fde3958 --- /dev/null +++ b/t/install.t @@ -0,0 +1,230 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 34; + +blib_load('Module::Build'); + +use Config; +use Cwd (); +my $cwd = Cwd::cwd; +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; +$dist->chdir_in; + +######################### + + +$dist->add_file( 'script', <<'---' ); +#!perl -w +print "Hello, World!\n"; +--- +$dist->change_build_pl +({ + module_name => $dist->name, + scripts => [ 'script' ], + license => 'perl', + requires => { 'File::Spec' => 0 }, +}); +$dist->regen; + + +use File::Spec::Functions qw( catdir ); + +my $mb = Module::Build->new_from_context( + # Need default install paths to ensure manpages get generated. + installdirs => 'site', + config => { + installman1dir => catdir($tmp, 'man', 'man1'), + installman3dir => catdir($tmp, 'man', 'man3'), + installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'), + installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'), + ## We also used to have HTML paths here, but building HTML docs + ## can be super slow, and we never checked the result anyway. + } + +); + +ok $mb; + + +my $destdir = File::Spec->catdir($cwd, 't', 'install_test' . $$); +$mb->add_to_cleanup($destdir); + +{ + eval {$mb->dispatch('install', destdir => $destdir)}; + is $@, ''; + + my @libdir = strip_volume( $mb->install_destination('lib') ); + my $install_to = File::Spec->catfile($destdir, @libdir, $dist->name ) . '.pm'; + file_exists($install_to); + + local @INC = (@INC, File::Spec->catdir($destdir, @libdir)); + eval "require @{[$dist->name]}"; + is $@, ''; + + # Make sure there's a packlist installed + my $archdir = $mb->install_destination('arch'); + my @dirs = strip_volume($archdir); + my $packlist = File::Spec->catfile + ($destdir, @dirs, 'auto', $dist->name, '.packlist'); + is -e $packlist, 1, "$packlist should be written"; +} + +{ + eval {$mb->dispatch('install', installdirs => 'core', destdir => $destdir)}; + is $@, ''; + my @libdir = strip_volume( $Config{installprivlib} ); + my $install_to = File::Spec->catfile($destdir, @libdir, $dist->name ) . '.pm'; + file_exists($install_to); +} + +{ + my $libdir = File::Spec->catdir(File::Spec->rootdir, 'foo', 'bar'); + eval {$mb->dispatch('install', install_path => {lib => $libdir}, destdir => $destdir)}; + is $@, ''; + my @dirs = strip_volume($libdir); + my $install_to = File::Spec->catfile($destdir, @dirs, $dist->name ) . '.pm'; + file_exists($install_to); +} + +{ + my $libdir = File::Spec->catdir(File::Spec->rootdir, 'foo', 'base'); + eval {$mb->dispatch('install', install_base => $libdir, destdir => $destdir)}; + is $@, ''; + my @dirs = strip_volume($libdir); + my $install_to = File::Spec->catfile($destdir, @dirs, 'lib', 'perl5', $dist->name ) . '.pm'; + file_exists($install_to); +} + +{ + # Test the ConfigData stuff + + $mb->config_data(foo => 'bar'); + $mb->features(baz => 1); + $mb->auto_features(auto_foo => {requires => {'File::Spec' => 0}}); + eval {$mb->dispatch('install', destdir => $destdir)}; + is $@, ''; + + my @libdir = strip_volume( $mb->install_destination('lib') ); + local @INC = (@INC, File::Spec->catdir($destdir, @libdir)); + eval "require @{[$dist->name]}::ConfigData"; + + is $mb->feature('auto_foo'), 1; + + SKIP: { + skip $@, 5 if @_; + + # Make sure the values are present + my $config = $dist->name . '::ConfigData'; + is( $config->config('foo'), 'bar' ); + ok( $config->feature('baz') ); + ok( $config->feature('auto_foo') ); + ok( not $config->feature('nonexistent') ); + + # Add a new value to the config set + $config->set_config(floo => 'bhlar'); + is( $config->config('floo'), 'bhlar' ); + + # Make sure it actually got written + $config->write; + delete $INC{"@{[$dist->name]}/ConfigData.pm"}; + { + local $^W; # Avoid warnings for subroutine redefinitions + eval "require $config"; + } + is( $config->config('floo'), 'bhlar' ); + } +} + + +eval {$mb->dispatch('realclean')}; +is $@, ''; + +{ + # Try again by running the script rather than with programmatic interface + my $libdir = File::Spec->catdir('', 'foo', 'lib'); + eval {$mb->run_perl_script('Build.PL', [], ['--install_path', "lib=$libdir"])}; + is $@, ''; + + my $cmd = 'Build'; + $cmd .= ".COM" if $^O eq 'VMS'; + eval {$mb->run_perl_script($cmd, [], ['install', '--destdir', $destdir])}; + is $@, ''; + my $install_to = File::Spec->catfile($destdir, $libdir, $dist->name ) . '.pm'; + file_exists($install_to); + + my $basedir = File::Spec->catdir('', 'bar'); + eval {$mb->run_perl_script($cmd, [], ['install', '--destdir', $destdir, + '--install_base', $basedir])}; + is $@, ''; + + $install_to = File::Spec->catfile($destdir, $libdir, $dist->name ) . '.pm'; + is -e $install_to, 1, "Look for file at $install_to"; + + eval {$mb->dispatch('realclean')}; + is $@, ''; +} + +{ + # Make sure 'install_path' overrides 'install_base' + my $mb = Module::Build->new( module_name => $dist->name, + install_base => File::Spec->catdir('', 'foo'), + install_path => { + lib => File::Spec->catdir('', 'bar') + } + ); + ok $mb; + is $mb->install_destination('lib'), File::Spec->catdir('', 'bar'); +} + +{ + $dist->add_file( 'lib/Simple/Docs.pod', <<'---' ); +=head1 NAME + +Simple::Docs - Simple pod + +=head1 AUTHOR + +Simple Man <simple@example.com> + +=cut +--- + $dist->regen; + + # _find_file_by_type() isn't a public method, but this is currently + # the only easy way to test that it works properly. + my $pods = $mb->_find_file_by_type('pod', 'lib'); + is keys %$pods, 1; + my $expect = $mb->localize_file_path('lib/Simple/Docs.pod'); + + is $pods->{$expect}, $expect; + + my $pms = $mb->_find_file_by_type('awefawef', 'lib'); + ok $pms; + is keys %$pms, 0; + + $pms = $mb->_find_file_by_type('pod', 'awefawef'); + ok $pms; + is keys %$pms, 0; + + # revert to pristine state + $dist->regen( clean => 1 ); +} + +sub strip_volume { + my $dir = shift; + (undef, $dir) = File::Spec->splitpath( $dir, 1 ); + my @dirs = File::Spec->splitdir($dir); + return @dirs; +} + +sub file_exists { + my $file = shift; + ok -e $file or diag("Expected $file to exist, but it doesn't"); +} + diff --git a/t/install_extra_target.t b/t/install_extra_target.t new file mode 100644 index 0000000..09d2cbe --- /dev/null +++ b/t/install_extra_target.t @@ -0,0 +1,135 @@ +#!perl -w +# Contributed by: Thorben Jaendling + +use strict; +use lib 't/lib'; +use MBTest tests => 6; + +blib_load('Module::Build'); + +use File::Spec::Functions qw( catdir catfile ); + +my $tmp = MBTest->tmpdir; +my $output; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); + +# note("Dist is in $tmp\n"); + +$dist->add_file("Build.PL", <<'===EOF==='); +#!perl -w + +use strict; +use Module::Build; + +my $subclass = Module::Build->subclass(code => <<'=EOF='); +sub copy_files +{ + my $self = shift; + my $dir = shift; + + my $files = $self->rscan_dir($dir, sub {-f $_ and not m!/\.|[#~]$!}); + + foreach my $file (@$files) { + $self->copy_if_modified(from => $file, to_dir => "blib"); + } +} + +#Copy etc files to blib +sub process_etc_files +{ + my $self = shift; + + $self->copy_files("etc"); +} + +#Copy share files to blib +sub process_shared_files +{ + my $self = shift; + + $self->copy_files("shared"); +} + +1; +=EOF= + +my $build = $subclass->new( + module_name => 'Simple', + license => 'perl' +); + +$build->add_build_element('etc'); +$build->add_build_element('shared'); + +my $distdir = lc $build->dist_name(); + +foreach my $id ('core', 'site', 'vendor') { + #Where to install these build types when using prefix symantics + $build->prefix_relpaths($id, 'shared' => "shared/$distdir"); + $build->prefix_relpaths($id, 'etc' => "etc/$distdir"); + + #Where to install these build types when using default symantics + my $set = $build->install_sets($id); + $set->{'shared'} = '/usr/'.($id eq 'site' ? 'local/':'')."shared/$distdir"; + $set->{'etc'} = ($id eq 'site' ? '/usr/local/etc/':'/etc/').$distdir; +} + +#Where to install these types when using install_base symantics +$build->install_base_relpaths('shared' => "shared/$distdir"); +$build->install_base_relpaths('etc' => "etc/$distdir"); + +$build->create_build_script(); + +===EOF=== + +#Test Build.PL exists ok? + +$dist->add_file("etc/config", <<'===EOF==='); +[main] +Foo = bar +Jim = bob + +[supplemental] +stardate = 1234344 + +===EOF=== + +$dist->add_file("shared/data", <<'===EOF==='); +7 * 9 = 42? + +===EOF=== + +$dist->add_file("shared/html/index.html", <<'===EOF==='); +<HTML> + <BODY> + <H1>Hello World!</H1> + </BODY> +</HTML> + +===EOF=== + +$dist->regen; +$dist->chdir_in; + +my $installdest = catdir($tmp, 't', "install_extra_targets-$$"); + +$output = stdout_of sub { $dist->run_build_pl("--install_base=$installdest") }; + +$output .= stdout_of sub { $dist->run_build }; + +my $error; +$error++ unless ok(-e "blib/etc/config", "Built etc/config"); +$error++ unless ok(-e "blib/shared/data", "Built shared/data"); +$error++ unless ok(-e "blib/shared/html/index.html", "Built shared/html"); +diag "OUTPUT:\n$output" if $error; + +$output = stdout_of sub { $dist->run_build('install') }; + +$error = 0; +$error++ unless ok(-e catfile($installdest, qw/etc simple config/), "installed etc/config"); +$error++ unless ok(-e catfile($installdest, qw/shared simple data/), "installed shared/data"); +$error++ unless ok(-e catfile($installdest, qw/shared simple html index.html/), "installed shared/html"); +diag "OUTPUT:\n$output" if $error; + diff --git a/t/lib/DistGen.pm b/t/lib/DistGen.pm new file mode 100644 index 0000000..5249372 --- /dev/null +++ b/t/lib/DistGen.pm @@ -0,0 +1,859 @@ +package DistGen; + +use strict; + +use vars qw( $VERSION $VERBOSE @EXPORT_OK); + +$VERSION = '0.01'; +$VERBOSE = 0; + +use Carp; + +use MBTest (); +use Cwd (); +use File::Basename (); +use File::Find (); +use File::Path (); +use File::Spec (); +use Tie::CPHash; +use Data::Dumper; + +my $vms_mode; +my $vms_lower_case; + +BEGIN { + $vms_mode = 0; + $vms_lower_case = 0; + if( $^O eq 'VMS' ) { + # For things like vmsify() + require VMS::Filespec; + VMS::Filespec->import; + $vms_mode = 1; + $vms_lower_case = 1; + my $vms_efs_case = 0; + my $unix_rpt = 0; + if (eval { local $SIG{__DIE__}; require VMS::Feature; }) { + $unix_rpt = VMS::Feature::current("filename_unix_report"); + $vms_efs_case = VMS::Feature::current("efs_case_preserve"); + } else { + my $env_unix_rpt = $ENV{'DECC$FILENAME_UNIX_REPORT'} || ''; + $unix_rpt = $env_unix_rpt =~ /^[ET1]/i; + my $efs_case = $ENV{'DECC$EFS_CASE_PRESERVE'} || ''; + $vms_efs_case = $efs_case =~ /^[ET1]/i; + } + $vms_mode = 0 if $unix_rpt; + $vms_lower_case = 0 if $vms_efs_case; + } +} +BEGIN { + require Exporter; + *{import} = \&Exporter::import; + @EXPORT_OK = qw( + undent + ); +} + +sub undent { + my ($string) = @_; + + my ($space) = $string =~ m/^(\s+)/; + $string =~ s/^$space//gm; + + return($string); +} + +sub chdir_all ($) { + # OS/2 has "current directory per disk", undeletable; + # doing chdir() to another disk won't change cur-dir of initial disk... + chdir('/') if $^O eq 'os2'; + chdir shift; +} + +######################################################################## + +END { chdir_all(MBTest->original_cwd); } + +sub new { + my $self = bless {}, shift; + $self->reset(@_); +} + +sub reset { + my $self = shift; + my %options = @_; + + $options{name} ||= 'Simple'; + $options{version} ||= q{'0.01'}; + $options{license} ||= 'perl'; + $options{dir} = File::Spec->rel2abs( + defined $options{dir} ? $options{dir} : MBTest->tmpdir + ); + + my %data = ( + no_manifest => 0, + xs => 0, + inc => 0, + %options, + ); + %$self = %data; + + tie %{$self->{filedata}}, 'Tie::CPHash'; + + tie %{$self->{pending}{change}}, 'Tie::CPHash'; + + # start with a fresh, empty directory + if ( -d $self->dirname ) { + warn "Warning: Removing existing directory '@{[$self->dirname]}'\n"; + File::Path::rmtree( $self->dirname ); + } + File::Path::mkpath( $self->dirname ); + + $self->_gen_default_filedata(); + + return $self; +} + +sub remove { + my $self = shift; + $self->chdir_original if($self->did_chdir); + File::Path::rmtree( $self->dirname ); + return $self; +} + +sub revert { + my ($self, $file) = @_; + if ( defined $file ) { + delete $self->{filedata}{$file}; + delete $self->{pending}{$_}{$file} for qw/change remove/; + } + else { + delete $self->{filedata}{$_} for keys %{ $self->{filedata} }; + for my $pend ( qw/change remove/ ) { + delete $self->{pending}{$pend}{$_} for keys %{ $self->{pending}{$pend} }; + } + } + $self->_gen_default_filedata; +} + +sub _gen_default_filedata { + my $self = shift; + + # TODO maybe a public method like this (but with a better name?) + my $add_unless = sub { + my $self = shift; + my ($member, $data) = @_; + $self->add_file($member, $data) unless($self->{filedata}{$member}); + }; + + if ( ! $self->{inc} ) { + $self->$add_unless('Build.PL', undent(<<" ---")); + use strict; + use Module::Build; + + my \$builder = Module::Build->new( + module_name => '$self->{name}', + license => '$self->{license}', + ); + + \$builder->create_build_script(); + --- + } + else { + $self->$add_unless('Build.PL', undent(<<" ---")); + use strict; + use inc::latest 'Module::Build'; + + my \$builder = Module::Build->new( + module_name => '$self->{name}', + license => '$self->{license}', + ); + + \$builder->create_build_script(); + --- + } + + my $module_filename = + join( '/', ('lib', split(/::/, $self->{name})) ) . '.pm'; + + unless ( $self->{xs} ) { + $self->$add_unless($module_filename, undent(<<" ---")); + package $self->{name}; + + use vars qw( \$VERSION ); + \$VERSION = $self->{version}; + + use strict; + + 1; + + __END__ + + =head1 NAME + + $self->{name} - Perl extension for blah blah blah + + =head1 DESCRIPTION + + Stub documentation for $self->{name}. + + =head1 AUTHOR + + A. U. Thor, a.u.thor\@a.galaxy.far.far.away + + =cut + --- + + $self->$add_unless('t/basic.t', undent(<<" ---")); + use Test::More tests => 1; + use strict; + + use $self->{name}; + ok 1; + --- + + } else { + $self->$add_unless($module_filename, undent(<<" ---")); + package $self->{name}; + + \$VERSION = $self->{version}; + + require Exporter; + require DynaLoader; + + \@ISA = qw(Exporter DynaLoader); + \@EXPORT_OK = qw( okay ); + + bootstrap $self->{name} \$VERSION; + + 1; + + __END__ + + =head1 NAME + + $self->{name} - Perl extension for blah blah blah + + =head1 DESCRIPTION + + Stub documentation for $self->{name}. + + =head1 AUTHOR + + A. U. Thor, a.u.thor\@a.galaxy.far.far.away + + =cut + --- + + my $xs_filename = + join( '/', ('lib', split(/::/, $self->{name})) ) . '.xs'; + $self->$add_unless($xs_filename, undent(<<" ---")); + #include "EXTERN.h" + #include "perl.h" + #include "XSUB.h" + + MODULE = $self->{name} PACKAGE = $self->{name} + + SV * + okay() + CODE: + RETVAL = newSVpv( "ok", 0 ); + OUTPUT: + RETVAL + + const char * + xs_version() + CODE: + RETVAL = XS_VERSION; + OUTPUT: + RETVAL + + const char * + version() + CODE: + RETVAL = VERSION; + OUTPUT: + RETVAL + --- + + # 5.6 is missing const char * in its typemap + $self->$add_unless('typemap', undent(<<" ---")); + const char *\tT_PV + --- + + $self->$add_unless('t/basic.t', undent(<<" ---")); + use Test::More tests => 2; + use strict; + + use $self->{name}; + ok 1; + + ok( $self->{name}::okay() eq 'ok' ); + --- + } +} + +sub _gen_manifest { + my $self = shift; + my $manifest = shift; + + open(my $fh, '>', $manifest ) or do { + die "Can't write '$manifest'\n"; + }; + + my @files = ( 'MANIFEST', keys %{$self->{filedata}} ); + my $data = join( "\n", sort @files ) . "\n"; + print $fh $data; + close( $fh ); + + $self->{filedata}{MANIFEST} = $data; + $self->{pending}{change}{MANIFEST} = 1; +} + +sub name { shift()->{name} } + +sub dirname { + my $self = shift; + my $dist = $self->{distdir} || join( '-', split( /::/, $self->{name} ) ); + return File::Spec->catdir( $self->{dir}, $dist ); +} + +sub _real_filename { + my $self = shift; + my $filename = shift; + return File::Spec->catfile( split( /\//, $filename ) ); +} + +sub regen { + my $self = shift; + my %opts = @_; + + my $dist_dirname = $self->dirname; + + if ( $opts{clean} ) { + $self->clean() if -d $dist_dirname; + } else { + # TODO: This might leave dangling directories; e.g. if the removed file + # is 'lib/Simple/Simon.pm', the directory 'lib/Simple' will be left + # even if there are no files left in it. However, clean() will remove it. + my @files = keys %{$self->{pending}{remove}}; + foreach my $file ( @files ) { + my $real_filename = $self->_real_filename( $file ); + my $fullname = File::Spec->catfile( $dist_dirname, $real_filename ); + if ( -e $fullname ) { + 1 while unlink( $fullname ); + } + print "Unlinking pending file '$file'\n" if $VERBOSE; + delete( $self->{pending}{remove}{$file} ); + } + } + + foreach my $file ( keys( %{$self->{filedata}} ) ) { + my $real_filename = $self->_real_filename( $file ); + my $fullname = File::Spec->catfile( $dist_dirname, $real_filename ); + + if ( ! -e $fullname || + ( -e $fullname && $self->{pending}{change}{$file} ) ) { + + print "Changed file '$file'.\n" if $VERBOSE; + + my $dirname = File::Basename::dirname( $fullname ); + unless ( -d $dirname ) { + File::Path::mkpath( $dirname ) or do { + die "Can't create '$dirname'\n"; + }; + } + + if ( -e $fullname ) { + 1 while unlink( $fullname ); + } + + open(my $fh, '>', $fullname) or do { + die "Can't write '$fullname'\n"; + }; + print $fh $self->{filedata}{$file}; + close( $fh ); + } + + delete( $self->{pending}{change}{$file} ); + } + + my $manifest = File::Spec->catfile( $dist_dirname, 'MANIFEST' ); + unless ( $self->{no_manifest} ) { + if ( -e $manifest ) { + 1 while unlink( $manifest ); + } + $self->_gen_manifest( $manifest ); + } + return $self; +} + +sub clean { + my $self = shift; + + my $here = Cwd::abs_path(); + my $there = File::Spec->rel2abs( $self->dirname() ); + + if ( -d $there ) { + chdir( $there ) or die "Can't change directory to '$there'\n"; + } else { + die "Distribution not found in '$there'\n"; + } + + my %names; + tie %names, 'Tie::CPHash'; + foreach my $file ( keys %{$self->{filedata}} ) { + my $filename = $self->_real_filename( $file ); + $filename = lc($filename) if $vms_lower_case; + my $dirname = File::Basename::dirname( $filename ); + + $names{$filename} = 0; + + print "Splitting '$dirname'\n" if $VERBOSE; + my @dirs = File::Spec->splitdir( $dirname ); + while ( @dirs ) { + my $dir = ( scalar(@dirs) == 1 + ? $dirname + : File::Spec->catdir( @dirs ) ); + if (length $dir) { + print "Setting directory name '$dir' in \%names\n" if $VERBOSE; + $names{$dir} = 0; + } + pop( @dirs ); + } + } + + File::Find::finddepth( sub { + my $name = File::Spec->canonpath( $File::Find::name ); + + if ($vms_mode) { + if ($name ne '.') { + $name =~ s/\.\z//; + $name = vmspath($name) if -d $name; + } + } + if ($^O eq 'VMS') { + $name = File::Spec->rel2abs($name) if $name eq File::Spec->curdir(); + } + + if ( not exists $names{$name} ) { + print "Removing '$name'\n" if $VERBOSE; + File::Path::rmtree( $_ ); + } + }, ($^O eq 'VMS' ? './' : File::Spec->curdir) ); + + chdir_all( $here ); + return $self; +} + +sub add_file { + my $self = shift; + $self->change_file( @_ ); +} + +sub remove_file { + my $self = shift; + my $file = shift; + unless ( exists $self->{filedata}{$file} ) { + warn "Can't remove '$file': It does not exist.\n" if $VERBOSE; + } + delete( $self->{filedata}{$file} ); + $self->{pending}{remove}{$file} = 1; + return $self; +} + +sub change_build_pl { + my ($self, @opts) = @_; + + my $opts = ref $opts[0] eq 'HASH' ? $opts[0] : { @opts }; + + local $Data::Dumper::Terse = 1; + (my $args = Dumper($opts)) =~ s/^\s*\{|\}\s*$//g; + + $self->change_file( 'Build.PL', undent(<<" ---") ); + use strict; + use Module::Build; + my \$b = Module::Build->new( + # Some CPANPLUS::Dist::Build versions need to allow mismatches + # On logic: thanks to Module::Install, CPAN.pm must set both keys, but + # CPANPLUS sets only the one + allow_mb_mismatch => ( + \$ENV{PERL5_CPANPLUS_IS_RUNNING} && ! \$ENV{PERL5_CPAN_IS_RUNNING} ? 1 : 0 + ), + $args + ); + \$b->create_build_script(); + --- + return $self; +} + +sub change_file { + my $self = shift; + my $file = shift; + my $data = shift; + $self->{filedata}{$file} = $data; + $self->{pending}{change}{$file} = 1; + return $self; +} + +sub get_file { + my $self = shift; + my $file = shift; + exists($self->{filedata}{$file}) or croak("no such entry: '$file'"); + return $self->{filedata}{$file}; +} + +sub chdir_in { + my $self = shift; + $self->{original_dir} ||= Cwd::cwd; # only once! + my $dir = $self->dirname; + chdir($dir) or die "Can't chdir to '$dir': $!"; + return $self; +} +######################################################################## + +sub did_chdir { exists shift()->{original_dir} } + +######################################################################## + +sub chdir_original { + my $self = shift; + + my $dir = delete $self->{original_dir}; + chdir_all($dir) or die "Can't chdir to '$dir': $!"; + return $self; +} +######################################################################## + +sub new_from_context { + my ($self, @args) = @_; + require Module::Build; + return Module::Build->new_from_context( quiet => 1, @args ); +} + +sub run_build_pl { + my ($self, @args) = @_; + require Module::Build; + return Module::Build->run_perl_script('Build.PL', [], [@args]) +} + +sub run_build { + my ($self, @args) = @_; + require Module::Build; + my $build_script = $^O eq 'VMS' ? 'Build.com' : 'Build'; + return Module::Build->run_perl_script($build_script, [], [@args]) +} + +1; + +__END__ + + +=head1 NAME + +DistGen - Creates simple distributions for testing. + +=head1 SYNOPSIS + + use DistGen; + + # create distribution and prepare to test + my $dist = DistGen->new(name => 'Foo::Bar'); + $dist->chdir_in; + + # change distribution files + $dist->add_file('t/some_test.t', $contents); + $dist->change_file('MANIFEST.SKIP', $new_contents); + $dist->remove_file('t/some_test.t'); + $dist->regen; + + # undo changes and clean up extraneous files + $dist->revert; + $dist->clean; + + # exercise the command-line interface + $dist->run_build_pl(); + $dist->run_build('test'); + + # start over as a new distribution + $dist->reset( name => 'Foo::Bar', xs => 1 ); + $dist->chdir_in; + +=head1 USAGE + +A DistGen object manages a set of files in a distribution directory. + +The C<new()> constructor initializes the object and creates an empty +directory for the distribution. It does not create files or chdir into +the directory. The C<reset()> method re-initializes the object in a +new directory with new parameters. It also does not create files or change +the current directory. + +Some methods only define the target state of the distribution. They do B<not> +make any changes to the filesystem: + + add_file + change_file + change_build_pl + remove_file + revert + +Other methods then change the filesystem to match the target state of +the distribution: + + clean + regen + remove + +Other methods are provided for a convenience during testing. The +most important is the one to enter the distribution directory: + + chdir_in + +Additional methods portably encapsulate running Build.PL and Build: + + run_build_pl + run_build + +=head1 API + +=head2 Constructors + +=head3 new() + +Create a new object and an empty directory to hold the distribution's files. +If no C<dir> option is provided, it defaults to MBTest->tmpdir, which sets +a different temp directory for Perl core testing and CPAN testing. + +The C<new> method does not write any files -- see L</regen()> below. + + my $dist = DistGen->new( + name => 'Foo::Bar', + version => '0.01', + license => 'perl', + dir => MBTest->tmpdir, + xs => 1, + no_manifest => 0, + ); + +The parameters are as follows. + +=over + +=item name + +The name of the module this distribution represents. The default is +'Simple'. This should be a "Foo::Bar" (module) name, not a "Foo-Bar" +dist name. + +=item version + +The version string that will be set. (E.g. C<our $VERSION = 0.01>) +Note -- to put this value in quotes, add those to the string. + + version => q{'0.01_01'} + +=item license + +The license string that will be set in Build.PL. Defaults to 'perl'. + +=item dir + +The (parent) directory in which to create the distribution directory. The +distribution will be created under this according to C<distdir> parameter +below. Defaults to a temporary directory. + + $dist = DistGen->new( dir => '/tmp/MB-test' ); + $dist->regen; + + # distribution files have been created in /tmp/MB-test/Simple + +=item distdir + +The name of the distribution directory to create. Defaults to the dist form of +C<name>, e.g. 'Foo-Bar' if C<name> is 'Foo::Bar'. + +=item xs + +If true, generates an XS based module. + +=item no_manifest + +If true, C<regen()> will not create a MANIFEST file. + +=back + +The following files are added as part of the default distribution: + + Build.PL + lib/Simple.pm # based on name parameter + t/basic.t + +If an XS module is generated, Simple.pm and basic.t are different and +the following files are also added: + + typemap + lib/Simple.xs # based on name parameter + +=head3 reset() + +The C<reset> method re-initializes the object as if it were generated +from a fresh call to C<new>. It takes the same optional parameters as C<new>. + + $dist->reset( name => 'Foo::Bar', xs => 0 ); + +=head2 Adding and editing files + +Note that C<$filename> should always be specified with unix-style paths, +and are relative to the distribution root directory, e.g. C<lib/Module.pm>. + +No changes are made to the filesystem until the distribution is regenerated. + +=head3 add_file() + +Add a $filename containing $content to the distribution. + + $dist->add_file( $filename, $content ); + +=head3 change_file() + +Changes the contents of $filename to $content. No action is performed +until the distribution is regenerated. + + $dist->change_file( $filename, $content ); + +=head3 change_build_pl() + +A wrapper around change_file specifically for setting Build.PL. Instead +of file C<$content>, it takes a hash-ref of Module::Build constructor +arguments: + + $dist->change_build_pl( + { + module_name => $dist->name, + dist_version => '3.14159265', + license => 'perl', + create_readme => 1, + } + ); + +=head3 get_file + +Retrieves the target contents of C<$filename>. + + $content = $dist->get_file( $filename ); + +=head3 remove_file() + +Removes C<$filename> from the distribution. + + $dist->remove_file( $filename ); + +=head3 revert() + +Returns the object to its initial state, or given a $filename it returns that +file to its initial state if it is one of the built-in files. + + $dist->revert; + $dist->revert($filename); + +=head2 Changing the distribution directory + +These methods immediately affect the filesystem. + +=head3 regen() + +Regenerate all missing or changed files. Also deletes any files +flagged for removal with remove_file(). + + $dist->regen(clean => 1); + +If the optional C<clean> argument is given, it also calls C<clean>. These +can also be chained like this, instead: + + $dist->clean->regen; + +=head3 clean() + +Removes any files that are not part of the distribution. + + $dist->clean; + +=head3 remove() + +Changes back to the original directory and removes the distribution +directory (but not the temporary directory set during C<new()>). + + $dist = DistGen->new->chdir->regen; + # ... do some testing ... + + $dist->remove->chdir_in->regen; + # ... do more testing ... + +This is like a more aggressive form of C<clean>. Generally, calling C<clean> +and C<regen> should be sufficient. + +=head2 Changing directories + +=head3 chdir_in + +Change directory into the dist root. + + $dist->chdir_in; + +=head3 chdir_original + +Returns to whatever directory you were in before chdir_in() (regardless +of the cwd.) + + $dist->chdir_original; + +=head2 Command-line helpers + +These use Module::Build->run_perl_script() to ensure that Build.PL or Build are +run in a separate process using the current perl interpreter. (Module::Build +is loaded on demand). They also ensure appropriate naming for operating +systems that require a suffix for Build. + +=head3 run_build_pl + +Runs Build.PL using the current perl interpreter. Any arguments are +passed on the command line. + + $dist->run_build_pl('--quiet'); + +=head3 run_build + +Runs Build using the current perl interpreter. Any arguments are +passed on the command line. + + $dist->run_build(qw/test --verbose/); + +=head2 Properties + +=head3 name() + +Returns the name of the distribution. + + $dist->name: # e.g. Foo::Bar + +=head3 dirname() + +Returns the directory where the distribution is created. + + $dist->dirname; # e.g. t/_tmp/Simple + +=head2 Functions + +=head3 undent() + +Removes leading whitespace from a multi-line string according to the +amount of whitespace on the first line. + + my $string = undent(" foo(\n bar => 'baz'\n )"); + $string eq "foo( + bar => 'baz' + )"; + +=cut + +# vim:ts=2:sw=2:et:sta diff --git a/t/lib/MBTest.pm b/t/lib/MBTest.pm new file mode 100644 index 0000000..fda7f69 --- /dev/null +++ b/t/lib/MBTest.pm @@ -0,0 +1,314 @@ +package MBTest; + +use strict; + +use File::Spec; +use File::Temp (); +use File::Path (); + + +# Setup the code to clean out %ENV +BEGIN { + # Environment variables which might effect our testing + my @delete_env_keys = qw( + HOME + DEVEL_COVER_OPTIONS + MODULEBUILDRC + PERL_MB_OPT + HARNESS_TIMER + HARNESS_OPTIONS + HARNESS_VERBOSE + PREFIX + INSTALL_BASE + INSTALLDIRS + ); + + # Remember the ENV values because on VMS %ENV is global + # to the user, not the process. + my %restore_env_keys; + + sub clean_env { + for my $key (@delete_env_keys) { + if( exists $ENV{$key} ) { + $restore_env_keys{$key} = delete $ENV{$key}; + } + else { + delete $ENV{$key}; + } + } + } + + END { + while( my($key, $val) = each %restore_env_keys ) { + $ENV{$key} = $val; + } + } +} + + +BEGIN { + clean_env(); + + # In case the test wants to use our other bundled + # modules, make sure they can be loaded. + my $t_lib = File::Spec->catdir('t', 'bundled'); + push @INC, $t_lib; # Let user's installed version override + + # We change directories, so expand @INC and $^X to absolute paths + # Also add . + @INC = (map(File::Spec->rel2abs($_), @INC), "."); + $^X = File::Spec->rel2abs($^X); +} + +use Exporter; +use Test::More; +use Config; +use Cwd (); + +# We pass everything through to Test::More +use vars qw($VERSION @ISA @EXPORT $TODO); +@ISA = ('Exporter'); +$VERSION = 0.01_01; + +# We have a few extra exports, but Test::More has a special import() +# that won't take extra additions. +@EXPORT = ( + qw( + stdout_of + stderr_of + stdout_stderr_of + slurp + find_in_path + check_compiler + have_module + blib_load + timed_out + $TODO + ), + @Test::More::EXPORT, +); + +sub import { + my $class = shift; + my $caller = caller; + + my @imports; + + while (my $item = shift @_) { + if ($item eq 'tests' || $item eq 'skip_all') { + my $arg = shift @_; + plan($item => $arg); + } + elsif($item eq 'no_plan') { + plan($item); + } + else { + push @imports => $item; + } + } + + @imports = @EXPORT unless @imports; + + $class->export($caller, @imports); +} + + +######################################################################## + +# always return to the current directory +{ + my $cwd; + # must be done in BEGIN because tmpdir uses it in BEGIN for $ENV{HOME} + BEGIN { + $cwd = File::Spec->rel2abs(Cwd::cwd); + } + + sub original_cwd { return $cwd } + + END { + # Go back to where you came from! + chdir $cwd or die "Couldn't chdir to $cwd"; + } +} +######################################################################## + +{ # backwards compatible temp filename recipe adapted from perlfaq + my $tmp_count = 0; + my $tmp_base_name = sprintf("MB-%d-%d", $$, time()); + sub temp_file_name { + sprintf("%s-%04d", $tmp_base_name, ++$tmp_count) + } +} +######################################################################## + +# Setup a temp directory +sub tmpdir { + my ($self, @args) = @_; + my $dir = $ENV{PERL_CORE} ? MBTest->original_cwd : File::Spec->tmpdir; + return File::Temp::tempdir('MB-XXXXXXXX', CLEANUP => 1, DIR => $dir, @args); +} + +BEGIN { + $ENV{HOME} = tmpdir; # don't want .modulebuildrc or other things interfering +} + +sub save_handle { + my ($handle, $subr) = @_; + my $outfile = File::Spec->catfile(File::Spec->tmpdir, temp_file_name()); + + local *SAVEOUT; + open SAVEOUT, ">&" . fileno($handle) + or die "Can't save output handle: $!"; + open $handle, "> $outfile" or die "Can't create $outfile: $!"; + + eval {$subr->()}; + open $handle, ">&SAVEOUT" or die "Can't restore output: $!"; + + my $ret = slurp($outfile); + 1 while unlink $outfile; + return $ret; +} + +sub stdout_of { save_handle(\*STDOUT, @_) } +sub stderr_of { save_handle(\*STDERR, @_) } +sub stdout_stderr_of { + my $subr = shift; + my ($stdout, $stderr); + $stdout = stdout_of ( sub { + $stderr = stderr_of( $subr ) + }); + return wantarray ? ($stdout, $stderr) : $stdout . $stderr; +} + +sub slurp { + open(my $fh, '<', $_[0]) or die "Can't open $_[0]: $!"; + local $/; + return scalar <$fh>; +} + +# Some extensions we should know about if we're looking for executables +sub exe_exts { + + if ($^O eq 'MSWin32') { + return split($Config{path_sep}, $ENV{PATHEXT} || '.com;.exe;.bat'); + } + if ($^O eq 'os2') { + return qw(.exe .com .pl .cmd .bat .sh .ksh); + } + return; +} + +sub find_in_path { + my $thing = shift; + + my @exe_ext = exe_exts(); + if ( File::Spec->file_name_is_absolute( $thing ) ) { + foreach my $ext ( '', @exe_ext ) { + return "$thing$ext" if -e "$thing$ext"; + } + } + else { + my @path = split $Config{path_sep}, $ENV{PATH}; + foreach (@path) { + my $fullpath = File::Spec->catfile($_, $thing); + foreach my $ext ( '', @exe_ext ) { + return "$fullpath$ext" if -e "$fullpath$ext"; + } + } + } + return; +} + +sub check_compiler { + if ($ENV{PERL_CORE}) { + require IPC::Cmd; + if ( $Config{usecrosscompile} && !IPC::Cmd::can_run($Config{cc}) ) { + return; + } + else { + return(1,1); + } + } + + local $SIG{__WARN__} = sub {}; + + blib_load('Module::Build'); + my $mb = Module::Build->current; + $mb->verbose( 0 ); + + my $have_c_compiler; + stderr_of( sub {$have_c_compiler = $mb->have_c_compiler} ); + # XXX link_executable() is not yet implemented for Windows + # and noexec tmpdir is irrelevant on Windows + return ($have_c_compiler, 1) if $^O eq "MSWin32"; + + # check noexec tmpdir + my $tmp_exec; + if ( $have_c_compiler ) { + my $dir = MBTest->tmpdir; + my $c_file = File::Spec->catfile($dir,'test.c'); + open my $fh, ">", $c_file; + print {$fh} "int main() { return 0; }\n"; + close $fh; + my $exe = $mb->cbuilder->link_executable( + objects => $mb->cbuilder->compile( source => $c_file ) + ); + $tmp_exec = 0 == system( $exe ); + } + return ($have_c_compiler, $tmp_exec); +} + +sub have_module { + my $module = shift; + return eval "require $module; 1"; +} + +sub blib_load { + # Load the given module and ensure it came from blib/, not the larger system + my $mod = shift; + have_module($mod) or die "Error loading $mod\: $@\n"; + + (my $path = $mod) =~ s{::}{/}g; + $path .= ".pm"; + my ($pkg, $file, $line) = caller; + unless($ENV{PERL_CORE}) { + unless($INC{$path} =~ m/\bblib\b/) { + (my $load_from = $INC{$path}) =~ s{$path$}{}; + die "$mod loaded from '$load_from'\nIt should have been loaded from blib. \@INC contains:\n ", + join("\n ", @INC) . "\nFatal error occured in blib_load() at $file, line $line.\n"; + } + } +} + +sub timed_out { + my ($sub, $timeout) = @_; + return unless $sub; + $timeout ||= 60; + + my $saw_alarm = 0; + eval { + local $SIG{ALRM} = sub { $saw_alarm++; die "alarm\n"; }; # NB: \n required + alarm $timeout; + $sub->(); + alarm 0; + }; + if ($@) { + die unless $@ eq "alarm\n"; # propagate unexpected errors + } + return $saw_alarm; +} + +sub check_EUI { + my $timed_out; + stdout_stderr_of( sub { + $timed_out = timed_out( sub { + ExtUtils::Installed->new(extra_libs => [@INC]) + } + ); + } + ); + return ! $timed_out; +} + +1; +# vim:ts=2:sw=2:et:sta diff --git a/t/lib/Module/Signature.pm b/t/lib/Module/Signature.pm new file mode 100644 index 0000000..2d58f7d --- /dev/null +++ b/t/lib/Module/Signature.pm @@ -0,0 +1,11 @@ +package Module::Signature; # mocked +use strict; +use warnings; +our $VERSION = 999; + +sub sign { + open my $fh, ">", "SIGNATURE"; + print {$fh} "SIGNATURE"; +} + +1; diff --git a/t/lib/Software/License/VaporWare.pm b/t/lib/Software/License/VaporWare.pm new file mode 100644 index 0000000..80d9fa5 --- /dev/null +++ b/t/lib/Software/License/VaporWare.pm @@ -0,0 +1,17 @@ +use strict; +use warnings; + +package Software::License::VaporWare; +our $VERSION = '0.001'; + +use Software::License; +our @ISA = qw/Software::License/; + +sub name { 'VaporWare License' } +sub url { 'http://example.com/vaporware/' } +sub meta_name { 'unrestricted' } +sub meta2_name { 'unrestricted' } + +1; + + diff --git a/t/manifypods.t b/t/manifypods.t new file mode 100644 index 0000000..de2a3e4 --- /dev/null +++ b/t/manifypods.t @@ -0,0 +1,158 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +if ( Module::Build::ConfigData->feature('manpage_support') ) { + plan tests => 21; +} else { + plan skip_all => 'manpage_support feature is not enabled'; +} + + +######################### + + +use Cwd (); +my $cwd = Cwd::cwd; +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->add_file( 'bin/nopod.pl', <<'---' ); +#!perl -w +print "sample script without pod to test manifypods action\n"; +--- +$dist->add_file( 'bin/haspod.pl', <<'---' ); +#!perl -w +print "Hello, world"; + +__END__ + +=head1 NAME + +haspod.pl - sample script with pod to test manifypods action + +=cut +--- +$dist->add_file( 'lib/Simple/NoPod.pm', <<'---' ); +package Simple::NoPod; +1; +--- +$dist->add_file( 'lib/Simple/AllPod.pod', <<'---' ); +=head1 NAME + +Simple::AllPod - Pure POD + +=head1 AUTHOR + +Simple Man <simple@example.com> + +=cut +--- +$dist->regen; + + +$dist->chdir_in; + +use File::Spec::Functions qw( catdir ); +my $destdir = catdir($cwd, 't', 'install_test' . $$); + + +my $mb = Module::Build->new( + module_name => $dist->name, + install_base => $destdir, + scripts => [ File::Spec->catfile( 'bin', 'nopod.pl' ), + File::Spec->catfile( 'bin', 'haspod.pl' ) ], + + # Need default install paths to ensure manpages get generated + installdirs => 'site', + config => { + installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'), + installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'), + } + +); + +$mb->add_to_cleanup($destdir); + + +is( ref $mb->{properties}->{bindoc_dirs}, 'ARRAY', 'bindoc_dirs' ); +is( ref $mb->{properties}->{libdoc_dirs}, 'ARRAY', 'libdoc_dirs' ); + +my %man = ( + sep => $mb->manpage_separator, + dir1 => 'man1', + dir3 => 'man3', + ext1 => $mb->config('man1ext'), + ext3 => $mb->config('man3ext'), + ); + +my %distro = ( + 'bin/nopod.pl' => '', + 'bin/haspod.pl' => "haspod.pl.$man{ext1}", + 'lib/Simple.pm' => "Simple.$man{ext3}", + 'lib/Simple/NoPod.pm' => '', + 'lib/Simple/AllPod.pod' => "Simple$man{sep}AllPod.$man{ext3}", + ); + +%distro = map {$mb->localize_file_path($_), $distro{$_}} keys %distro; + +my $lib_path = $mb->localize_dir_path('lib'); + +# Remove trailing directory delimiter on VMS for compares +$lib_path =~ s/\]// if $^O eq 'VMS'; + +$mb->dispatch('build'); + +eval {$mb->dispatch('docs')}; +is $@, ''; + +while (my ($from, $v) = each %distro) { + if (!$v) { + ok ! $mb->contains_pod($from), "$from should not contain POD"; + next; + } + + my $to = File::Spec->catfile('blib', ($from =~ /^[\.\/\[]*lib/ ? 'libdoc' : 'bindoc'), $v); + ok $mb->contains_pod($from), "$from should contain POD"; + ok -e $to, "Created $to manpage"; +} + + +$mb->dispatch('install'); + +while (my ($from, $v) = each %distro) { + next unless $v; + my $to = File::Spec->catfile + ($destdir, 'man', $man{($from =~ /^\Q$lib_path\E/ ? 'dir3' : 'dir1')}, $v); + ok -e $to, "Created $to manpage"; +} + +$mb->dispatch('realclean'); + + +# revert to a pristine state +$dist->regen( clean => 1 ); + +my $mb2 = Module::Build->new( + module_name => $dist->name, + libdoc_dirs => [qw( foo bar baz )], +); + +is( $mb2->{properties}->{libdoc_dirs}->[0], 'foo', 'override libdoc_dirs' ); + +# Make sure we can find our own action documentation +ok $mb2->get_action_docs('build'); +ok !eval{$mb2->get_action_docs('foo')}; + +# Make sure those docs are the correct ones +foreach ('testcover', 'disttest') { + my $docs = $mb2->get_action_docs($_); + like $docs, qr/=item $_/; + unlike $docs, qr/\n=/, $docs; +} + diff --git a/t/manifypods_with_utf8.t b/t/manifypods_with_utf8.t new file mode 100644 index 0000000..ebb0db6 --- /dev/null +++ b/t/manifypods_with_utf8.t @@ -0,0 +1,68 @@ +package ManifypodsWithUtf8; +use strict; +use utf8; +use Test::More; + +use lib 't/lib'; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +SKIP: { + unless ( Module::Build::ConfigData->feature('manpage_support') ) { + skip 'manpage_support feature is not enabled'; + } +} + +use MBTest tests => 2; +use File::Spec::Functions qw( catdir ); + +use Cwd (); +my $cwd = Cwd::cwd; +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +my $content = <<'---'; + +=encoding utf8 + +=head1 NAME + +Simple::PodWithUtf8 - POD with some (ç á à ô) special chars + +=cut +--- +utf8::encode($content); +$dist->add_file( 'lib/Simple/PodWithUtf8.pod', $content); +$dist->regen; +$dist->chdir_in; + +my $destdir = catdir($cwd, 't', 'install_test' . $$); + +my $mb = Module::Build->new( + module_name => $dist->name, + install_base => $destdir, + + # need default install paths to ensure manpages get generated + installdirs => 'site', + config => { + installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'), + installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'), + }, + extra_manify_args => { utf8 => 1 }, + ); +$mb->add_to_cleanup($destdir); + + +$mb->dispatch('build'); +my $sep = $mb->manpage_separator; +my $ext3 = $mb->config('man3ext'); +my $to = File::Spec->catfile('blib', 'libdoc', "Simple${sep}PodWithUtf8.${ext3}"); + +ok(-e $to, "Manpage is found at $to"); +open my $pod, '<:encoding(utf-8)', $to or diag "Could not open $to: $!"; +my $pod_content = do { local $/; <$pod> }; +close $pod; + +like($pod_content, qr/ \(ç á à ô\) /, "POD should contain special characters"); + diff --git a/t/metadata.t b/t/metadata.t new file mode 100755 index 0000000..ae9a5af --- /dev/null +++ b/t/metadata.t @@ -0,0 +1,109 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 14; + +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +my $tmp = MBTest->tmpdir; + +my %metadata = + ( + module_name => 'Simple', + dist_version => '3.14159265', + dist_author => [ 'Simple Simon <ss\@somewhere.priv>' ], + dist_abstract => 'Something interesting', + test_requires => { + 'Test::More' => 0.49, + }, + license => 'perl', + meta_add => { + keywords => [qw(super duper something)], + resources => {homepage => 'http://foo.example.com'}, + }, + ); + + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->change_build_pl( \%metadata ); +$dist->regen; + +my $simple_file = 'lib/Simple.pm'; +my $simple2_file = 'lib/Simple2.pm'; + + # Traditional VMS will return the file in in lower case, and is_deeply + # does exact case comparisons. + # When ODS-5 support is active for preserved case file names we do not + # change the case. + if ($^O eq 'VMS') { + my $lower_case_expect = 1; + my $vms_efs_case = 0; + if (eval 'require VMS::Feature') { + $vms_efs_case = VMS::Feature::current("efs_case_preserve"); + } else { + my $efs_case = $ENV{'DECC$EFS_CASE_PRESERVE'} || ''; + $vms_efs_case = $efs_case =~ /^[ET1]/i; + } + $lower_case_expect = 0 if $vms_efs_case; + if ($lower_case_expect) { + $simple_file = lc($simple_file); + $simple2_file = lc($simple2_file); + } + } + + +$dist->chdir_in; + +my $mb = Module::Build->new_from_context; + +################################################## +# +# Test for valid META.yml + +{ + my $mb_prereq = { 'Module::Build' => $Module::Build::VERSION }; + my $mb_config_req = { + 'Module::Build' => sprintf '%2.2f', int($Module::Build::VERSION * 100)/100 + }; + my $node; + my $output = stdout_stderr_of( sub { + $node = $mb->get_metadata( auto => 1 ); + }); + like( $output, qr/Module::Build was not found in configure_requires/, + "saw warning about M::B not in configure_requires" + ); + + # exists() doesn't seem to work here + is $node->{name}, $metadata{module_name}; + is $node->{version}, $metadata{dist_version}; + is $node->{abstract}, $metadata{dist_abstract}; + is_deeply $node->{author}, $metadata{dist_author}; + is_deeply $node->{license}, [ 'perl_5' ]; + is_deeply $node->{prereqs}{configure}{requires}, $mb_config_req, 'Add M::B to configure_requires'; + is_deeply $node->{prereqs}{test}{requires}, { + 'Test::More' => '0.49', + }, 'Test::More was required by ->new'; + like $node->{generated_by}, qr{Module::Build}; + ok defined( $node->{'meta-spec'}{version} ), + "'meta-spec' -> 'version' field present in META.yml"; + ok defined( $node->{'meta-spec'}{url} ), + "'meta-spec' -> 'url' field present in META.yml"; + is_deeply $node->{keywords}, $metadata{meta_add}{keywords}; + is_deeply $node->{resources}, $metadata{meta_add}{resources}; +} + +{ + my $mb_prereq = { 'Module::Build' => 0 }; + $mb->configure_requires( $mb_prereq ); + my $node = $mb->get_metadata( auto => 1 ); + + + # exists() doesn't seem to work here + is_deeply $node->{prereqs}{configure}{requires}, $mb_prereq, 'Add M::B to configure_requires'; +} + +$dist->clean; + diff --git a/t/metadata2.t b/t/metadata2.t new file mode 100644 index 0000000..347a9a4 --- /dev/null +++ b/t/metadata2.t @@ -0,0 +1,128 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 18; + +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +use DistGen; + + +############################## ACTION distmeta works without a MANIFEST file + +{ + my $dist = DistGen->new( no_manifest => 1 )->chdir_in->regen; + + ok ! -e 'MANIFEST'; + + my $mb; + stderr_of( sub { $mb = Module::Build->new_from_context } ); + + my $out; + $out = eval { stderr_of(sub{$mb->dispatch('distmeta')}) }; + is $@, ''; + + like $out, qr/Nothing to enter for 'provides'/; + + ok -e 'META.yml'; + +} + + +############################## Check generation of README file + +# TODO: We need to test faking the absence of Pod::Readme when present +# so Pod::Text will be used. Also fake the absence of both to +# test that we fail gracefully. + +my $provides; # Used a bunch of times below + +my $pod_text = <<'---'; +=pod + +=head1 NAME + +Simple - A simple module + +=head1 AUTHOR + +Simple Simon <simon@simple.sim> + +=cut +--- + +my $dist = DistGen->new->chdir_in; + +$dist->change_build_pl +({ + module_name => $dist->name, + dist_version => '3.14159265', + license => 'perl', + create_readme => 1, +}); + +# .pm File with pod +# + +$dist->change_file( 'lib/Simple.pm', <<'---' . $pod_text); +package Simple; +$VERSION = '1.23'; +--- +$dist->regen( clean => 1 ); +ok( -e "lib/Simple.pm", "Creating Simple.pm" ); +my $mb = Module::Build->new_from_context; +$mb->do_create_readme; +like( slurp("README"), qr/NAME/, + "Generating README from .pm"); +is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', + "Extracting AUTHOR from .pm"); +is( $mb->dist_abstract, "A simple module", + "Extracting abstract from .pm"); + +# .pm File with pod in separate file +# + +$dist->change_file( 'lib/Simple.pm', <<'---'); +package Simple; +$VERSION = '1.23'; +--- +$dist->change_file( 'lib/Simple.pod', $pod_text ); +$dist->regen( clean => 1 ); + +ok( -e "lib/Simple.pm", "Creating Simple.pm" ); +ok( -e "lib/Simple.pod", "Creating Simple.pod" ); +$mb = Module::Build->new_from_context; +$mb->do_create_readme; +like( slurp("README"), qr/NAME/, "Generating README from .pod"); +is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', + "Extracting AUTHOR from .pod"); +is( $mb->dist_abstract, "A simple module", + "Extracting abstract from .pod"); + +# .pm File with pod and separate pod file +# + +$dist->change_file( 'lib/Simple.pm', <<'---' ); +package Simple; +$VERSION = '1.23'; + +=pod + +=head1 DONT USE THIS FILE FOR POD + +=cut +--- +$dist->change_file( 'lib/Simple.pod', $pod_text ); +$dist->regen( clean => 1 ); +ok( -e "lib/Simple.pm", "Creating Simple.pm" ); +ok( -e "lib/Simple.pod", "Creating Simple.pod" ); +$mb = Module::Build->new_from_context; +$mb->do_create_readme; +like( slurp("README"), qr/NAME/, "Generating README from .pod over .pm"); +is( $mb->dist_author->[0], 'Simple Simon <simon@simple.sim>', + "Extracting AUTHOR from .pod over .pm"); +is( $mb->dist_abstract, "A simple module", + "Extracting abstract from .pod over .pm"); + diff --git a/t/mymeta.t b/t/mymeta.t new file mode 100644 index 0000000..73cda05 --- /dev/null +++ b/t/mymeta.t @@ -0,0 +1,170 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use CPAN::Meta 2.110420; +use CPAN::Meta::YAML; +use Parse::CPAN::Meta 1.4401; +plan tests => 41; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->change_file('Build.PL', <<"---"); +use strict; +use Module::Build; + +my \$builder = Module::Build->new( + module_name => '$dist->{name}', + license => 'perl', + requires => { + 'File::Spec' => ( \$ENV{BUMP_PREREQ} ? 0.86 : 0 ), + }, + configure_requires => { + 'Module::Build' => '0.42', + } +); + +\$builder->create_build_script(); +--- +$dist->regen; +$dist->chdir_in; + +######################### + +# Test MYMETA generation +{ + ok( ! -e "META.yml", "META.yml doesn't exist before Build.PL runs" ); + ok( ! -e "MYMETA.yml", "MYMETA.yml doesn't exist before Build.PL runs" ); + ok( ! -e "META.json", "META.json doesn't exist before Build.PL runs" ); + ok( ! -e "MYMETA.json", "MYMETA.json doesn't exist before Build.PL runs" ); + my $output; + $output = stdout_of sub { $dist->run_build_pl }; + like($output, qr/Created MYMETA\.yml and MYMETA\.json/, + "Ran Build.PL and saw MYMETA.yml creation message" + ); + ok( -e "MYMETA.yml", "MYMETA.yml exists" ); + ok( -e "MYMETA.json", "MYMETA.json exists" ); +} + +######################### + +# Test interactions between META/MYMETA +{ + my $output = stdout_stderr_of sub { $dist->run_build('distmeta') }; + like($output, qr/Created META\.yml and META\.json/, + "Ran Build distmeta to create META.yml"); + # regenerate MYMETA to pick up from META instead of creating from scratch + $output = stdout_of sub { $dist->run_build_pl }; + like($output, qr/Created MYMETA\.yml and MYMETA\.json/, + "Re-ran Build.PL and regenerated MYMETA.yml based on META.yml" + ); + + for my $suffix ( qw/.yml .json/ ) { + my $meta = Parse::CPAN::Meta->load_file("META$suffix"); + my $mymeta = Parse::CPAN::Meta->load_file("MYMETA$suffix"); + is( delete $meta->{dynamic_config}, 1, + "META$suffix 'dynamic_config' is 1" + ); + is( delete $mymeta->{dynamic_config}, 0, + "MYMETA$suffix 'dynamic_config' is 0" + ); + + my $have_url = delete $mymeta->{'meta-spec'}->{url}; + my $want_url = delete $meta->{'meta-spec'}->{url}; + + is_deeply( $mymeta, $meta, "Other generated MYMETA$suffix matches generated META$suffix" ) + or do { + require Data::Dumper; + diag "MYMETA:\n" . Data::Dumper::Dumper($mymeta) + . "META:\n" . Data::Dumper::Dumper($meta); + }; + + like $have_url, qr{Meta(::|-)Spec}i, "CPAN meta spec mentioned in meta-spec URL"; + } + + $output = stdout_stderr_of sub { $dist->run_build('realclean') }; + like( $output, qr/Cleaning up/, "Ran realclean"); + ok( ! -e 'Build', "Build file removed" ); + ok( ! -e 'MYMETA.yml', "MYMETA.yml file removed" ); + ok( ! -e 'MYMETA.json', "MYMETA.json file removed" ); + + # test that dynamic prereq is picked up + my $meta = Parse::CPAN::Meta->load_file("META.yml"); + my $meta2 = Parse::CPAN::Meta->load_file("META.json"); + local $ENV{BUMP_PREREQ} = 1; + $output = stdout_of sub { $dist->run_build_pl }; + like($output, qr/Created MYMETA\.yml and MYMETA\.json/, + "Ran Build.PL with dynamic config" + ); + ok( -e "MYMETA.yml", "MYMETA.yml exists" ); + ok( -e "MYMETA.json", "MYMETA.json exists" ); + my $mymeta = Parse::CPAN::Meta->load_file('MYMETA.yml'); + my $mymeta2 = Parse::CPAN::Meta->load_file('MYMETA.json'); + isnt( $meta->{requires}{'File::Spec'}, + $mymeta->{requires}{'File::Spec'}, + "MYMETA.yml requires differs from META.yml" + ); + isnt( $meta2->{prereqs}{runtime}{requires}{'File::Spec'}, + $mymeta2->{prereqs}{runtime}{requires}{'File::Spec'}, + "MYMETA.json requires differs from META.json" + ); + $output = stdout_stderr_of sub { $dist->run_build('realclean') }; + like( $output, qr/Cleaning up/, "Ran realclean"); + ok( ! -e 'Build', "Build file removed" ); + ok( ! -e 'MYMETA.yml', "MYMETA file removed" ); + ok( ! -e 'MYMETA.json', "MYMETA file removed" ); + + # manually change META and check that changes are preserved + $meta->{author} = ['John Gault']; + $meta2->{author} = ['John Gault']; + ok( CPAN::Meta::YAML->new($meta)->write('META.yml'), + "Wrote manually modified META.yml" ); + ok( CPAN::Meta->new( $meta2 )->save('META.json'), + "Wrote manually modified META.json" ); + + $output = stdout_of sub { $dist->run_build_pl }; + like($output, qr/Created MYMETA\.yml and MYMETA\.json/, + "Ran Build.PL" + ); + $mymeta = Parse::CPAN::Meta->load_file('MYMETA.yml'); + $mymeta2 = Parse::CPAN::Meta->load_file('MYMETA.json'); + is_deeply( $mymeta->{author}, [ 'John Gault' ], + "MYMETA.yml preserved META.yml modifications" + ); + is_deeply( $mymeta2->{author}, [ 'John Gault' ], + "MYMETA.json preserved META.json modifications" + ); + +} + +######################### + +# Test cleanup +{ + my $output = stdout_stderr_of sub { $dist->run_build('distcheck') }; + like($output, qr/Creating a temporary 'MANIFEST.SKIP'/, + "MANIFEST.SKIP created for distcheck" + ); + unlike($output, qr/MYMETA/, + "MYMETA not flagged by distcheck" + ); +} + + +{ + my $output = stdout_of sub { $dist->run_build_pl }; + like($output, qr/Created MYMETA\.yml and MYMETA\.json/, + "Ran Build.PL and saw MYMETA.yml creation message" + ); + $output = stdout_stderr_of sub { $dist->run_build('distclean') }; + ok( ! -f 'MYMETA.yml', "No MYMETA.yml after distclean" ); + ok( ! -f 'MYMETA.json', "No MYMETA.json after distclean" ); + ok( ! -f 'MANIFEST.SKIP', "No MANIFEST.SKIP after distclean" ); +} + + diff --git a/t/new_from_context.t b/t/new_from_context.t new file mode 100644 index 0000000..a9ec00b --- /dev/null +++ b/t/new_from_context.t @@ -0,0 +1,26 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 2; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); + +my $libdir = 'badlib'; +$dist->add_file("$libdir/Build.PL", 'die'); +$dist->regen; + +$dist->chdir_in; + + +unshift(@INC, $libdir); +my $mb = eval { Module::Build->new_from_context}; +ok(! $@, 'dodged the bullet') or die; +ok($mb); + +# vim:ts=2:sw=2:et:sta diff --git a/t/notes.t b/t/notes.t new file mode 100644 index 0000000..4568e7c --- /dev/null +++ b/t/notes.t @@ -0,0 +1,66 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 11; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + + +################################### +$dist->change_file( 'Build.PL', <<"---" ); +use Module::Build; +my \$build = Module::Build->new( + module_name => @{[$dist->name]}, + license => 'perl' +); +\$build->create_build_script; +\$build->notes(foo => 'bar'); +--- + +$dist->regen; + +my $mb = Module::Build->new_from_context; + +is $mb->notes('foo'), 'bar'; + +# Try setting & checking a new value +$mb->notes(argh => 'new'); +is $mb->notes('argh'), 'new'; + +# Change existing value +$mb->notes(foo => 'foo'); +is $mb->notes('foo'), 'foo'; + +# Change back so we can run this test again successfully +$mb->notes(foo => 'bar'); +is $mb->notes('foo'), 'bar'; + +# Check undef vs. 0 vs '' +foreach my $val (undef, 0, '') { + $mb->notes(null => $val); + is $mb->notes('null'), $val; +} + + +################################### +# Make sure notes set before create_build_script() get preserved +$mb = Module::Build->new(module_name => $dist->name); +ok $mb; +$mb->notes(foo => 'bar'); +is $mb->notes('foo'), 'bar'; + +$mb->create_build_script; + +$mb = Module::Build->resume; +ok $mb; +is $mb->notes('foo'), 'bar'; + @@ -0,0 +1,96 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +my $tmp; + +{ + my ($have_c_compiler, $tmp_exec) = check_compiler(); + if ( ! $have_c_compiler ) { + plan skip_all => 'No compiler found'; + } elsif ( ! eval {require PAR::Dist; PAR::Dist->VERSION(0.17)} ) { + plan skip_all => "PAR::Dist 0.17 or up not installed to check .par's."; + } elsif ( ! eval {require Archive::Zip} ) { + plan skip_all => "Archive::Zip required."; + } else { + plan tests => 3; + } + require Cwd; + $tmp = MBTest->tmpdir( $tmp_exec ? () : (DIR => Cwd::cwd) ); +} + + + +use DistGen; +my $dist = DistGen->new( dir => $tmp, xs => 1 ); +$dist->add_file( 'hello', <<'---' ); +#!perl -w +print "Hello, World!\n"; +__END__ + +=pod + +=head1 NAME + +hello + +=head1 DESCRIPTION + +Says "Hello" + +=cut +--- +$dist->change_build_pl +({ + module_name => $dist->name, + version => '0.01', + license => 'perl', + scripts => [ 'hello' ], +}); +$dist->regen; + +$dist->chdir_in; + +use File::Spec::Functions qw(catdir); + +my @installstyle = qw(lib perl5); +my $mb = Module::Build->new_from_context( + verbose => 0, + quiet => 1, + + installdirs => 'site', +); + +my $filename = $mb->dispatch('pardist'); + +ok( -f $filename, '.par distributions exists' ); +my $distname = $dist->name; +ok( $filename =~ /^\Q$distname\E/, 'Distribution name seems correct' ); + +#--------------------------------------------------------------------------# +# must work around broken Archive::Zip (1.28) which breaks PAR::Dist +#--------------------------------------------------------------------------# + +SKIP: { + my $zip = Archive::Zip->new; + my $tmp2 = MBTest->tmpdir; + local %SIG; + $SIG{__WARN__} = sub { print STDERR $_[0] unless $_[0] =~ /\bstat\b/ }; + skip "broken Archive::Zip", 1 + unless eval { $zip->read($filename) == Archive::Zip::AZ_OK() } + && eval { $zip->extractTree('', "$tmp2/") == Archive::Zip::AZ_OK() } + && -r File::Spec->catfile( $tmp2, 'blib', 'META.yml' ); + + my $meta; + eval { $meta = PAR::Dist::get_meta($filename) }; + + ok( + (not $@ and defined $meta and not $meta eq ''), + 'Distribution contains META.yml' + ); +} + diff --git a/t/parents.t b/t/parents.t new file mode 100644 index 0000000..825f79a --- /dev/null +++ b/t/parents.t @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 26; + +blib_load('Module::Build'); + +######################### + +package Foo; +sub foo; + +package MySub1; +use base 'Module::Build'; + +package MySub2; +use base 'MySub1'; + +package MySub3; +use base qw(MySub2 Foo); + +package MyTest; +use base 'Module::Build'; + +package MyBulk; +use base qw(MySub2 MyTest); + +package main; + +ok my @parents = MySub1->mb_parents; +# There will be at least one platform class in between. +ok @parents >= 2; +# They should all inherit from Module::Build::Base; +ok ! grep { !$_->isa('Module::Build::Base') } @parents; +is $parents[0], 'Module::Build'; +is $parents[-1], 'Module::Build::Base'; + +ok @parents = MySub2->mb_parents; +ok @parents >= 3; +ok ! grep { !$_->isa('Module::Build::Base') } @parents; +is $parents[0], 'MySub1'; +is $parents[1], 'Module::Build'; +is $parents[-1], 'Module::Build::Base'; + +ok @parents = MySub3->mb_parents; +ok @parents >= 4; +ok ! grep { !$_->isa('Module::Build::Base') } @parents; +is $parents[0], 'MySub2'; +is $parents[1], 'MySub1'; +is $parents[2], 'Module::Build'; +is $parents[-1], 'Module::Build::Base'; + +ok @parents = MyBulk->mb_parents; +ok @parents >= 5; +ok ! grep { !$_->isa('Module::Build::Base') } @parents; +is $parents[0], 'MySub2'; +is $parents[1], 'MySub1'; +is $parents[2], 'Module::Build'; +is $parents[-2], 'Module::Build::Base'; +is $parents[-1], 'MyTest'; diff --git a/t/perl_mb_opt.t b/t/perl_mb_opt.t new file mode 100644 index 0000000..70089ee --- /dev/null +++ b/t/perl_mb_opt.t @@ -0,0 +1,62 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 8; # or 'no_plan' + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in->regen; + +$dist->add_file('t/subtest/foo.t', <<'END_T'); +use strict; +use Test::More tests => 1; +ok(1, "this is a recursive test"); +END_T + +$dist->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); +ok( ! $mb->recursive_test_files, "set for no recursive testing" ); + +# set for recursive testing using PERL_MB_OPT +{ + local $ENV{PERL_MB_OPT} = "--verbose --recursive_test_files 1"; + + my $out = stdout_stderr_of( sub { + $dist->run_build('test'); + }); + like( $out, qr/this is a recursive test/, + "recursive tests run via PERL_MB_OPT" + ); +} + +# set Build.PL opts using PERL_MB_OPT +{ + local $ENV{PERL_MB_OPT} = "--verbose --recursive_test_files 1"; + my $mb = $dist->new_from_context(); # quiet by default + ok( $mb->recursive_test_files, "PERL_MB_OPT set recusive tests in Build.PL" ); + ok( $mb->verbose, "PERL_MB_OPT set verbose in Build.PL" ); +} + +# verify settings preserved during 'Build test' +{ + ok( !$ENV{PERL_MB_OPT}, "PERL_MB_OPT cleared" ); + my $out = stdout_stderr_of( sub { + $dist->run_build('test'); + }); + like( $out, qr/this is a recursive test/, + "recursive tests run via Build object" + ); +} + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/pod_parser.t b/t/pod_parser.t new file mode 100644 index 0000000..d4ebcdc --- /dev/null +++ b/t/pod_parser.t @@ -0,0 +1,137 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 14; + +blib_load('Module::Build::PodParser'); + +######################### + +{ + package IO::StringBased; + + sub TIEHANDLE { + my ($class, $string) = @_; + return bless { + data => [ map "$_\n", split /\n/, $string], + }, $class; + } + + sub READLINE { + shift @{ shift()->{data} }; + } +} + +local *FH; +tie *FH, 'IO::StringBased', <<'EOF'; +=head1 NAME + +Foo::Bar - Perl extension for blah blah blah + +=head1 AUTHOR + +C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004. + +Home page: http://example.com/~eh/ + +=cut +EOF + + +my $pp = Module::Build::PodParser->new(fh => \*FH); +ok $pp, 'object created'; + +is $pp->get_author->[0], 'C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.', 'author'; +is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract'; + + +{ + # Try again without a valid author spec + untie *FH; + tie *FH, 'IO::StringBased', <<'EOF'; +=head1 NAME + +Foo::Bar - Perl extension for blah blah blah + +=cut +EOF + + my $pp = Module::Build::PodParser->new(fh => \*FH); + ok $pp, 'object created'; + + is_deeply $pp->get_author, [], 'author'; + is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract'; +} + + +{ + # Try again with mixed-case =head1s. + untie *FH; + tie *FH, 'IO::StringBased', <<'EOF'; +=head1 Name + +Foo::Bar - Perl extension for blah blah blah + +=head1 Author + +C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004. + +Home page: http://example.com/~eh/ + +=cut +EOF + + my $pp = Module::Build::PodParser->new(fh => \*FH); + ok $pp, 'object created'; + + is $pp->get_author->[0], 'C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.', 'author'; + is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract'; +} + + +{ + # Now with C<Module::Name> + untie *FH; + tie *FH, 'IO::StringBased', <<'EOF'; +=head1 Name + +C<Foo::Bar> - Perl extension for blah blah blah + +=head1 Author + +C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004. + +Home page: http://example.com/~eh/ + +=cut +EOF + + my $pp = Module::Build::PodParser->new(fh => \*FH); + ok $pp, 'object created'; + + is $pp->get_author->[0], 'C<Foo::Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004.', 'author'; + is $pp->get_abstract, 'Perl extension for blah blah blah', 'abstract'; +} + +{ +local *FH; +tie *FH, 'IO::StringBased', <<'EOF'; +=head1 NAME + +Foo_Bar - Perl extension for eating pie + +=head1 AUTHOR + +C<Foo_Bar> was written by Engelbert Humperdinck I<E<lt>eh@example.comE<gt>> in 2004. + +Home page: http://example.com/~eh/ + +=cut +EOF + + + my $pp = Module::Build::PodParser->new(fh => \*FH); + ok $pp, 'object created'; + is $pp->get_abstract, 'Perl extension for eating pie', 'abstract'; +} @@ -0,0 +1,223 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use Config; + +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); +my $PPM_support = Module::Build::ConfigData->feature('PPM_support'); +my $manpage_support = Module::Build::ConfigData->feature('manpage_support'); +my $HTML_support = Module::Build::ConfigData->feature('HTML_support'); + +my $tmp; + +{ + my ($have_c_compiler, $tmp_exec) = check_compiler(); + if ( ! $have_c_compiler ) { + plan skip_all => 'No compiler found'; + } elsif ( ! $PPM_support ) { + plan skip_all => 'PPM support modules not installed'; + } elsif ( !$Config{usedl} ) { + plan skip_all => 'Perl not compiled for dynamic loading'; + } elsif ( ! $HTML_support ) { + plan skip_all => "HTML support not installed"; + } elsif ( ! eval {require Archive::Tar} ) { + plan skip_all => "Archive::Tar not installed to read archives."; + } elsif ( ! eval {IO::Zlib->VERSION(1.01)} ) { + plan skip_all => "IO::Zlib 1.01 required to read compressed archives."; + } elsif ( $^O eq 'VMS' ) { + plan skip_all => "Needs porting work on VMS"; + } else { + plan tests => 12; + } + require Cwd; + $tmp = MBTest->tmpdir( $tmp_exec ? () : (DIR => Cwd::cwd) ); +} + + +use DistGen; +my $dist = DistGen->new( dir => $tmp, xs => 1 ); +$dist->add_file( 'hello', <<'---' ); +#!perl -w +print "Hello, World!\n"; +__END__ + +=pod + +=head1 NAME + +hello + +=head1 DESCRIPTION + +Says "Hello" + +=cut +--- +$dist->change_build_pl +({ + module_name => $dist->name, + license => 'perl', + scripts => [ 'hello' ], +}); +$dist->regen; + +$dist->chdir_in; + +use File::Spec::Functions qw(catdir); + +my @installstyle = qw(lib perl5); +my $mb = Module::Build->new_from_context( + verbose => 0, + quiet => 1, + + installdirs => 'site', + config => { + manpage_reset(), html_reset(), + ( $manpage_support ? + ( installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'), + installsiteman3dir => catdir($tmp, 'site', 'man', 'man3') ) : () ), + ( $HTML_support ? + ( installsitehtml1dir => catdir($tmp, 'site', 'html'), + installsitehtml3dir => catdir($tmp, 'site', 'html') ) : () ), + }, + html_links => 0, +); + + + +$mb->dispatch('ppd', args => {codebase => '/path/to/codebase-xs'}); + +(my $dist_filename = $dist->name) =~ s/::/-/g; +my $ppd = slurp($dist_filename . '.ppd'); + +my $perl_version = Module::Build::PPMMaker->_ppd_version($mb->perl_version); +my $varchname = Module::Build::PPMMaker->_varchname($mb->config); + +# This test is quite a hack since with XML you don't really want to +# do a strict string comparison, but absent an XML parser it's the +# best we can do. +is $ppd, <<"---"; +<SOFTPKG NAME="$dist_filename" VERSION="0.01"> + <ABSTRACT>Perl extension for blah blah blah</ABSTRACT> + <AUTHOR>A. U. Thor, a.u.thor\@a.galaxy.far.far.away</AUTHOR> + <IMPLEMENTATION> + <ARCHITECTURE NAME="$varchname" /> + <CODEBASE HREF="/path/to/codebase-xs" /> + </IMPLEMENTATION> +</SOFTPKG> +--- + + + +$mb->dispatch('ppmdist'); +is $@, ''; + +my $tar = Archive::Tar->new; + +my $tarfile = $mb->ppm_name . '.tar.gz'; +$tar->read( $tarfile, 1 ); + +my $files = { map { $_ => 1 } $tar->list_files }; + +my $fname = 'Simple'; +$fname = DynaLoader::mod2fname([$fname]) if defined &DynaLoader::mod2fname; +exists_ok($files, "blib/arch/auto/Simple/$fname." . $mb->config('dlext')); +exists_ok($files, 'blib/lib/Simple.pm'); +exists_ok($files, 'blib/script/hello'); + +SKIP: { + skip( "manpage_support not enabled.", 2 ) unless $manpage_support; + + exists_ok($files, 'blib/man3/Simple.' . $mb->config('man3ext')); + exists_ok($files, 'blib/man1/hello.' . $mb->config('man1ext')); +} + +SKIP: { + skip( "HTML_support not enabled.", 2 ) unless $HTML_support; + + exists_ok($files, 'blib/html/site/lib/Simple.html'); + exists_ok($files, 'blib/html/bin/hello.html'); +} + +$tar->clear; +undef( $tar ); + +$mb->dispatch('realclean'); +$dist->clean; + + +SKIP: { + skip( "HTML_support not enabled.", 3 ) unless $HTML_support; + + # Make sure html documents are generated for the ppm distro even when + # they would not be built during a normal build. + $mb = Module::Build->new_from_context( + verbose => 0, + quiet => 1, + + installdirs => 'site', + config => { + html_reset(), + installsiteman1dir => catdir($tmp, 'site', 'man', 'man1'), + installsiteman3dir => catdir($tmp, 'site', 'man', 'man3'), + }, + html_links => 0, + ); + + $mb->dispatch('ppmdist'); + is $@, ''; + + $tar = Archive::Tar->new; + $tar->read( $tarfile, 1 ); + + $files = {map { $_ => 1 } $tar->list_files}; + + exists_ok($files, 'blib/html/site/lib/Simple.html'); + exists_ok($files, 'blib/html/bin/hello.html'); + + $tar->clear; + + $mb->dispatch('realclean'); + $dist->clean; +} + + +######################################## + +sub exists_ok { + my $files = shift; + my $file = shift; + local $Test::Builder::Level = $Test::Builder::Level + 1; + ok exists( $files->{$file} ) && $files->{$file}, $file; +} + +# A hash of all Config.pm settings related to installing +# manpages with values set to an empty string. +sub manpage_reset { + return ( + installman1dir => '', + installman3dir => '', + installsiteman1dir => '', + installsiteman3dir => '', + installvendorman1dir => '', + installvendorman3dir => '', + ); +} + +# A hash of all Config.pm settings related to installing +# html documents with values set to an empty string. +sub html_reset { + return ( + installhtmldir => '', + installhtml1dir => '', + installhtml3dir => '', + installsitehtml1dir => '', + installsitehtml3dir => '', + installvendorhtml1dir => '', + installvendorhtml3dir => '', + ); +} + diff --git a/t/properties/dist_suffix.t b/t/properties/dist_suffix.t new file mode 100644 index 0000000..aaee112 --- /dev/null +++ b/t/properties/dist_suffix.t @@ -0,0 +1,33 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 2; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +#--------------------------------------------------------------------------# +# Create test distribution +#--------------------------------------------------------------------------# + +use DistGen; +my $dist = DistGen->new( name => 'Simple::Name' ); + +$dist->change_build_pl( + module_name => 'Simple::Name', + dist_suffix => 'SUFFIX', +)->regen; + +$dist->chdir_in; + +my $mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_dir, "Simple-Name-0.01-SUFFIX", + "dist_suffix set correctly" +); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/properties/license.t b/t/properties/license.t new file mode 100644 index 0000000..bb7247e --- /dev/null +++ b/t/properties/license.t @@ -0,0 +1,66 @@ +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan 'no_plan'; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +#--------------------------------------------------------------------------# +# Create test distribution +#--------------------------------------------------------------------------# + +{ + my $dist = DistGen->new( + name => 'Simple::Name', + version => '0.01', + license => 'perl' + ); + + $dist->regen; + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->license, 'perl', + "license 'perl' is valid" + ); + + my $meta = $mb->get_metadata( fatal => 0 ); + + is_deeply( $meta->{license} => [ 'perl_5' ], "META license will be 'perl'" ); + is_deeply( $meta->{resources}{license}, [ "http://dev.perl.org/licenses/" ], + "META license URL is correct" + ); + +} + +{ + my $dist = DistGen->new( + name => 'Simple::Name', + version => '0.01', + license => 'VaporWare' + ); + + $dist->regen; + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->license, 'VaporWare', + "license 'VaporWare' is valid" + ); + + my $meta = $mb->get_metadata( fatal => 0 ); + + is_deeply( $meta->{license} => [ 'unrestricted' ], "META license will be 'unrestricted'" ); + is_deeply( $meta->{resources}{license}, [ "http://example.com/vaporware/" ], + "META license URL is correct" + ); + +} + +# Test with alpha number +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/properties/module_name.t b/t/properties/module_name.t new file mode 100644 index 0000000..69aec8e --- /dev/null +++ b/t/properties/module_name.t @@ -0,0 +1,57 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 4; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +my $dist; + +#--------------------------------------------------------------------------# +# try getting module_name from dist_name +#--------------------------------------------------------------------------# + +$dist = DistGen->new( + name => "Not::So::Simple", + distdir => 'Random-Name', +)->chdir_in; + +$dist->change_build_pl( + dist_name => 'Not-So-Simple', + dist_version => 1, +)->regen; + +my $mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); +is( $mb->module_name, "Not::So::Simple", + "module_name guessed from dist_name" +); + +#--------------------------------------------------------------------------# +# Try getting module_name from dist_version_from +#--------------------------------------------------------------------------# + +$dist->add_file( 'lib/Simple/Name.pm', << 'END_PACKAGE' ); +package Simple::Name; +our $VERSION = 1.23; +1; +END_PACKAGE + +$dist->change_build_pl( + dist_name => 'Random-Name', + dist_version_from => 'lib/Simple/Name.pm', + dist_abstract => "Don't complain about missing abstract", +)->regen( clean => 1 ); + +$mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); +is( $mb->module_name, "Simple::Name", + "module_name guessed from dist_version_from" +); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/properties/needs_compiler.t b/t/properties/needs_compiler.t new file mode 100644 index 0000000..f616dfc --- /dev/null +++ b/t/properties/needs_compiler.t @@ -0,0 +1,125 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 19; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +my $dist = DistGen->new->regen->chdir_in; + +# get a Module::Build object and test with it +my $mb; +stderr_of(sub { + ok( $mb = $dist->new_from_context, "Default Build.PL" ); +}); + +ok( ! $mb->needs_compiler, "needs_compiler is false" ); +ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder is not in build_requires" +); + +#--------------------------------------------------------------------------# +# try with c_source +#--------------------------------------------------------------------------# +$dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + c_source => 'src', +}); +$dist->regen; +stderr_of(sub { + ok( $mb = $dist->new_from_context, + "Build.PL with c_source" + ); +}); +is( $mb->c_source, 'src', "c_source is set" ); +ok( $mb->needs_compiler, "needs_compiler is true" ); +ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder was added to build_requires" +); + +#--------------------------------------------------------------------------# +# try with xs files +#--------------------------------------------------------------------------# +$dist = DistGen->new(dir => 'MBTest', xs => 1); +$dist->regen; +$dist->chdir_in; + +stderr_of(sub { + ok( $mb = $dist->new_from_context, + "Build.PL with xs files" + ); +}); +ok( $mb->needs_compiler, "needs_compiler is true" ); +ok( exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder was added to build_requires" +); + +#--------------------------------------------------------------------------# +# force needs_compiler off, despite xs modules +#--------------------------------------------------------------------------# + +$dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + needs_compiler => 0, +}); +$dist->regen; + +stderr_of(sub { + ok( $mb = $dist->new_from_context , + "Build.PL with xs files, but needs_compiler => 0" + ); +}); +is( $mb->needs_compiler, 0, "needs_compiler is false" ); +ok( ! exists $mb->{properties}{build_requires}{'ExtUtils::CBuilder'}, + "ExtUtils::CBuilder is not in build_requires" +); + +#--------------------------------------------------------------------------# +# don't override specific EU::CBuilder build_requires +#--------------------------------------------------------------------------# + +$dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + build_requires => { 'ExtUtils::CBuilder' => 0.2 }, +}); +$dist->regen; + +stderr_of(sub { + ok( $mb = $dist->new_from_context , + "Build.PL with xs files, build_requires EU::CB 0.2" + ); +}); +ok( $mb->needs_compiler, "needs_compiler is true" ); +is( $mb->build_requires->{'ExtUtils::CBuilder'}, 0.2, + "build_requires for ExtUtils::CBuilder is correct version" +); + +#--------------------------------------------------------------------------# +# falsify compiler and test error handling +#--------------------------------------------------------------------------# + +# clear $ENV{CC} so we are sure to fail to find our fake compiler :-) +local $ENV{CC}; + +my $err = stderr_of( sub { + $mb = $dist->new_from_context( config => { cc => "adfasdfadjdjk" } ) +}); +ok( $mb, "Build.PL while hiding compiler" ); +like( $err, qr/no compiler detected/, + "hidden compiler resulted in warning message during Build.PL" +); +eval { $mb->dispatch('build') }; +like( $@, qr/no compiler detected/, + "hidden compiler resulted in fatal message during Build" +); + + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/properties/release_status.t b/t/properties/release_status.t new file mode 100644 index 0000000..45c7f33 --- /dev/null +++ b/t/properties/release_status.t @@ -0,0 +1,204 @@ +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +if ( $] lt 5.008001 ) { + plan skip_all => "dotted-version numbers are buggy before 5.8.1"; +} else { + plan 'no_plan'; +} + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +#--------------------------------------------------------------------------# +# Create test distribution +#--------------------------------------------------------------------------# + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => '0.01' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->release_status, "stable", + "regular version has release_status 'stable'" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => 'v1.2.3' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->release_status, "stable", + "dotted-decimal version has release_status 'stable'" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => q{'0.01_01'} ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->release_status, "testing", + "alpha version has release_status 'testing'" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => 'v1.2.3_1' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->release_status, "testing", + "dotted alpha version has release_status 'testing'" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => q{'0.01_01'} ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + release_status => 'unstable', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->release_status, "unstable", + "explicit 'unstable' keeps release_status 'unstable'" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => '0.01' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + release_status => 'testing', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->dist_suffix, "TRIAL", + "regular version marked 'testing' gets 'TRIAL' suffix" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => 'v1.2.3' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + release_status => 'testing', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->dist_suffix, "TRIAL", + "dotted version marked 'testing' gets 'TRIAL' suffix" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => '0.01' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + release_status => 'unstable', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->dist_suffix, "TRIAL", + "regular version marked 'unstable' gets 'TRIAL' suffix" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => '0.01' ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + release_status => 'beta', + )->regen; + + $dist->chdir_in; + + my $output = stdout_stderr_of sub { $dist->run_build_pl() }; + like( $output, qr/Illegal value 'beta' for release_status/i, + "Got error message for illegal release_status" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => q{'0.01_01'} ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + release_status => 'stable', + )->regen; + + $dist->chdir_in; + + my $output = stdout_stderr_of sub { $dist->run_build_pl() }; + like( $output, qr/Illegal value 'stable' with version '0.01_01'/i, + "Got error message for illegal 'stable' with alpha version" + ); +} + +{ + my $dist = DistGen->new( name => 'Simple::Name', version => q{'0.01_01'} ); + + $dist->change_build_pl( + module_name => 'Simple::Name', + dist_version => '1.23beta1', + )->regen; + + $dist->chdir_in; + + my $mb = $dist->new_from_context(); + isa_ok( $mb, "Module::Build" ); + is( $mb->dist_suffix, "", + "non-standard dist_version does not get a suffix" + ); + is( $mb->release_status, "stable", + "non-standard dist_version defaults to stable release_status" + ); +} + +# Test with alpha number +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/properties/requires.t b/t/properties/requires.t new file mode 100644 index 0000000..6511e80 --- /dev/null +++ b/t/properties/requires.t @@ -0,0 +1,54 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest; +use DistGen; + +plan tests => 4; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +my ($dist, $mb, $prereqs); + +#--------------------------------------------------------------------------# +# try undefined prereq version +#--------------------------------------------------------------------------# + +$dist = DistGen->new( name => 'Simple::Requires' ); + +$dist->change_build_pl( + module_name => 'Simple::Requires', + requires => { + 'File::Basename' => undef, + }, +)->regen; + +$dist->chdir_in; + +$mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); + +$prereqs = $mb->_normalize_prereqs; +is($prereqs->{runtime}{requires}{'File::Basename'}, 0, "undef prereq converted to 0"); + +#--------------------------------------------------------------------------# +# try empty string prereq version +#--------------------------------------------------------------------------# + +$dist->change_build_pl( + module_name => 'Simple::Requires', + requires => { + 'File::Basename' => '', + }, +)->regen; + +$mb = $dist->new_from_context(); +isa_ok( $mb, "Module::Build" ); + +$prereqs = $mb->_normalize_prereqs; +is($prereqs->{runtime}{requires}{'File::Basename'}, 0, "empty string prereq converted to 0"); + + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/properties/share_dir.t b/t/properties/share_dir.t new file mode 100644 index 0000000..f1cda13 --- /dev/null +++ b/t/properties/share_dir.t @@ -0,0 +1,257 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use File::Spec::Functions qw/catdir catfile/; + +#--------------------------------------------------------------------------# +# Begin testing +#--------------------------------------------------------------------------# + +plan tests => 23; + +blib_load('Module::Build'); + +#--------------------------------------------------------------------------# +# Create test distribution +#--------------------------------------------------------------------------# + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp, name => 'Simple::Share' ); +$dist->regen; +$dist->chdir_in; + +#--------------------------------------------------------------------------# +# Test setting 'share_dir' +#--------------------------------------------------------------------------# + +my $mb = $dist->new_from_context; + +# Test without a 'share' dir +ok( $mb, "Created Module::Build object" ); +is( $mb->share_dir, undef, + "default share_dir undef if no 'share' dir exists" +); +ok( ! exists $mb->{properties}{requires}{'File::ShareDir'}, + "File::ShareDir not added to 'requires'" +); + +# Add 'share' dir and an 'other' dir and content +$dist->add_file('share/foo.txt',<< '---'); +This is foo.txt +--- +$dist->add_file('share/subdir/share/anotherbar.txt',<< '---'); +This is anotherbar.txt in a subdir - test for a bug in M::B 0.38 when full path contains 'share/.../*share/...' subdir +--- +$dist->add_file('share/subdir/whatever/anotherfoo.txt',<< '---'); +This is anotherfoo.txt in a subdir - this shoud work on M::B 0.38 +--- +$dist->add_file('other/share/bar.txt',<< '---'); +This is bar.txt +--- +$dist->regen; +ok( -e catfile(qw/share foo.txt/), "Created 'share' directory" ); +ok( -d catfile(qw/share subdir share/), "Created 'share/subdir/share' directory" ); +ok( -d catfile(qw/share subdir whatever/), "Created 'share/subdir/whatever' directory" ); +ok( -e catfile(qw/other share bar.txt/), "Created 'other/share' directory" ); + +# Check default when share_dir is not given +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is( $mb->share_dir, undef, + "Default share_dir is undef even if 'share' exists" +); +ok( ! exists $mb->{properties}{requires}{'File::ShareDir'}, + "File::ShareDir not added to 'requires'" +); + + +# share_dir set to scalar +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => 'share', + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Scalar share_dir set as dist-type share" +); + +# share_dir set to arrayref +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => [ 'share' ], + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Arrayref share_dir set as dist-type share" +); + +# share_dir set to hashref w scalar +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { dist => 'share' }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Hashref share_dir w/ scalar dist set as dist-type share" +); + +# share_dir set to hashref w array +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { dist => [ 'share' ] }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, { dist => [ 'share' ] }, + "Hashref share_dir w/ arrayref dist set as dist-type share" +); + +# Generate a module sharedir (scalar) +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { + dist => 'share', + module => { $dist->name => 'other/share' }, + }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, + { dist => [ 'share' ], + module => { $dist->name => ['other/share'] }, + }, + "Hashref share_dir w/ both dist and module shares (scalar-form)" +); + +# Generate a module sharedir (array) +$dist->change_build_pl( + { + module_name => $dist->name, + license => 'perl', + share_dir => { + dist => [ 'share' ], + module => { $dist->name => ['other/share'] }, + }, + } +); +$dist->regen; +stdout_stderr_of( sub { $mb = $dist->new_from_context }); +is_deeply( $mb->share_dir, + { dist => [ 'share' ], + module => { $dist->name => ['other/share'] }, + }, + "Hashref share_dir w/ both dist and module shares (array-form)" +); + +#--------------------------------------------------------------------------# +# test constructing to/from mapping +#--------------------------------------------------------------------------# + +is_deeply( $mb->_find_share_dir_files, + { + "share/foo.txt" => "dist/Simple-Share/foo.txt", + "share/subdir/share/anotherbar.txt" => "dist/Simple-Share/subdir/share/anotherbar.txt", + "share/subdir/whatever/anotherfoo.txt" => "dist/Simple-Share/subdir/whatever/anotherfoo.txt", + "other/share/bar.txt" => "module/Simple-Share/bar.txt", + }, + "share_dir filemap for copying to lib complete" +); + +#--------------------------------------------------------------------------# +# test moving files to blib +#--------------------------------------------------------------------------# + +$mb->dispatch('build'); + +ok( -d 'blib', "Build ran and blib exists" ); +ok( -d 'blib/lib/auto/share', "blib/lib/auto/share exists" ); + +my $share_list = Module::Build->rscan_dir('blib/lib/auto/share', sub {-f}); + +SKIP: +{ + +skip 'filename case not necessarily preserved', 1 if $^O eq 'VMS'; + +is_deeply( + [ sort @$share_list ], [ + 'blib/lib/auto/share/dist/Simple-Share/foo.txt', + 'blib/lib/auto/share/dist/Simple-Share/subdir/share/anotherbar.txt', + 'blib/lib/auto/share/dist/Simple-Share/subdir/whatever/anotherfoo.txt', + 'blib/lib/auto/share/module/Simple-Share/bar.txt', + ], + "share_dir files copied to blib" +); + +} + +#--------------------------------------------------------------------------# +# test installing +#--------------------------------------------------------------------------# + +my $temp_install = 'temp_install'; +mkdir $temp_install; +ok( -d $temp_install, "temp install dir created" ); + +$mb->install_base($temp_install); +stdout_of( sub { $mb->dispatch('install') } ); + +$share_list = Module::Build->rscan_dir( + "$temp_install/lib/perl5/auto/share", sub {-f} +); + +SKIP: +{ + +skip 'filename case not necessarily preserved', 1 if $^O eq 'VMS'; + +is_deeply( + [ sort @$share_list ], [ + "$temp_install/lib/perl5/auto/share/dist/Simple-Share/foo.txt", + "$temp_install/lib/perl5/auto/share/dist/Simple-Share/subdir/share/anotherbar.txt", + "$temp_install/lib/perl5/auto/share/dist/Simple-Share/subdir/whatever/anotherfoo.txt", + "$temp_install/lib/perl5/auto/share/module/Simple-Share/bar.txt", + ], + "share_dir files correctly installed" +); + +} + +#--------------------------------------------------------------------------# +# test with File::ShareDir +#--------------------------------------------------------------------------# + +SKIP: { + eval { require File::ShareDir; File::ShareDir->VERSION(1.00) }; + skip "needs File::ShareDir 1.00", 2 if $@; + + unshift @INC, File::Spec->catdir($temp_install, qw/lib perl5/); + require Simple::Share; + + eval {File::ShareDir::dist_file('Simple-Share','foo.txt') }; + is( $@, q{}, "Found shared dist file" ); + + eval {File::ShareDir::module_file('Simple::Share','bar.txt') }; + is( $@, q{}, "Found shared module file" ); +} diff --git a/t/resume.t b/t/resume.t new file mode 100644 index 0000000..add123d --- /dev/null +++ b/t/resume.t @@ -0,0 +1,43 @@ +use strict; +use lib 't/lib'; +use MBTest; +plan tests => 3; # or 'no_plan' +use DistGen; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in; +$dist->add_file('mylib/MBUtil.pm', << "---"); +package MBUtil; +sub foo { 42 } +1; +--- + +$dist->add_file('Build.PL', << "---"); +use strict; +use lib 'mylib'; +use MBUtil; +use Module::Build; + +die unless MBUtil::foo() == 42; + +my \$builder = Module::Build->new( +module_name => '$dist->{name}', +license => 'perl', +); + +\$builder->create_build_script(); +--- + +$dist->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); +ok( ( grep { /mylib/ } @INC ), "resume added \@INC addition to \@INC"); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/runthrough.t b/t/runthrough.t new file mode 100644 index 0000000..1f6730e --- /dev/null +++ b/t/runthrough.t @@ -0,0 +1,201 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 29; + +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +######################### + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new(); +$dist->change_build_pl +({ + module_name => 'Simple', + scripts => [ 'script' ], + license => 'perl', + requires => { 'File::Spec' => 0 }, +}); + +$dist->add_file( 'MANIFEST.SKIP', <<'---' ); +^MYMETA.yml$ +--- +$dist->add_file( 'script', <<'---' ); +#!perl -w +print "Hello, World!\n"; +--- +$dist->add_file( 'lib/Simple/Script.PL', <<'---' ); +#!perl -w + +my $filename = shift; +open FH, "> $filename" or die "Can't create $filename: $!"; +print FH "Contents: $filename\n"; +close FH; +--- +$dist->regen; + +$dist->chdir_in; + + +######################### + +my $mb = Module::Build->new_from_context; +ok $mb; +is $mb->license, 'perl'; + +# Make sure cleanup files added before create_build_script() get respected +$mb->add_to_cleanup('before_script'); + +eval {$mb->create_build_script}; +is $@, ''; +ok -e $mb->build_script; + +my $dist_dir = 'Simple-0.01'; + +# VMS in traditional mode needs the $dist_dir name to not have a '.' in it +# as this is a directory delimiter. In extended character set mode the dot +# is permitted for Unix format file specifications. +if ($^O eq 'VMS') { + my $Is_VMS_noefs = 1; + my $vms_efs = 0; + if (eval 'require VMS::Feature') { + $vms_efs = VMS::Feature::current("efs_charset"); + } else { + my $efs_charset = $ENV{'DECC$EFS_CHARSET'} || ''; + $vms_efs = $efs_charset =~ /^[ET1]/i; + } + $Is_VMS_noefs = 0 if $vms_efs; + if ($Is_VMS_noefs) { + $dist_dir = 'Simple-0_01'; + } +} + +is $mb->dist_dir, $dist_dir; + +# The 'cleanup' file doesn't exist yet +ok grep {$_ eq 'before_script'} $mb->cleanup; + +$mb->add_to_cleanup('save_out'); + +# The 'cleanup' file now exists +ok grep {$_ eq 'before_script'} $mb->cleanup; +ok grep {$_ eq 'save_out' } $mb->cleanup; + +{ + # Make sure verbose=>1 works + my $all_ok = 1; + my $output = eval { + stdout_of( sub { $mb->dispatch('test', verbose => 1) } ) + }; + $all_ok &&= is($@, ''); + $all_ok &&= like($output, qr/all tests successful/i); + + # This is the output of lib/Simple/Script.PL + $all_ok &&= ok(-e $mb->localize_file_path('lib/Simple/Script')); + + unless ($all_ok) { + # We use diag() so Test::Harness doesn't get confused. + diag("vvvvvvvvvvvvvvvvvvvvv Simple/t/basic.t output vvvvvvvvvvvvvvvvvvvvv"); + diag($output); + diag("^^^^^^^^^^^^^^^^^^^^^ Simple/t/basic.t output ^^^^^^^^^^^^^^^^^^^^^"); + } +} + +{ + my $output = eval { + stdout_stderr_of( sub { $mb->dispatch('disttest') } ) + }; + is $@, ''; + + # After a test, the distdir should contain a blib/ directory + ok -e File::Spec->catdir('Simple-0.01', 'blib'); + + stdout_stderr_of ( sub { eval {$mb->dispatch('distdir')} } ); + is $@, ''; + + # The 'distdir' should contain a lib/ directory + ok -e File::Spec->catdir('Simple-0.01', 'lib'); + + # The freshly run 'distdir' should never contain a blib/ directory, or + # else it could get into the tarball + ok ! -e File::Spec->catdir('Simple-0.01', 'blib'); + + # Make sure all of the above was done by the new version of Module::Build + open(my $fh, '<', File::Spec->catfile($dist->dirname, 'META.yml')); + my $contents = do {local $/; <$fh>}; + $contents =~ /Module::Build version ([0-9_.]+)/m; + cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION; + + SKIP: { + skip( "Archive::Tar 1.08+ not installed", 1 ) + unless eval { require Archive::Tar && Archive::Tar->VERSION(1.08); 1 }; + $mb->add_to_cleanup($mb->dist_dir . ".tar.gz"); + eval {$mb->dispatch('dist')}; + is $@, ''; + } + +} + +{ + # Make sure the 'script' file was recognized as a script. + my $scripts = $mb->script_files; + ok $scripts->{script}; + + # Check that a shebang line is rewritten + my $blib_script = File::Spec->catfile( qw( blib script script ) ); + ok -e $blib_script; + + SKIP: { + skip("We do not rewrite shebang on VMS", 1) if $^O eq 'VMS'; + open(my $fh, '<', $blib_script); + my $first_line = <$fh>; + isnt $first_line, "#!perl -w\n", "should rewrite the shebang line"; + } +} + + +eval {$mb->dispatch('realclean')}; +is $@, ''; + +ok ! -e $mb->build_script; +ok ! -e $mb->config_dir; +ok ! -e $mb->dist_dir; + +SKIP: { + skip( 'Windows-only test', 4 ) unless $^O =~ /^MSWin/; + + my $script_data = <<'---'; +@echo off +echo Hello, World! +--- + + $dist = DistGen->new(); + $dist->change_build_pl({ + module_name => 'Simple', + scripts => [ 'bin/script.bat' ], + license => 'perl', + }); + + $dist->add_file( 'bin/script.bat', $script_data ); + + $dist->regen; + $dist->chdir_in; + + $mb = Module::Build->new_from_context; + ok $mb; + + eval{ $mb->dispatch('build') }; + is $@, ''; + + my $script_file = File::Spec->catfile( qw(blib script), 'script.bat' ); + ok -f $script_file, "Native batch file copied to 'scripts'"; + + my $out = slurp( $script_file ); + is $out, $script_data, ' unmodified by pl2bat'; + +} + diff --git a/t/sample.t b/t/sample.t new file mode 100644 index 0000000..d83bc56 --- /dev/null +++ b/t/sample.t @@ -0,0 +1,20 @@ +# sample.t -- a sample test file for Module::Build + +use strict; +use lib 't/lib'; +use MBTest tests => 2; # or 'no_plan' +use DistGen; + +# Ensure any Module::Build modules are loaded from correct directory +blib_load('Module::Build'); + +# create dist object in a temp directory +# enter the directory and generate the skeleton files +my $dist = DistGen->new->chdir_in->regen; + +# get a Module::Build object and test with it +my $mb = $dist->new_from_context(); # quiet by default +isa_ok( $mb, "Module::Build" ); +is( $mb->dist_name, "Simple", "dist_name is 'Simple'" ); + +# vim:ts=2:sw=2:et:sta:sts=2 diff --git a/t/script_dist.t b/t/script_dist.t new file mode 100644 index 0000000..fa02b49 --- /dev/null +++ b/t/script_dist.t @@ -0,0 +1,79 @@ +#!/usr/bin/perl -w +# -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*- +# vim:ts=8:sw=2:et:sta:sts=2 + +use strict; +use lib 't/lib'; +use MBTest 'no_plan'; + +use DistGen qw(undent); +use CPAN::Meta::YAML; + +blib_load('Module::Build'); +blib_load('Module::Build::ConfigData'); + +# XXX DistGen shouldn't be assuming module-ness? +my $dist = DistGen->new(dir => MBTest->tmpdir); +$dist->add_file('bin/foo', undent(<<' ---')); + #!/usr/bin/perl + + package bin::foo; + $VERSION = 0.01; + + =head1 NAME + + foo - does stuff + + =head1 AUTHOR + + A. U. Thor, a.u.thor@a.galaxy.far.far.away + + =cut + + print "hello world\n"; + --- + +my %details = ( + dist_name => 'bin-foo', + dist_version_from => 'bin/foo', + dist_author => ['A. U. Thor, a.u.thor@a.galaxy.far.far.away'], + dist_version => '0.01', +); +my %meta_provides = ( + 'foo' => { + file => 'bin/foo', + version => '0.01', + } +); +$dist->change_build_pl({ + # TODO need to get all of this data out of the program itself + ! $ENV{EXTRA_TEST} ? ( + %details, meta_merge => { provides => \%meta_provides, }, + ) : (), + program_name => 'bin/foo', + license => 'perl', +}); + +# hmm... the old assumption of what a dist looks like is wrong here +$dist->remove_file('lib/Simple.pm'); $dist->regen; + +$dist->chdir_in; +rmdir('lib'); + +#system('konsole'); +my $mb = Module::Build->new_from_context; +ok($mb); +is($mb->program_name, 'bin/foo'); +is($mb->license, 'perl'); +is($mb->dist_name, 'bin-foo'); +is($mb->dist_version, '0.01'); +is_deeply($mb->dist_author, + ['A. U. Thor, a.u.thor@a.galaxy.far.far.away']); +my $result; +stdout_stderr_of( sub { $result = $mb->dispatch('distmeta') } ); +ok $result; + +my $yml = CPAN::Meta::YAML->read_string(slurp('META.yml'))->[0]; +is_deeply($yml->{provides}, \%meta_provides); + +$dist->chdir_original if $dist->did_chdir; diff --git a/t/signature.t b/t/signature.t new file mode 100644 index 0000000..48d97e4 --- /dev/null +++ b/t/signature.t @@ -0,0 +1,100 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; + +if ( have_module( 'Module::Signature' ) + && $INC{'Module/Signature.pm'} =~ m{t/lib/Module/Signature\.pm} +) { + plan tests => 12; +} else { + plan skip_all => "Mock Module::Signature not loadable"; +} + +blib_load('Module::Build'); + +######################### + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->change_build_pl +({ + module_name => $dist->name, + license => 'perl', + sign => 1, + auto_configure_requires => 0, + quiet => 1, +}); +$dist->regen; + +$dist->chdir_in; + +######################### + +my $mb = Module::Build->new_from_context; + +{ + eval {$mb->dispatch('distdir')}; + my $err = $@; + is $err, ''; + chdir( $mb->dist_dir ) or die "Can't chdir to '@{[$mb->dist_dir]}': $!"; + ok -e 'SIGNATURE'; + + $dist->chdir_in; +} + +{ + # Fake out Module::Signature and Module::Build - the first one to + # run should be distmeta. + my @run_order; + { + local $^W; # Skip 'redefined' warnings + local *Module::Signature::sign; + *Module::Signature::sign = sub { push @run_order, 'sign' }; + local *Module::Build::Base::ACTION_distmeta; + *Module::Build::Base::ACTION_distmeta = sub { push @run_order, 'distmeta' }; + eval { $mb->dispatch('distdir') }; + } + is $@, ''; + is $run_order[0], 'distmeta'; + is $run_order[1], 'sign'; +} + +eval { $mb->dispatch('realclean') }; +is $@, ''; + +{ + eval {$mb->dispatch('distdir', sign => 0 )}; + is $@, ''; + chdir( $mb->dist_dir ) or die "Can't chdir to '@{[$mb->dist_dir]}': $!"; + ok !-e 'SIGNATURE', './Build distdir --sign 0 does not sign'; +} + +eval { $mb->dispatch('realclean') }; +is $@, ''; + +$dist->chdir_in; + +{ + local @ARGV = '--sign=1'; + $dist->change_build_pl({ + module_name => $dist->name, + license => 'perl', + auto_configure_requires => 0, + quiet => 1, + }); + $dist->regen; + + my $mb = Module::Build->new_from_context; + is $mb->{properties}{sign}, 1; + + eval {$mb->dispatch('distdir')}; + my $err = $@; + is $err, ''; + chdir( $mb->dist_dir ) or die "Can't chdir to '@{[$mb->dist_dir]}': $!"; + ok -e 'SIGNATURE', 'Build.PL --sign=1 signs'; +} + diff --git a/t/test_file_exts.t b/t/test_file_exts.t new file mode 100644 index 0000000..5bb803c --- /dev/null +++ b/t/test_file_exts.t @@ -0,0 +1,41 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 3; +use DistGen; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; +my $dist = DistGen->new( dir => $tmp ); + +$dist->add_file('t/mytest.s', <<'---' ); +#!perl +use Test::More tests => 2; +ok(1, 'first mytest.s'); +ok(1, 'second mytest.s'); +--- + +$dist->regen; +$dist->chdir_in; + +######################### + +# So make sure that the test gets run with the alternate extension. +ok my $mb = Module::Build->new( + module_name => $dist->name, + test_file_exts => ['.s'], + quiet => 1, +), 'Construct build object with test_file_exts parameter'; + +$mb->add_to_cleanup('save_out'); +# Use uc() so we don't confuse the current test output +my $out = uc(stdout_of( + sub {$mb->dispatch('test', verbose => 1)} +)); + +like $out, qr/^OK 1 - FIRST MYTEST[.]S/m, 'Should see first test output'; +like $out, qr/^OK 2 - SECOND MYTEST[.]S/m, 'Should see second test output'; + +# vim:ts=4:sw=4:et:sta diff --git a/t/test_reqs.t b/t/test_reqs.t new file mode 100644 index 0000000..bd04f86 --- /dev/null +++ b/t/test_reqs.t @@ -0,0 +1,52 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use CPAN::Meta 2.110420; +use CPAN::Meta::YAML; +use Parse::CPAN::Meta 1.4401; +plan tests => 4; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->change_file('Build.PL', <<"---"); +use strict; +use Module::Build; + +my \$builder = Module::Build->new( + module_name => '$dist->{name}', + license => 'perl', + requires => { + 'File::Spec' => 0, + }, + test_requires => { + 'Test::More' => 0, + } +); + +\$builder->create_build_script(); +--- +$dist->regen; +$dist->chdir_in; +$dist->run_build_pl; +my $output = stdout_stderr_of sub { $dist->run_build('distmeta') }; + +for my $file ( qw/MYMETA META/ ) { + my $meta = Parse::CPAN::Meta->load_file($file.".json"); + is_deeply($meta->{prereqs}->{runtime},{ + requires => { + 'File::Spec' => '0', + } + }, "runtime prereqs in $file"); + is_deeply($meta->{prereqs}->{test},{ + requires => { + 'Test::More' => '0', + } + }, "test prereqs in $file"); +} + diff --git a/t/test_type.t b/t/test_type.t new file mode 100644 index 0000000..bdbf0cd --- /dev/null +++ b/t/test_type.t @@ -0,0 +1,74 @@ +#!/usr/bin/perl -w + +BEGIN { + if ($^O eq 'VMS') { + print '1..0 # Child test output confuses harness'; + exit; + } +} + +use strict; +use lib 't/lib'; +use MBTest tests => 7; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; + +my $dist = DistGen->new( dir => $tmp ); + + +$dist->add_file('t/special_ext.st', <<'---' ); +#!perl +use Test::More tests => 2; +ok(1, 'first test in special_ext'); +ok(1, 'second test in special_ext'); +--- + +$dist->regen; + +$dist->chdir_in; + +######################### + +# Here we make sure we can define an action that will test a particular type +$::x = 0; +my $mb = Module::Build->subclass( + code => q# + sub ACTION_testspecial { + $::x++; + shift->generic_test(type => 'special'); + } + # +)->new( + module_name => $dist->name, + test_types => { special => '.st' } +); + +ok $mb; + +$mb->dispatch('testspecial'); +is($::x, 1, "called once"); + + +$mb->add_to_cleanup('save_out'); +# Use uc() so we don't confuse the current test output +my $verbose_output = uc(stdout_of( + sub {$mb->dispatch('testspecial', verbose => 1)} +)); + +like($verbose_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m); +like($verbose_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m); + +is( $::x, 2, "called again"); + +my $output = uc(stdout_of( + sub {$mb->dispatch('testspecial', verbose => 0)} +)); +like($output, qr/\.\. ?OK/); + +is($::x, 3, "called a third time"); + +# vim:ts=4:sw=4:et:sta diff --git a/t/test_types.t b/t/test_types.t new file mode 100644 index 0000000..bcb58c4 --- /dev/null +++ b/t/test_types.t @@ -0,0 +1,174 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 25; + +blib_load('Module::Build'); + +use DistGen; + +my $dist = DistGen->new()->chdir_in; + +$dist->add_file('t/special_ext.st', <<'---'); +#!perl +use Test::More tests => 2; +ok(1, 'first test in special_ext'); +ok(1, 'second test in special_ext'); +--- + +$dist->add_file('t/another_ext.at', <<'---'); +#!perl +use Test::More tests => 2; +ok(1, 'first test in another_ext'); +ok(1, 'second test in another_ext'); +--- +$dist->add_file('t/foo.txt', <<'---'); +#!perl +use Test::More tests => 1; +ok 0, "don't run this non-test file"; +die "don't run this non-test file"; +--- + +$dist->regen; +######################### + +my $mb = Module::Build->subclass( + code => q# + sub ACTION_testspecial { + shift->generic_test(type => 'special'); + } + + sub ACTION_testanother { + shift->generic_test(type => 'another'); + } + # + )->new( + module_name => $dist->name, + test_types => { + special => '.st', + another => '.at', + }, + ); + + +ok $mb; + +my $special_output = uc(stdout_of( + sub {$mb->dispatch('testspecial', verbose => 1)} +)); + +like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'saw expected output from first test'); +like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'saw expected output from second test'); + +my $another_output = uc(stdout_of( + sub {$mb->dispatch('testanother', verbose => 1)} +)); + +ok($another_output, 'we have some test output'); + +like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m, + 'saw expected output from first test'); +like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m, + 'saw expected output from second test'); + + +my $all_output = uc(stdout_of( + sub {$mb->dispatch('testall', verbose => 1)} +)); + +0 and warn "\ntestall said >>>\n$all_output\n<<<\n"; + +like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); +like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); + +like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m); +like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m); + +# we get a third one from basic.t +is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 ); +is(scalar(@{[$all_output =~ m/OK/mg]}), 8 ); +is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}), 1); + +{ # once-again + +$dist->revert; + +$dist->add_file('t/foo/special.st', <<'---'); +#!perl +use Test::More tests => 2; +ok(1, 'first test in special_ext'); +ok(1, 'second test in special_ext'); +--- +$dist->add_file('t/foo/basic_foo.t', <<'---'); +use Test::More tests => 1; +use strict; use Simple; +ok 1; +--- +$dist->regen; + +my $mb = Module::Build->subclass( + code => q# + sub ACTION_testspecial { + shift->generic_test(type => 'special'); + } + + sub ACTION_testanother { + shift->generic_test(type => 'another'); + } + # + )->new( + recursive_test_files => 1, + module_name => $dist->name, + test_types => { + special => '.st', + another => '.at', + }, + ); + +ok $mb; + +my $special_output = uc(stdout_of( + sub {$mb->dispatch('testspecial', verbose => 1)} +)); + +like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'saw expected output from first test'); +like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'saw expected output from second test'); + +my $another_output = uc(stdout_of( + sub {$mb->dispatch('testanother', verbose => 1)} +)); + +ok($another_output, 'we have some test output'); + +like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m, + 'saw expected output from first test'); +like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m, + 'saw expected output from second test'); + + +my $all_output = uc(stdout_of( + sub {$mb->dispatch('testall', verbose => 1)} +)); + +like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); +like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); + +like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m); +like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m); + +# we get a third one from basic.t +is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 ); +is(scalar(@{[$all_output =~ m/(OK)/mg]}), 13 ); + +} # end once-again + +# vim:ts=4:sw=4:et:sta diff --git a/t/tilde.t b/t/tilde.t new file mode 100644 index 0000000..09673f6 --- /dev/null +++ b/t/tilde.t @@ -0,0 +1,114 @@ +#!/usr/bin/perl -w + +# Test ~ expansion from command line arguments. + +use strict; +use lib 't/lib'; +use MBTest tests => 16; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + + +sub run_sample { + my @args = @_; + + local $Test::Builder::Level = $Test::Builder::Level + 1; + + $dist->clean; + + my $mb; + stdout_of( sub { + $mb = Module::Build->new_from_context( @args ); + } ); + + return $mb; +} + + +my $p = 'install_base'; + +SKIP: { + my $home = $ENV{HOME} ? $ENV{HOME} : undef; + + if ($^O eq 'VMS') { + # Convert the path to UNIX format, trim off the trailing slash + $home = VMS::Filespec::unixify($home); + $home =~ s#/$##; + } + + unless (defined $home) { + my @info = eval { getpwuid $> }; + skip "No home directory for tilde-expansion tests", 15 if $@ + or !defined $info[7]; + $home = $info[7]; + } + + is( run_sample( $p => '~' )->$p(), $home ); + + is( run_sample( $p => '~/fooxzy' )->$p(), "$home/fooxzy" ); + + is( run_sample( $p => '~/ fooxzy')->$p(), "$home/ fooxzy" ); + + is( run_sample( $p => '~/fo o')->$p(), "$home/fo o" ); + + is( run_sample( $p => 'fooxzy~' )->$p(), 'fooxzy~' ); + + is( run_sample( prefix => '~' )->prefix, + $home ); + + # Test when HOME is different from getpwuid(), as in sudo. + { + local $ENV{HOME} = '/wibble/whomp'; + + is( run_sample( $p => '~' )->$p(), "/wibble/whomp" ); + } + + my $mb = run_sample( install_path => { html => '~/html', + lib => '~/lib' } + ); + is( $mb->install_destination('lib'), "$home/lib" ); + # 'html' is translated to 'binhtml' & 'libhtml' + is( $mb->install_destination('binhtml'), "$home/html" ); + is( $mb->install_destination('libhtml'), "$home/html" ); + + $mb = run_sample( install_path => { lib => '~/lib' } ); + is( $mb->install_destination('lib'), "$home/lib" ); + + $mb = run_sample( destdir => '~' ); + is( $mb->destdir, $home ); + + $mb->$p('~'); + is( $mb->$p(), '~', 'API does not expand tildes' ); + + skip "On OS/2 EMX all users are equal", 2 if $^O eq 'os2'; + is( run_sample( $p => '~~' )->$p(), '~~' ); + is( run_sample( $p => '~ fooxzy' )->$p(), '~ fooxzy' ); +} + +# Again, with named users +SKIP: { + my @info = eval { getpwuid $> }; + skip "No home directory for tilde-expansion tests", 1 if $@ + or !defined $info[7] or !defined $info[0]; + my ($me, $home) = @info[0,7]; + + if ($^O eq 'VMS') { + # Convert the path to UNIX format and trim off the trailing slash. + # Also, the fake module we're in has mangled $ENV{HOME} for its own + # purposes; getpwuid doesn't know about that but _detildefy does. + $home = VMS::Filespec::unixify($ENV{HOME}); + $home =~ s#/$##; + } + my $expected = "$home/fooxzy"; + + like( run_sample( $p => "~$me/fooxzy")->$p(), qr(\Q$expected\E)i ); +} + diff --git a/t/unit_run_test_harness.t b/t/unit_run_test_harness.t new file mode 100644 index 0000000..e6a7f53 --- /dev/null +++ b/t/unit_run_test_harness.t @@ -0,0 +1,73 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 9; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +$dist->chdir_in; + +######################### + + +# make sure Test::Harness loaded before we define Test::Harness::runtests otherwise we'll +# get another redefined warning inside Test::Harness::runtests +use Test::Harness; + +{ + package MB::Subclass; + use base qw(Module::Build); + sub harness_switches { return } +} + +{ + local $SIG{__WARN__} = sub { die "Termination after a warning: $_[0]"}; + my $mock1 = { A => 1 }; + my $mock2 = { B => 2 }; + + no warnings qw[redefine once]; + + # This runs run_test_harness with Test::Harness::switches = undef and harness_switches() returning empty list, + # ensure there are no warnings, and output is empty too + { + my $mb = MB::Subclass->new( module_name => $dist->name ); + local *Test::Harness::runtests = sub { + is shift(), $mock1, "runtests ran with expected parameters"; + is shift(), $mock2, "runtests ran with expected parameters"; + is $Test::Harness::switches, '', "switches are undef"; + is $Test::Harness::Switches, '', "switches are undef"; + }; + + # $Test::Harness::switches and $Test::Harness::switches are aliases, but we pretend we don't know this + local $Test::Harness::switches = ''; + local $Test::Harness::switches = ''; + $mb->run_test_harness([$mock1, $mock2]); + + ok 1, "run_test_harness should not produce warning if Test::Harness::[Ss]witches are undef and harness_switches() return empty list"; + } + + # This runs run_test_harness with Test::Harness::switches = '' and harness_switches() returning empty list, + # ensure there are no warnings, and switches are empty string + { + my $mb = MB::Subclass->new( module_name => $dist->name ); + local *Test::Harness::runtests = sub { + is shift(), $mock1, "runtests ran with expected parameters"; + is shift(), $mock2, "runtests ran with expected parameters"; + is $Test::Harness::switches, '', "switches are empty string"; + is $Test::Harness::Switches, '', "switches are empty string"; + }; + + # $Test::Harness::switches and $Test::Harness::switches are aliases, but we pretend we don't know this + local $Test::Harness::switches = ''; + local $Test::Harness::switches = ''; + $mb->run_test_harness([$mock1, $mock2]); + } + +} diff --git a/t/use_tap_harness.t b/t/use_tap_harness.t new file mode 100644 index 0000000..bfce506 --- /dev/null +++ b/t/use_tap_harness.t @@ -0,0 +1,94 @@ +#!/usr/bin/perl -w + +use strict; +use Test::More; +use lib 't/lib'; +if (eval { require TAP::Harness && TAP::Harness->VERSION(3) }) { + plan tests => 9; +} else { + plan skip_all => 'TAP::Harness 3+ not installed' +} + +use MBTest; +use DistGen; + +blib_load('Module::Build'); +my $tmp = MBTest->tmpdir; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; +$dist->chdir_in; + +######################### + +# Make sure that TAP::Harness properly does its thing. +$dist->change_build_pl( + module_name => $dist->name, + use_tap_harness => 1, + quiet => 1, +); +$dist->regen; + +ok my $mb = $dist->new_from_context, + 'Construct build object with test_file_exts parameter'; + +$mb->add_to_cleanup('save_out'); +# Use uc() so we don't confuse the current test output +my $out = uc(stdout_of( + sub {$mb->dispatch('test', verbose => 1)} +)); + +like $out, qr/^OK 1/m, 'Should see first test output'; +like $out, qr/^ALL TESTS SUCCESSFUL/m, 'Should see test success message'; + +######################### + +# Make sure that arguments are passed through to TAP::Harness. +$dist->change_build_pl( + module_name => $dist->name, + use_tap_harness => 1, + tap_harness_args => { verbosity => 0 }, + quiet => 1, +); +$dist->regen; + +ok $mb = $dist->new_from_context, + 'Construct build object with test_file_exts parameter'; + +$mb->add_to_cleanup('save_out'); +# Use uc() so we don't confuse the current test output +$out = uc(stdout_of( + sub {$mb->dispatch('test', verbose => 1)} +)); + +unlike $out, qr/^OK 1/m, 'Should not see first test output'; +like $out, qr/^ALL TESTS SUCCESSFUL/m, 'Should see test success message'; + +#--------------------------------------------------------------------------# +# test that a failing test dies +#--------------------------------------------------------------------------# + +$dist->change_build_pl( + module_name => $dist->name, + use_tap_harness => 1, + tap_harness_args => { verbosity => 1 }, + quiet => 1, +); +$dist->change_file('t/basic.t',<<"---"); +use Test::More tests => 1; +use strict; + +use $dist->{name}; +ok 0; +--- +$dist->regen; + +ok $mb = $dist->new_from_context, + 'Construct build object after setting tests to fail'; +# Use uc() so we don't confuse the current test output +$out = stdout_stderr_of( sub { $dist->run_build('test')} ); +ok( $?, "'Build test' had non-zero exit code" ); +like( $out, qr{Errors in testing\. Cannot continue\.}, + "Saw emulated Test::Harness die() message" +); + +# vim:ts=4:sw=4:et:sta diff --git a/t/versions.t b/t/versions.t new file mode 100644 index 0000000..5eafbac --- /dev/null +++ b/t/versions.t @@ -0,0 +1,21 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 2; + +blib_load('Module::Build'); + +my $tmp = MBTest->tmpdir; + +use DistGen; +my $dist = DistGen->new( dir => $tmp ); +$dist->regen; + +######################### + +my @mod = split( /::/, $dist->name ); +my $file = File::Spec->catfile( $dist->dirname, 'lib', @mod ) . '.pm'; +is( Module::Build->version_from_file( $file ), '0.01', 'version_from_file' ); + +ok( Module::Build->compare_versions( '1.01_01', '>', '1.01' ), 'compare: 1.0_01 > 1.0' ); diff --git a/t/write_default_maniskip.t b/t/write_default_maniskip.t new file mode 100644 index 0000000..40389f2 --- /dev/null +++ b/t/write_default_maniskip.t @@ -0,0 +1,42 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use lib 't/lib'; +use MBTest 'no_plan'; +use DistGen; +use Cwd; + +blib_load('Module::Build'); + +{ + my $cwd = Cwd::cwd; + chdir MBTest->tmpdir(); + + my $build = Module::Build->new( + module_name => "Foo::Bar", + dist_name => "Foo-Bar", + dist_version => '1.23', + ); + + my $skip = "mskip.txt"; # for compatibility + $build->_write_default_maniskip($skip); + + ok -r $skip, "Default maniskip written"; + my $have = slurp($skip); + + my $head; + if( $build->_eumanifest_has_include ) { + $head = "#!include_default\n"; + } + else { + $head = slurp($build->_default_maniskip); + } + + like $have, qr/^\Q$head\E/, "default MANIFEST.SKIP used"; + like $have, qr/^# Avoid Module::Build generated /ms, "Module::Build specific entries"; + like $have, qr/Foo-Bar-/, "distribution tarball entry"; + + DistGen::chdir_all($cwd); +} @@ -0,0 +1,217 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest; +use Config; + +my $tmp; + +blib_load('Module::Build'); + +{ + my ($have_c_compiler, $tmp_exec) = check_compiler(); + + if ( !$have_c_compiler ) { + plan skip_all => 'No compiler found'; + } elsif ( $^O eq 'VMS' ) { + plan skip_all => 'Child test output confuses harness'; + } elsif ( !$Config{usedl} ) { + plan skip_all => 'Perl not compiled for dynamic loading' + } else { + plan tests => 22; + } + require Cwd; + $tmp = MBTest->tmpdir( $tmp_exec ? () : (DIR => Cwd::cwd) ); +} + + + +######################### + +use DistGen; +my $dist = DistGen->new( dir => $tmp, xs => 1 )->chdir_in->regen; + +my $mb = $dist->new_from_context; + +eval {$mb->dispatch('clean')}; +is $@, ''; + +eval {$mb->dispatch('build')}; +is $@, ''; + +{ + # Make sure it actually works: that we can call methods in the XS module + + # Unfortunately, We must do this is a subprocess because some OS will not + # release the handle on a dynamic lib until the attaching process terminates + + ok $mb->run_perl_command(['-Mblib', '-M'.$dist->name, '-e1']); + + like stdout_of( sub {$mb->run_perl_command([ + '-Mblib', '-M'.$dist->name, + '-we', "print @{[$dist->name]}::okay()"])}), qr/ok$/; + + like stdout_of( sub {$mb->run_perl_command([ + '-Mblib', '-M'.$dist->name, + '-we', "print @{[$dist->name]}::version()"])}), qr/0.01$/; + + like stdout_of( sub {$mb->run_perl_command([ + '-Mblib', '-M'.$dist->name, + '-we', "print @{[$dist->name]}::xs_version()"])}), qr/0.01$/; + +} + +{ + # Try again in a subprocess + eval {$mb->dispatch('clean')}; + is $@, ''; + + + $mb->create_build_script; + my $script = $mb->build_script; + ok -e $script; + + eval {$mb->run_perl_script($script)}; + is $@, ''; +} + +# We can't be verbose in the sub-test, because Test::Harness will +# think that the output is for the top-level test. +stdout_stderr_of( sub { eval {$mb->dispatch('test')} }); +is $@, ''; + +eval {$mb->dispatch('clean')}; +is $@, ''; + + +SKIP: { + skip( "skipping a Unixish-only tests", 1 ) + unless $mb->is_unixish; + + $mb->{config}->push(ld => "FOO=BAR ".$mb->config('ld')); + eval {$mb->dispatch('build')}; + is $@, ''; + $mb->{config}->pop('ld'); +} + +eval {$mb->dispatch('realclean')}; +is $@, ''; + +# Make sure blib/ is gone after 'realclean' +ok ! -e 'blib'; + +######################################## + +# Try a XS distro with a deep namespace + + +$dist->reset( name => 'Simple::With::Deep::Name', dir => $tmp, xs => 1 ); +$dist->chdir_in->regen; + +$mb = $dist->new_from_context; + +eval { $mb->dispatch('build') }; +is $@, ''; + +stdout_stderr_of( sub { eval { $mb->dispatch('test') } } ); +is $@, ''; + +eval { $mb->dispatch('clean') }; + +eval { $mb->dispatch('build', 'pureperl_only' => 1) }; +like $@, qr/\ACan\'t build xs files under --pureperl-only/, 'Can\'t build xs under pureperl'; + +eval { $mb->dispatch('build', pureperl_only => 1, allow_pureperl => 1) }; +is $@, '', 'Can\'t build xs under pureperl, unless allow_pureperl'; + +eval { $mb->dispatch('realclean') }; +is $@, ''; + +######################################## + +# Try a XS distro using a flat directory structure +# and a 'dist_name' instead of a 'module_name' + +$dist->reset( name => 'Dist-Name', dir => $tmp, xs => 1 )->chdir_in; + +$dist->remove_file('lib/Dist-Name.pm'); +$dist->remove_file('lib/Dist-Name.xs'); + +$dist->change_build_pl + ({ + dist_name => 'Dist-Name', + dist_version_from => 'Simple.pm', + pm_files => { 'Simple.pm' => 'lib/Simple.pm' }, + xs_files => { 'Simple.xs' => 'lib/Simple.xs' }, + }); + +$dist->add_file('Simple.xs', <<"---"); +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +MODULE = Simple PACKAGE = Simple + +SV * +okay() + CODE: + RETVAL = newSVpv( "ok", 0 ); + OUTPUT: + RETVAL +--- + +$dist->add_file( 'Simple.pm', <<"---" ); +package Simple; + +\$VERSION = '0.01'; + +require Exporter; +require DynaLoader; + +\@ISA = qw( Exporter DynaLoader ); +\@EXPORT_OK = qw( okay ); + +bootstrap Simple \$VERSION; + +1; + +__END__ + +=head1 NAME + +Simple - Perl extension for blah blah blah + +=head1 DESCRIPTION + +Stub documentation for Simple. + +=head1 AUTHOR + +A. U. Thor, a.u.thor\@a.galaxy.far.far.away + +=cut +--- +$dist->change_file('t/basic.t', <<"---"); +use Test::More tests => 2; +use strict; + +use Simple; +ok( 1 ); + +ok( Simple::okay() eq 'ok' ); +--- + +$dist->regen; + +$mb = $dist->new_from_context; + +eval { $mb->dispatch('build') }; +is $@, ''; + +stdout_of( sub { eval { $mb->dispatch('test') } } ); +is $@, ''; + +eval { $mb->dispatch('realclean') }; +is $@, ''; + |