Ken Williams wrote:
> Let me know when you've got a patch that you think is ready.

Here we go.  I added some new tests to t/moduleinfo.t for:

1) $VERSION initialized with version->new();
2) $VERSION initialized with qv();
3) $VERSION initialized with an alpha string.

I made the patch dependent on version-0.64, which is the current release.

Please let me know if you have any questions or concerns...

John

-- 
John Peacock
Director of Information Research and Technology
Rowman & Littlefield Publishing Group
4501 Forbes Blvd
Suite H
Lanham, MD 20706
301-459-3366 x.5010
fax 301-429-5747
=== Build.PL
==================================================================
--- Build.PL    (revision 1909)
+++ Build.PL    (local)
@@ -37,6 +37,7 @@
                'Text::ParseWords' => 0,
                'Getopt::Long'   => 0,
                'Test::Harness'  => 0,
+               'version'        => 0.64,
               },
    recommends => {
                  'Archive::Tar' => '1.08',
=== lib/Module/Build/Base.pm
==================================================================
--- lib/Module/Build/Base.pm    (revision 1909)
+++ lib/Module/Build/Base.pm    (local)
@@ -1232,11 +1232,9 @@
 sub compare_versions {
   my $self = shift;
   my ($v1, $op, $v2) = @_;
+  $v1 = Module::Build::Version->new($v1) 
+    unless UNIVERSAL::isa($v1,'Module::Build::Version');
 
-  # for alpha versions - this doesn't cover all cases, but should work for 
most:
-  $v1 =~ s/_(\d+)\z/$1/;
-  $v2 =~ s/_(\d+)\z/$1/;
-
   my $eval_str = "\$v1 $op \$v2";
   my $result   = eval $eval_str;
   $self->log_warn("error comparing versions: '$eval_str' $@") if $@;
=== lib/Module/Build/ModuleInfo.pm
==================================================================
--- lib/Module/Build/ModuleInfo.pm      (revision 1909)
+++ lib/Module/Build/ModuleInfo.pm      (local)
@@ -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;
 }
=== lib/Module/Build/Version.pm
==================================================================
--- lib/Module/Build/Version.pm (revision 1909)
+++ lib/Module/Build/Version.pm (local)
@@ -0,0 +1,26 @@
+package Module::Build::Version;
+use base qw/version/;
+
+use overload (
+    '""' => \&stringify,
+);
+
+sub new {
+    my ($class, $value) = @_;
+    my $self = $class->SUPER::new($value);
+    $self->original($value);
+    return $self;
+}
+
+sub original {
+    my $self = shift;
+    $self->{original} = shift if @_;
+    return $self->{original};
+}
+
+sub stringify {
+    my $self = shift;
+    return $self->original;
+}
+
+1;
=== t/moduleinfo.t
==================================================================
--- t/moduleinfo.t      (revision 1909)
+++ t/moduleinfo.t      (local)
@@ -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,7 +232,27 @@
 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': $!";
 $dist->remove;

Reply via email to