Based on a discussion started on p5p, I have revised the version object code to always return the initializer string as the stringified version (much like I was already doing for Module::Build::Version). Thus what you put in is what you get out; the sole exception is that the use of qv(1.2) *NOTE* one decimal place and no leading 'v' *NOTE* will stringify as "v1.2" so we can successfully roundtrip that value.
Attached, please find the patch to bring Module::Build into compliance. I also included a $VERSION scalar in M::B::Version, since that was missing (and already patched in bleadperl). I chose to keep the same $VERSION as the underlying version.pm release. I had to tweak a couple of tests that expected a leading 'v' (which the old code would prepend). 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/Version.pm ================================================================== --- lib/Module/Build/Version.pm (revision 2045) +++ lib/Module/Build/Version.pm (local) @@ -1,7 +1,10 @@ package Module::Build::Version; use strict; -eval "use version 0.70"; +use vars qw($VERSION); +$VERSION = 0.7201; + +eval "use version 0.7201"; if ($@) { # can't locate version files, use our own # Avoid redefined warnings if an old version.pm was available @@ -35,28 +38,6 @@ use vars qw(@ISA); @ISA = 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; __DATA__ # stub version module to make everything else happy @@ -94,7 +75,7 @@ use locale; use vars qw ($VERSION @ISA @REGEXS); -$VERSION = 0.71; +$VERSION = 0.7201; push @REGEXS, qr/ ^v? # optional leading 'v' @@ -124,6 +105,7 @@ # RT #19517 - special case for undef comparison # or someone forgot to pass a value push @{$self->{version}}, 0; + $self->{original} = "0"; return ($self); } @@ -312,6 +294,9 @@ "ignoring: '".substr($value,$pos)."'"; } + # cache the original value for use when stringification + $self->{original} = substr($value,0,$pos); + return ($self); } @@ -399,12 +384,7 @@ require Carp; Carp::croak("Invalid version object"); } - if ( exists $self->{qv} ) { - return $self->normal; - } - else { - return $self->numify; - } + return $self->{original}; } sub vcmp @@ -495,8 +475,9 @@ my ($value) = @_; $value = _un_vstring($value); - $value = 'v'.$value unless $value =~ /^v/; - return version->new($value); # always use base class + $value = 'v'.$value unless $value =~ /(^v|\d+\.\d+\.\d)/; + my $version = version->new($value); # always use base class + return $version; } sub is_qv { @@ -585,13 +566,13 @@ Carp::croak( sprintf ("%s version %s required--". "this is only version %s", $class, - $req->numify, $version->numify) + $req->stringify, $version->stringify) ); } } } - return defined $version ? $version->numify : undef; + return defined $version ? $version->stringify : undef; }; } === t/metadata.t ================================================================== --- t/metadata.t (revision 2045) +++ t/metadata.t (local) @@ -147,8 +147,8 @@ --- $dist->regen; my $provides = new_build()->prepare_metadata()->{provides}; - is $provides->{'Simple'}{version}, 'v0.60.128', "Check version"; - is $provides->{'Simple::Simon'}{version}, 'v0.61.129', "Check version"; + is $provides->{'Simple'}{version}, '0.60.128', "Check version"; + is $provides->{'Simple::Simon'}{version}, '0.61.129', "Check version"; is ref($provides->{'Simple'}{version}), '', "Versions from prepare_metadata() aren't refs"; is ref($provides->{'Simple::Simon'}{version}), '', "Versions from prepare_metadata() aren't refs"; } === t/moduleinfo.t ================================================================== --- t/moduleinfo.t (revision 2045) +++ t/moduleinfo.t (local) @@ -419,10 +419,10 @@ $pm_info = Module::Build::ModuleInfo->new_from_file('lib/Simple.pm'); is( $pm_info->name, 'Simple', 'found default package' ); - is( $pm_info->version, 'v0.60.128', 'version for default package' ); + is( $pm_info->version, '0.60.128', 'version for default package' ); my @packages = $pm_info->packages_inside; is_deeply([sort @packages], ['Simple', 'Simple::Simon']); - is( $pm_info->version('Simple::Simon'), 'v0.61.129', 'version for embedded package' ); + is( $pm_info->version('Simple::Simon'), '0.61.129', 'version for embedded package' ); }