Author: kwilliams
Date: Wed Jul 5 19:36:28 2006
New Revision: 6619
Modified:
Module-Build/trunk/Build.PL
Module-Build/trunk/Changes
Module-Build/trunk/lib/Module/Build/Base.pm
Module-Build/trunk/lib/Module/Build/ModuleInfo.pm
Module-Build/trunk/t/moduleinfo.t
Log:
Add support & tests for version.pm
Modified: Module-Build/trunk/Build.PL
==============================================================================
--- Module-Build/trunk/Build.PL (original)
+++ Module-Build/trunk/Build.PL Wed Jul 5 19:36:28 2006
@@ -37,6 +37,7 @@
'Text::ParseWords' => 0,
'Getopt::Long' => 0,
'Test::Harness' => 0,
+ 'version' => 0.64,
},
recommends => {
'Archive::Tar' => '1.08',
Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes (original)
+++ Module-Build/trunk/Changes Wed Jul 5 19:36:28 2006
@@ -2,6 +2,12 @@
0.2802
+ - 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]
+
- Sped up execution of find_pods by catering to File::Spec's and
Cwd's peculiarities. This produces about a factor of 3 speedup in
building M::B itself (from about 3.5 seconds down to 1.2 seconds on
@@ -12,7 +18,6 @@
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
Modified: Module-Build/trunk/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Wed Jul 5 19:36:28 2006
@@ -1232,10 +1232,8 @@
sub compare_versions {
my $self = shift;
my ($v1, $op, $v2) = @_;
-
- # for alpha versions - this doesn't cover all cases, but should work for
most:
- $v1 =~ s/_(\d+)\z/$1/;
- $v2 =~ s/_(\d+)\z/$1/;
+ $v1 = Module::Build::Version->new($v1)
+ unless UNIVERSAL::isa($v1,'Module::Build::Version');
my $eval_str = "\$v1 $op \$v2";
my $result = eval $eval_str;
Modified: Module-Build/trunk/lib/Module/Build/ModuleInfo.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/ModuleInfo.pm (original)
+++ Module-Build/trunk/lib/Module/Build/ModuleInfo.pm Wed Jul 5 19:36:28 2006
@@ -8,6 +8,7 @@
use File::Spec;
use IO::File;
+use Module::Build::Version;
my $PKG_REGEXP = qr/ # match a package declaration
@@ -283,23 +284,14 @@
$line
}; \$$var
};
- local $^W;
-
- # version.pm will change the ->VERSION method, so we mitigate the
- # potential effects here. Unfortunately local(*UNIVERSAL::VERSION)
- # will crash perl < 5.8.1. We also use * Foo::VERSION instead of
- # *Foo::VERSION so that old versions of CPAN.pm, etc. with a
- # too-permissive regex don't think we're actually declaring a
- # version.
- my $old_version = \&UNIVERSAL::VERSION;
- eval {require version};
+ local $^W;
+ # Try and get the $VERSION
my $result = eval $eval;
- * UNIVERSAL::VERSION = $old_version;
warn "Error evaling version line '$eval' in $self->{filename}: [EMAIL
PROTECTED]" if $@;
- # Unbless it if it's a version.pm object
- $result = $result->numify if UNIVERSAL::isa($result, 'version');
+ # Bless it into our own version class
+ $result = Module::Build::Version->new($result);
return $result;
}
Modified: Module-Build/trunk/t/moduleinfo.t
==============================================================================
--- Module-Build/trunk/t/moduleinfo.t (original)
+++ Module-Build/trunk/t/moduleinfo.t Wed Jul 5 19:36:28 2006
@@ -2,7 +2,7 @@
use strict;
use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
-use MBTest tests => 66;
+use MBTest tests => 72;
use Cwd ();
my $cwd = Cwd::cwd;
@@ -163,6 +163,15 @@
our $VERSION = "1.23";
---
+ <<'---', # $VERSION using version.pm
+ package Simple;
+ use version; our $VERSION = version->new('1.23');
+---
+ <<'---', # $VERSION using version.pm and qv()
+ package Simple;
+ use version; our $VERSION = qv('1.230');
+---
+
);
my( $i, $n ) = ( 1, scalar( @modules ) );
@@ -178,7 +187,7 @@
local $SIG{__WARN__} = sub { $warnings .= $_ for @_ };
my $pm_info = Module::Build::ModuleInfo->new_from_file( $file );
- is( $pm_info->version, '1.23',
+ cmp_ok( $pm_info->version, '==', '1.23',
"correct module version ($i of $n)" );
is( $warnings, '', 'no warnings from parsing' );
$i++;
@@ -223,6 +232,26 @@
is( $pm_info->name, undef, 'no default package' );
is( $pm_info->version, undef, 'no version w/o default package' );
+# Module 'Simple.pm' contains an alpha version
+# constructor should report first $VERSION found
+$dist->change_file( 'lib/Simple.pm', <<'---' );
+package Simple;
+$VERSION = '1.23_01';
+$VERSION = eval $VERSION;
+---
+
+$dist->regen;
+$pm_info = Module::Build::ModuleInfo->new_from_file( $file );
+
+is( $pm_info->version, '1.23_01', 'alpha version reported');
+
+# NOTE the following test has be done this way because Test::Builder is
+# too smart for our own good and tries to see if the version object is a
+# dual-var, which breaks with alpha versions:
+# Argument "1.23_0100" isn't numeric in addition (+) at
+# /usr/lib/perl5/5.8.7/Test/Builder.pm line 505.
+
+ok( $pm_info->version > 1.23, 'alpha version greater than non');
# revert to pristine state
chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";