[Module-build-general] [PATCH] Make Compat.pm play well with old CPAN(PLUS)?.pm.
Status: Beta
Brought to you by:
kwilliams
From: Autrijus T. <aut...@au...> - 2002-08-15 10:54:38
|
As attached. Two things are fixed: - PREREQ_PM info is now written to Makefile. - Friendly bootstrapping code that makes Module::Build to be installed first. I hadn't tested extensively whether old CPAN.pm will resume from 'perl Makefile.PL' step or merely 'make'. If it's the latter case then we also need a fake 'all :' target that runs 'Build.PL' again in the POD. Thanks, /Autrijus/ --- lib/Module/Build/Compat.pm Wed Jun 5 11:25:43 2002 +++ /home/autrijus/Compat.pm Thu Aug 15 18:52:39 2002 @@ -36,12 +36,31 @@ EOF } -sub write_makefile { - # Note - this doesn't yet emulate the PREREQ_PM stuff. +sub fake_prereqs { + my ($pack, %in) = @_; + $in{metadata} ||= 'META.yaml'; + + my @prereq; + foreach my $section (qw/build_requires requires/) { + # parse YAML's prerequisite info + open META, $in{metadata} or die "Cannot read $in{metadata}: $!"; + while (<META>) { + next if (1 .. /^$section:$/); + last unless /^ (.*): (.*)$/; + push @prereq, "$1=>q[$2]" unless $1 eq 'perl'; + } + close META; + } + return unless @prereq; + return "# PREREQ_PM => { " . join(", ", @prereq) . " }\n\n"; +} + +sub write_makefile { my ($pack, %in) = @_; $in{makefile} ||= 'Makefile'; open MAKE, "> $in{makefile}" or die "Cannot write $in{makefile}: $!"; + print MAKE $pack->fake_prereqs; print MAKE $pack->fake_makefile; close MAKE; } @@ -58,7 +77,16 @@ Here's a Makefile.PL that passes all functionality through to Module::Build - use Module::Build::Compat; + unless (eval { require Module::Build::Compat; 1 }) { + # Workaround with old CPAN.pm and CPANPLUS.pm + require ExtUtils::MakeMaker; + ExtUtils::MakeMaker::WriteMakefile( + 'PREREQ_PM' => { 'Module::Build::Compat' => 0 } + ); + warn "Warning: prerequisite Module::Build::Compat is not found.\n"; + exit(0); + } + Module::Build::Compat->run_build_pl(args => \@ARGV); Module::Build::Compat->write_makefile(); |