Subject: | [PATCH] Module-Build & evaluating qv()-type versions |
Greetings,
today i tried to add 'unix::process' as a prerequiste to a module::build based install.
When running 'perl Build.PL' it blew up with the error:
Undefined subroutine &Module::Build::ModuleInfo::_version::qv called at (eval 110) line 9,
<GEN12> line 13
After quite some digging, i found the problem in:
Module::Build::ModuleInfo->_evaluate_version_line
which built the following eval string:
DB<26> x $eval
0 'BEGIN { q# Hide from _packages_inside()
#; package Module::Build::ModuleInfo::_version;
no strict;
local $VERSION;
$VERSION=undef;
$vsub = sub {
our $VERSION = qv(\'1.2.2\');;
$VERSION
};
}'
Note that M::B::MI::_version has no support for qv(), and therefor
the error occurred.
Below is a patch for this situation, which addresses 2 things:
1) it makes qv() supported in this eval string by adding 'use Module::Build::Version'
to the string. Not all modules do 'use version; $VERSION = qv...' on one line, and
adding M::B::Version gets around that problem, making it DWYM.
2) If for some reason, the evalstring still fails (due to malformed perl for example),
i improved the diagnostic to be more helpful in tracking down the problem.
For Unix::Process, the error would be:
$ perl Build.PL
Checking prerequisites...
Could not get version from /usr/local/share/perl/5.8.4/Unix/Process.pm by executing:
BEGIN { q# Hide from _packages_inside()
#; package Module::Build::ModuleInfo::_version;
use Module::Build::Version;
no strict;
local $VERSION;
$VERSION=undef;
$vsub = sub {
our $VERSION = qv('1.2.2');;
$VERSION
};
}
The fatal error was: Undefined subroutine &Module::Build::ModuleInfo::_version::qv called at
(eval 110) line 9, <GEN12> line 13.
As said, below is the patch against latest stable (0.2808). If you have any
questions, don't hesitate to ask.
Cheers,
Jos
--- ModuleInfo.pm.org 2008-07-02 18:49:34.000000000 +0200
+++ ModuleInfo.pm 2008-07-02 18:53:34.000000000 +0200
@@ -291,6 +291,7 @@
my $vsub;
my $eval = qq{BEGIN { q# Hide from _packages_inside()
#; package Module::Build::ModuleInfo::_version;
+ use Module::Build::Version;
no strict;
local $sigil$var;
@@ -308,7 +309,9 @@
if $@;
(ref($vsub) eq 'CODE') or
die "failed to build version sub for $self->{filename}";
- my $result = $vsub->();
+ my $result = eval { $vsub->() };
+
+ die "Could not get version from $self->{filename} by executing:\n$eval\n\nThe fatal error
was: $@\n" if $@;
# Bless it into our own version class
$result = Module::Build::Version->new($result);