Skip Menu |

This queue is for tickets about the Module-Build CPAN distribution.

Report information
The Basics
Id: 2948
Status: resolved
Priority: 0/
Queue: Module-Build

People
Owner: Nobody in particular
Requestors: spurkis [...] epn.nu
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.19
Fixed in: 0.19_02



Subject: [PATCH] version_from_file does not ignore comments/pod
Hi, Module::Build::Base::version_from_file does not ignore version lines in comments or POD. The attached patch fixes this. hth, -Steve
diff -ruN Module-Build-0.19.orig/lib/Module/Build/Base.pm Module-Build-0.19/lib/Module/Build/Base.pm --- Module-Build-0.19.orig/lib/Module/Build/Base.pm Mon Jul 7 23:02:21 2003 +++ Module-Build-0.19/lib/Module/Build/Base.pm Mon Jul 14 15:49:37 2003 @@ -366,9 +366,12 @@ my ($self, $file) = @_; # Some of this code came from the ExtUtils:: hierarchy. - my $fh = IO::File->new($file) or die "Can't open '$file' for version: $!"; - local $_; + my $fh = IO::File->new($file) or die "Can't open '$file' for version: $!"; + my $inpod = 0; + while (<$fh>) { + $inpod = /^=(?!cut)/ ? 1 : /^=cut/ ? 0 : $inpod; + next if $inpod || /^\s*#/; if ( my ($sigil, $var) = /([\$*])(([\w\:\']*)\bVERSION)\b.*\=/ ) { my $eval = qq{ package Module::Build::Base::_version; @@ -380,7 +383,9 @@ }; \$$var }; local $^W; - return scalar eval $eval; + my $result = eval $eval; + warn "Error evaling version line '$eval' in $file: $@\n" if $@; + return $result; } } return undef; diff -ruN Module-Build-0.19.orig/t/data/version-test.pl Module-Build-0.19/t/data/version-test.pl --- Module-Build-0.19.orig/t/data/version-test.pl Thu Jan 1 01:00:00 1970 +++ Module-Build-0.19/t/data/version-test.pl Mon Jul 14 15:47:35 2003 @@ -0,0 +1,16 @@ +=head1 some pod + +version lines in pod should be ignored: +$VERSION = 'not ok: got version from pod!'; + +=cut + +# version lines in comments should be ignored: +# $VERSION = 'not ok: got version from comment!'; + +# this is the version line we're looking for: +$VERSION = ('ok: got version from code')[0]; # should be eval'd + +# we should only take the first version line found: +$VERSION = 'not ok: got second version from code!'; + diff -ruN Module-Build-0.19.orig/t/versions.t Module-Build-0.19/t/versions.t --- Module-Build-0.19.orig/t/versions.t Thu Jan 1 01:00:00 1970 +++ Module-Build-0.19/t/versions.t Mon Jul 14 15:47:26 2003 @@ -0,0 +1,13 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test; +BEGIN { plan tests => 1 } + +use Module::Build::Base; + +my $build = bless {}, 'Module::Build::Base'; +ok( $build->version_from_file( 't/data/version-test.pl' ), qr/^ok/, 'version_from_file' ); +
Thanks for the patch, Steve. I'm applying it now in a modified form. -Ken
no worries, I noticed that too and added it back. -Ken