All:

Attached please find my first pass implementation of version object support for
Module::Build.  This simple patch does the following:

1) adds an explicit dependency on version.pm as distributed on CPAN or in the
core in v5.10.0;

2) overrides the overloaded stringification operator so that whatever string the
original author used to define their $VERSION is what M::B will use as the
stringified representation (much better than the current hack of forcing the
numification to be used);

3) performs all version comparisons using version objects (so it handles alpha
releases automatically, for example).

As you can see, there isn't much to the patch, since I wanted to make the
minimal amount of changes required to get all current tests passing.  I will
provide additional tests of the new functionality before I suggest that it be
integrated into the core.

Please let me know what you think.

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

=== 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;

Reply via email to