diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-04-21 09:20:56 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2007-04-21 09:20:56 +0000 |
commit | 8cb289bd08361a8bd4bed96b220c3e5ea828821b (patch) | |
tree | f1d0f18d727ce3d0edb927c4a0405fb13e0344f4 /lib | |
parent | c94dd5be9196e7fc999830ac8069b03bb8f510be (diff) | |
download | perl-8cb289bd08361a8bd4bed96b220c3e5ea828821b.tar.gz |
Upgrade to version-0.7203.
Plus a change in Module::Build::Version, specific to bleadperl.
p4raw-id: //depot/perl@31005
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Module/Build/Version.pm | 600 | ||||
-rw-r--r-- | lib/Module/Build/t/metadata.t | 4 | ||||
-rw-r--r-- | lib/Module/Build/t/moduleinfo.t | 4 | ||||
-rw-r--r-- | lib/version.pm | 2 | ||||
-rw-r--r-- | lib/version.pod | 100 | ||||
-rw-r--r-- | lib/version.t | 98 |
6 files changed, 99 insertions, 709 deletions
diff --git a/lib/Module/Build/Version.pm b/lib/Module/Build/Version.pm index 00db2f62ea..2a956ff75c 100644 --- a/lib/Module/Build/Version.pm +++ b/lib/Module/Build/Version.pm @@ -2,601 +2,5 @@ package Module::Build::Version; use strict; use vars qw($VERSION); -$VERSION = '0.58_01'; -$VERSION = eval $VERSION; - -eval "use version 0.70"; -if ($@) { # can't locate version files, use our own - - # Avoid redefined warnings if an old version.pm was available - delete $version::{$_} foreach keys %version::; - - # first we get the stub version module - my $version; - while (<DATA>) { - s/(\$VERSION)\s=\s\d+/\$VERSION = 0/; - $version .= $_ if $_; - last if /^1;$/; - } - - # and now get the current version::vpp code - my $vpp; - while (<DATA>) { - s/(\$VERSION)\s=\s\d+/\$VERSION = 0/; - $vpp .= $_ if $_; - last if /^1;$/; - } - - # but we eval them in reverse order since version depends on - # version::vpp to already exist - eval $vpp; die $@ if $@; - $INC{'version/vpp.pm'} = 'inside Module::Build::Version'; - eval $version; die $@ if $@; - $INC{'version.pm'} = 'inside Module::Build::Version'; -} - -# now we can safely subclass version, installed or not -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 -package version; - -use 5.005_04; -use strict; - -use vars qw(@ISA $VERSION $CLASS *qv); - -$VERSION = 0.000; - -$CLASS = 'version'; - -push @ISA, "version::vpp"; -*version::qv = \&version::vpp::qv; - -# Preloaded methods go here. -sub import { - my ($class) = @_; - my $callpkg = caller(); - no strict 'refs'; - - *{$callpkg."::qv"} = - sub {return bless version::qv(shift), $class } - unless defined(&{"$callpkg\::qv"}); - -} - -1; -# replace everything from here to the end with the current version/vpp.pm - -package version::vpp; -use strict; - -use locale; -use vars qw ($VERSION @ISA @REGEXS); -$VERSION = 0.71; - -push @REGEXS, qr/ - ^v? # optional leading 'v' - (\d*) # major revision not required - \. # requires at least one decimal - (?:(\d+)\.?){1,} - /x; - -use overload ( - '""' => \&stringify, - '0+' => \&numify, - 'cmp' => \&vcmp, - '<=>' => \&vcmp, - 'bool' => \&vbool, - 'nomethod' => \&vnoop, -); - -sub new -{ - my ($class, $value) = @_; - my $self = bless ({}, ref ($class) || $class); - require POSIX; - my $currlocale = POSIX::setlocale(&POSIX::LC_ALL); - my $radix_comma = ( POSIX::localeconv()->{decimal_point} eq ',' ); - - if ( not defined $value or $value =~ /^undef$/ ) { - # RT #19517 - special case for undef comparison - # or someone forgot to pass a value - push @{$self->{version}}, 0; - return ($self); - } - - if ( $#_ == 2 ) { # must be CVS-style - $value = 'v'.$_[2]; - } - - $value = _un_vstring($value); - - # exponential notation - if ( $value =~ /\d+.?\d*e-?\d+/ ) { - $value = sprintf("%.9f",$value); - $value =~ s/(0+)$//; - } - - # if the original locale used commas for decimal points, we - # just replace commas with decimal places, rather than changing - # locales - if ( $radix_comma ) { - $value =~ tr/,/./; - } - - # This is not very efficient, but it is morally equivalent - # to the XS code (as that is the reference implementation). - # See vutil/vutil.c for details - my $qv = 0; - my $alpha = 0; - my $width = 3; - my $saw_period = 0; - my ($start, $last, $pos, $s); - $s = 0; - - while ( substr($value,$s,1) =~ /\s/ ) { # leading whitespace is OK - $s++; - } - - if (substr($value,$s,1) eq 'v') { - $s++; # get past 'v' - $qv = 1; # force quoted version processing - } - - $start = $last = $pos = $s; - - # pre-scan the input string to check for decimals/underbars - while ( substr($value,$pos,1) =~ /[._\d]/ ) { - if ( substr($value,$pos,1) eq '.' ) { - if ($alpha) { - require Carp; - Carp::croak("Invalid version format ". - "(underscores before decimal)"); - } - $saw_period++; - $last = $pos; - } - elsif ( substr($value,$pos,1) eq '_' ) { - if ($alpha) { - require Carp; - Carp::croak("Invalid version format ". - "(multiple underscores)"); - } - $alpha = 1; - $width = $pos - $last - 1; # natural width of sub-version - } - $pos++; - } - - if ( $alpha && !$saw_period ) { - require Carp; - Carp::croak("Invalid version format (alpha without decimal)"); - } - - if ( $alpha && $saw_period && $width == 0 ) { - require Carp; - Carp::croak("Invalid version format (misplaced _ in number)"); - } - - if ( $saw_period > 1 ) { - $qv = 1; # force quoted version processing - } - - $pos = $s; - - if ( $qv ) { - $self->{qv} = 1; - } - - if ( $alpha ) { - $self->{alpha} = 1; - } - - if ( !$qv && $width < 3 ) { - $self->{width} = $width; - } - - while ( substr($value,$pos,1) =~ /\d/ ) { - $pos++; - } - - if ( substr($value,$pos,1) !~ /[a-z]/ ) { ### FIX THIS ### - my $rev; - - while (1) { - $rev = 0; - { - - # this is atoi() that delimits on underscores - my $end = $pos; - my $mult = 1; - my $orev; - - # the following if() will only be true after the decimal - # point of a version originally created with a bare - # floating point number, i.e. not quoted in any way - if ( !$qv && $s > $start && $saw_period == 1 ) { - $mult *= 100; - while ( $s < $end ) { - $orev = $rev; - $rev += substr($value,$s,1) * $mult; - $mult /= 10; - if ( abs($orev) > abs($rev) ) { - require Carp; - Carp::croak("Integer overflow in version"); - } - $s++; - if ( substr($value,$s,1) eq '_' ) { - $s++; - } - } - } - else { - while (--$end >= $s) { - $orev = $rev; - $rev += substr($value,$end,1) * $mult; - $mult *= 10; - if ( abs($orev) > abs($rev) ) { - require Carp; - Carp::croak("Integer overflow in version"); - } - } - } - } - - # Append revision - push @{$self->{version}}, $rev; - if ( substr($value,$pos,1) eq '.' - && substr($value,$pos+1,1) =~ /\d/ ) { - $s = ++$pos; - } - elsif ( substr($value,$pos,1) eq '_' - && substr($value,$pos+1,1) =~ /\d/ ) { - $s = ++$pos; - } - elsif ( substr($value,$pos,1) =~ /\d/ ) { - $s = $pos; - } - else { - $s = $pos; - last; - } - if ( $qv ) { - while ( substr($value,$pos,1) =~ /\d/ ) { - $pos++; - } - } - else { - my $digits = 0; - while (substr($value,$pos,1) =~ /[\d_]/ && $digits < 3) { - if ( substr($value,$pos,1) ne '_' ) { - $digits++; - } - $pos++; - } - } - } - } - if ( $qv ) { # quoted versions always get at least three terms - my $len = scalar @{$self->{version}}; - $len = 3 - $len; - while ($len-- > 0) { - push @{$self->{version}}, 0; - } - } - - if ( substr($value,$pos) ) { # any remaining text - warn "Version string '$value' contains invalid data; ". - "ignoring: '".substr($value,$pos)."'"; - } - - return ($self); -} - -sub numify -{ - my ($self) = @_; - unless (_verify($self)) { - require Carp; - Carp::croak("Invalid version object"); - } - my $width = $self->{width} || 3; - my $alpha = $self->{alpha} || ""; - my $len = $#{$self->{version}}; - my $digit = $self->{version}[0]; - my $string = sprintf("%d.", $digit ); - - for ( my $i = 1 ; $i < $len ; $i++ ) { - $digit = $self->{version}[$i]; - if ( $width < 3 ) { - my $denom = 10**(3-$width); - my $quot = int($digit/$denom); - my $rem = $digit - ($quot * $denom); - $string .= sprintf("%0".$width."d_%d", $quot, $rem); - } - else { - $string .= sprintf("%03d", $digit); - } - } - - if ( $len > 0 ) { - $digit = $self->{version}[$len]; - if ( $alpha && $width == 3 ) { - $string .= "_"; - } - $string .= sprintf("%0".$width."d", $digit); - } - else # $len = 0 - { - $string .= sprintf("000"); - } - - return $string; -} - -sub normal -{ - my ($self) = @_; - unless (_verify($self)) { - require Carp; - Carp::croak("Invalid version object"); - } - my $alpha = $self->{alpha} || ""; - my $len = $#{$self->{version}}; - my $digit = $self->{version}[0]; - my $string = sprintf("v%d", $digit ); - - for ( my $i = 1 ; $i < $len ; $i++ ) { - $digit = $self->{version}[$i]; - $string .= sprintf(".%d", $digit); - } - - if ( $len > 0 ) { - $digit = $self->{version}[$len]; - if ( $alpha ) { - $string .= sprintf("_%0d", $digit); - } - else { - $string .= sprintf(".%0d", $digit); - } - } - - if ( $len <= 2 ) { - for ( $len = 2 - $len; $len != 0; $len-- ) { - $string .= sprintf(".%0d", 0); - } - } - - return $string; -} - -sub stringify -{ - my ($self) = @_; - unless (_verify($self)) { - require Carp; - Carp::croak("Invalid version object"); - } - if ( exists $self->{qv} ) { - return $self->normal; - } - else { - return $self->numify; - } -} - -sub vcmp -{ - require UNIVERSAL; - my ($left,$right,$swap) = @_; - my $class = ref($left); - unless ( UNIVERSAL::isa($right, $class) ) { - $right = $class->new($right); - } - - if ( $swap ) { - ($left, $right) = ($right, $left); - } - unless (_verify($left)) { - require Carp; - Carp::croak("Invalid version object"); - } - unless (_verify($right)) { - require Carp; - Carp::croak("Invalid version object"); - } - my $l = $#{$left->{version}}; - my $r = $#{$right->{version}}; - my $m = $l < $r ? $l : $r; - my $lalpha = $left->is_alpha; - my $ralpha = $right->is_alpha; - my $retval = 0; - my $i = 0; - while ( $i <= $m && $retval == 0 ) { - $retval = $left->{version}[$i] <=> $right->{version}[$i]; - $i++; - } - - # tiebreaker for alpha with identical terms - if ( $retval == 0 - && $l == $r - && $left->{version}[$m] == $right->{version}[$m] - && ( $lalpha || $ralpha ) ) { - - if ( $lalpha && !$ralpha ) { - $retval = -1; - } - elsif ( $ralpha && !$lalpha) { - $retval = +1; - } - } - - # possible match except for trailing 0's - if ( $retval == 0 && $l != $r ) { - if ( $l < $r ) { - while ( $i <= $r && $retval == 0 ) { - if ( $right->{version}[$i] != 0 ) { - $retval = -1; # not a match after all - } - $i++; - } - } - else { - while ( $i <= $l && $retval == 0 ) { - if ( $left->{version}[$i] != 0 ) { - $retval = +1; # not a match after all - } - $i++; - } - } - } - - return $retval; -} - -sub vbool { - my ($self) = @_; - return vcmp($self,$self->new("0"),1); -} - -sub vnoop { - require Carp; - Carp::croak("operation not supported with version object"); -} - -sub is_alpha { - my ($self) = @_; - return (exists $self->{alpha}); -} - -sub qv { - my ($value) = @_; - - $value = _un_vstring($value); - $value = 'v'.$value unless $value =~ /^v/; - return version->new($value); # always use base class -} - -sub is_qv { - my ($self) = @_; - return (exists $self->{qv}); -} - - -sub _verify { - my ($self) = @_; - if ( ref($self) - && eval { exists $self->{version} } - && ref($self->{version}) eq 'ARRAY' - ) { - return 1; - } - else { - return 0; - } -} - -sub _un_vstring { - my $value = shift; - # may be a v-string - if ( $] >= 5.006_000 && length($value) >= 3 && $value !~ /[._]/ ) { - my $tvalue = sprintf("%vd",$value); - if ( $tvalue =~ /^\d+\.\d+\.\d+$/ ) { - # must be a v-string - $value = $tvalue; - } - } - return $value; -} - -# Thanks to Yitzchak Scott-Thoennes for this mode of operation -{ - local $^W; - *UNIVERSAL::VERSION = sub { - my ($obj, $req) = @_; - my $class = ref($obj) || $obj; - - no strict 'refs'; - eval "require $class" unless %{"$class\::"}; # already existing - return undef if $@ =~ /Can't locate/ and not defined $req; - - if ( not %{"$class\::"} and $] >= 5.008) { # file but no package - require Carp; - Carp::croak( "$class defines neither package nor VERSION" - ."--version check failed"); - } - - my $version = eval "\$$class\::VERSION"; - if ( defined $version ) { - local $^W if $] <= 5.008; - $version = version::vpp->new($version); - } - - if ( defined $req ) { - unless ( defined $version ) { - require Carp; - my $msg = $] < 5.006 - ? "$class version $req required--this is only version " - : "$class does not define \$$class\::VERSION" - ."--version check failed"; - - if ( $ENV{VERSION_DEBUG} ) { - Carp::confess($msg); - } - else { - Carp::croak($msg); - } - } - - $req = version::vpp->new($req); - - if ( $req > $version ) { - require Carp; - if ( $req->is_qv ) { - Carp::croak( - sprintf ("%s version %s required--". - "this is only version %s", $class, - $req->normal, $version->normal) - ); - } - else { - Carp::croak( - sprintf ("%s version %s required--". - "this is only version %s", $class, - $req->numify, $version->numify) - ); - } - } - } - - return defined $version ? $version->numify : undef; - }; -} - -1; #this line is important and will help the module return a true value +$VERSION = 0.7203; +use base qw/version/; diff --git a/lib/Module/Build/t/metadata.t b/lib/Module/Build/t/metadata.t index 6dc67a8daf..41660929d9 100644 --- a/lib/Module/Build/t/metadata.t +++ b/lib/Module/Build/t/metadata.t @@ -147,8 +147,8 @@ $VERSION = version->new('0.61.' . (qw$Revision: 129 $)[1]); --- $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"; } diff --git a/lib/Module/Build/t/moduleinfo.t b/lib/Module/Build/t/moduleinfo.t index b08d5a2a9a..a97cac5ee4 100644 --- a/lib/Module/Build/t/moduleinfo.t +++ b/lib/Module/Build/t/moduleinfo.t @@ -419,10 +419,10 @@ $VERSION = version->new('0.61.' . (qw$Revision: 129 $)[1]); $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' ); } diff --git a/lib/version.pm b/lib/version.pm index 9fd7208314..3ea5007f27 100644 --- a/lib/version.pm +++ b/lib/version.pm @@ -6,7 +6,7 @@ use strict; use vars qw(@ISA $VERSION $CLASS *qv); -$VERSION = 0.71; +$VERSION = 0.7203; $CLASS = 'version'; diff --git a/lib/version.pod b/lib/version.pod index b0dcc84970..dee652dbed 100644 --- a/lib/version.pod +++ b/lib/version.pod @@ -161,7 +161,8 @@ if required: $v2 = version->new("1.2.3"); # v1.2.3 In specific, version numbers initialized as L<Numeric Versions> will -stringify in Numeric form. Version numbers initialized as L<Extended Versions> +stringify as they were originally created (i.e. the same string that was +passed to C<new()>. Version numbers initialized as L<Extended Versions> will be stringified as L<Normal Form>. =head2 Numeric Versions @@ -177,11 +178,11 @@ will have trailing zeros added to make up the difference, but only for purposes of comparison with other version objects. For example: # Prints Equivalent to - $v = version->new( 1.2); # 1.200 v1.200.0 - $v = version->new( 1.02); # 1.020 v1.20.0 + $v = version->new( 1.2); # 1.2 v1.200.0 + $v = version->new( 1.02); # 1.02 v1.20.0 $v = version->new( 1.002); # 1.002 v1.2.0 - $v = version->new( 1.0023); # 1.002300 v1.2.300 - $v = version->new( 1.00203); # 1.002030 v1.2.30 + $v = version->new( 1.0023); # 1.0023 v1.2.300 + $v = version->new( 1.00203); # 1.00203 v1.2.30 $v = version->new( 1.002003); # 1.002003 v1.2.3 All of the preceding examples are true whether or not the input value is @@ -233,16 +234,15 @@ is quoted. For example Module::Example was released to CPAN with the following sequence of $VERSION's: # $VERSION Stringified - 0.01 0.010 - 0.02 0.020 - 0.02_01 0.02_0100 - 0.02_02 0.02_0200 - 0.03 0.030 + 0.01 0.01 + 0.02 0.02 + 0.02_01 0.02_01 + 0.02_02 0.02_02 + 0.03 0.03 etc. -As you can see, the version object created from the values in the first -column may contain a trailing 0, but will otherwise be both mathematically -equivalent and sorts alpha-numerically as would be expected. +The stringified form of numeric versions will always be the same string +that was used to initialize the version object. =head2 Object Methods @@ -387,25 +387,25 @@ trailing zeros to preserve the correct version value. =item * Stringification -In order to mirror as much as possible the existing behavior of ordinary -$VERSION scalars, the stringification operation will display differently, -depending on whether the version was initialized as a L<Numeric Version> -or L<Extended Version>. +The default stringification for version objects returns exactly the same +string as was used to create it, whether you used C<new()> or C<qv()>, +with one exception. The sole exception is if the object was created using +C<qv()> and the initializer did not have two decimal places or a leading +'v' (both optional), then the stringified form will have a leading 'v' +prepended, in order to support round-trip processing. -What this means in practice is that if the normal CPAN and Camel rules are -followed ($VERSION is a floating point number with no more than 3 decimal -points), the stringified output will be exactly the same as the numified -output. There will be no visible difference, although the internal -representation will be different, and the L<Comparison operators> will -function using the internal coding. +For example: -If a version object is initialized using a L<Extended Version> form, then -the stringified form will be the L<Normal Form>. The $obj->normal -operation can always be used to produce the L<Normal Form>, even if the -version was originally a L<Numeric Version>. + Initialized as Stringifies to + ============== ============== + version->new("1.2") 1.2 + version->new("v1.2") v1.2 + qv("1.2.3") 1.2.3 + qv("v1.3.5") v1.3.5 + qv("1.2") v1.2 ### exceptional case - print $ver->stringify; # prints v1.2.3.4 - print $nver->stringify; # prints 1.002 +See also L<UNIVERSAL::VERSION>, as this also returns the stringified form +when used as a class method. =back @@ -538,6 +538,10 @@ version, e.g. 1.2.3 or v1.2.3 in order for this heuristic to be successful. core to be magical, which means that the version.pm code can automatically determine whether the v-string encoding was used. +3) In all cases, a version created using v-strings will have a stringified +form that has a leading 'v' character, for the simple reason that sometimes +it is impossible to tell whether one was present initially. + =head2 Types of Versions Objects There are two types of Version Objects: @@ -573,14 +577,9 @@ obeys the relationship 12.03 < $alphaver < 12.04 Alpha versions with a single decimal point will be treated exactly as if -they were L<Numeric Versions>, for parsing purposes. The stringification for -alpha versions with a single decimal point may seem surprising, since any -trailing zeros will visible. For example, the above $alphaver will print as - - 12.03_0100 - -which is mathematically equivalent and ASCII sorts exactly the same as -without the trailing zeros. +they were L<Numeric Versions>, for parsing and output purposes. The +underscore will be output when an alpha version is stringified, in the same +place as it was when input. Alpha versions with more than a single decimal point will be treated exactly as if they were L<Extended Versions>, and will display without any @@ -595,9 +594,9 @@ trailing (or leading) zeros, in the L<Version Normal> form. For example, In addition to the version objects, this modules also replaces the core UNIVERSAL::VERSION function with one that uses version objects for its -comparisons. The return from this operator is always the numified form, -and the warning message generated includes both the numified and normal -forms (for clarity). +comparisons. The return from this operator is always the stringified form, +but the warning message generated includes either the stringified form or +the normal form, depending on how it was called. For example: @@ -614,20 +613,29 @@ For example: print $Bar::VERSION; # prints 1.003005 - eval "use CGI 10"; # some far future release - print $@; # prints "CGI version 10 (10.0.0) required..." + eval "use foo 10"; + print $@; # prints "foo version 10 required..." + eval "use foo 1.3.5; # work in Perl 5.6.1 or better + print $@; # prints "foo version 1.3.5 required..." + + eval "use bar 1.3.6"; + print $@; # prints "bar version 1.3.6 required..." + eval "use bar 1.004"; # note numeric version + print $@; # prints "bar version 1.004 required..." + IMPORTANT NOTE: This may mean that code which searches for a specific string (to determine whether a given module is available) may need to be -changed. +changed. It is always better to use the built-in comparison implicit in +C<use> or C<require>, rather than manually poking at C<class->VERSION> +and then doing a comparison yourself. The replacement UNIVERSAL::VERSION, when used as a function, like this: print $module->VERSION; -will also exclusively return the numified form. Technically, the -$module->VERSION function returns a string (PV) that can be converted to a -number following the normal Perl rules, when used in a numeric context. +will also exclusively return the stringified form. See L<Stringification> +for more details. =head1 SUBCLASSING diff --git a/lib/version.t b/lib/version.t index 11a6b07e46..09fecc91f3 100644 --- a/lib/version.t +++ b/lib/version.t @@ -73,25 +73,25 @@ sub BaseTests { # Test bare number processing diag "tests with bare numbers" if $Verbose; $version = $CLASS->new(5.005_03); - is ( "$version" , "5.005030" , '5.005_03 eq 5.5.30' ); + is ( "$version" , "5.00503" , '5.005_03 eq 5.00503' ); $version = $CLASS->new(1.23); - is ( "$version" , "1.230" , '1.23 eq "1.230"' ); + is ( "$version" , "1.23" , '1.23 eq "1.23"' ); # Test quoted number processing diag "tests with quoted numbers" if $Verbose; $version = $CLASS->new("5.005_03"); - is ( "$version" , "5.005_030" , '"5.005_03" eq "5.005_030"' ); + is ( "$version" , "5.005_03" , '"5.005_03" eq "5.005_03"' ); $version = $CLASS->new("v1.23"); - is ( "$version" , "v1.23.0" , '"v1.23" eq "v1.23.0"' ); + is ( "$version" , "v1.23" , '"v1.23" eq "v1.23"' ); # Test stringify operator diag "tests with stringify" if $Verbose; $version = $CLASS->new("5.005"); is ( "$version" , "5.005" , '5.005 eq "5.005"' ); $version = $CLASS->new("5.006.001"); - is ( "$version" , "v5.6.1" , '5.006.001 eq v5.6.1' ); + is ( "$version" , "5.006.001" , '5.006.001 eq v5.6.1' ); $version = $CLASS->new("1.2.3_4"); - is ( "$version" , "v1.2.3_4" , 'alpha version 1.2.3_4 eq v1.2.3_4' ); + is ( "$version" , "1.2.3_4" , 'alpha version 1.2.3_4 eq v1.2.3_4' ); # test illegal formats diag "test illegal formats" if $Verbose; @@ -126,7 +126,7 @@ sub BaseTests { like($warning, qr/$warnregex/, "Version string contains invalid data; ignoring"); - ok ("$version" eq "99.000", '$version eq "99.000"'); + is ("$version", "99", '$version eq "99"'); ok ($version->numify == 99.0, '$version->numify == 99.0'); ok ($version->normal eq "v99.0.0", '$version->normal eq v99.0.0'); @@ -146,33 +146,12 @@ sub BaseTests { # Test comparison operators with self diag "tests with self" if $Verbose; - ok ( $version eq $version, '$version eq $version' ); - is ( $version cmp $version, 0, '$version cmp $version == 0' ); + is ( $version <=> $version, 0, '$version <=> $version == 0' ); ok ( $version == $version, '$version == $version' ); - # test first with non-object - $version = $CLASS->new("5.006.001"); - $new_version = "5.8.0"; - diag "tests with non-objects" if $Verbose; - ok ( $version ne $new_version, '$version ne $new_version' ); - ok ( $version lt $new_version, '$version lt $new_version' ); - ok ( $new_version gt $version, '$new_version gt $version' ); - ok ( ref(\$new_version) eq 'SCALAR', 'no auto-upgrade'); - $new_version = "$version"; - ok ( $version eq $new_version, '$version eq $new_version' ); - ok ( $new_version eq $version, '$new_version eq $version' ); - - # now test with existing object - $new_version = $CLASS->new("5.8.0"); - diag "tests with objects" if $Verbose; - ok ( $version ne $new_version, '$version ne $new_version' ); - ok ( $version lt $new_version, '$version lt $new_version' ); - ok ( $new_version gt $version, '$new_version gt $version' ); - $new_version = $CLASS->new("$version"); - ok ( $version eq $new_version, '$version eq $new_version' ); - # Test Numeric Comparison operators # test first with non-object + $version = $CLASS->new("5.006.001"); $new_version = "5.8.0"; diag "numeric tests with non-objects" if $Verbose; ok ( $version == $version, '$version == $version' ); @@ -197,20 +176,20 @@ sub BaseTests { # test with long decimals diag "Tests with extended decimal versions" if $Verbose; $version = $CLASS->new(1.002003); - ok ( $version eq "1.2.3", '$version eq "1.2.3"'); + ok ( $version == "1.2.3", '$version == "1.2.3"'); ok ( $version->numify == 1.002003, '$version->numify == 1.002003'); $version = $CLASS->new("2002.09.30.1"); - ok ( $version eq "2002.9.30.1",'$version eq 2002.9.30.1'); + ok ( $version == "2002.9.30.1",'$version == 2002.9.30.1'); ok ( $version->numify == 2002.009030001, '$version->numify == 2002.009030001'); # now test with alpha version form with string $version = $CLASS->new("1.2.3"); $new_version = "1.2.3_4"; - diag "tests with alpha-style non-objects" if $Verbose; - ok ( $version lt $new_version, '$version lt $new_version' ); - ok ( $new_version gt $version, '$new_version gt $version' ); - ok ( $version ne $new_version, '$version ne $new_version' ); + diag "numeric tests with alpha-style non-objects" if $Verbose; + ok ( $version < $new_version, '$version < $new_version' ); + ok ( $new_version > $version, '$new_version > $version' ); + ok ( $version != $new_version, '$version != $new_version' ); $version = $CLASS->new("1.2.4"); diag "numeric tests with alpha-style non-objects" @@ -270,9 +249,9 @@ SKIP: { # test the qv() sub diag "testing qv" if $Verbose; $version = qv("1.2"); - cmp_ok ( $version, "eq", "v1.2.0", 'qv("1.2") eq "1.2.0"' ); + is ( "$version", "v1.2", 'qv("1.2") == "1.2.0"' ); $version = qv(1.2); - cmp_ok ( $version, "eq", "v1.2.0", 'qv(1.2) eq "1.2.0"' ); + is ( "$version", "v1.2", 'qv(1.2) == "1.2.0"' ); isa_ok( qv('5.008'), $CLASS ); } @@ -283,21 +262,21 @@ SKIP: { ok ($new_version == $version, "class->new($version) identical"); $new_version = $version->new(); isa_ok ($new_version, $CLASS ); - is ($new_version, "0.000", "version->new() doesn't clone"); + is ($new_version, "0", "version->new() doesn't clone"); $new_version = $version->new("1.2.3"); - is ($new_version, "v1.2.3" , '$version->new("1.2.3") works too'); + is ($new_version, "1.2.3" , '$version->new("1.2.3") works too'); # test the CVS revision mode diag "testing CVS Revision" if $Verbose; $version = new $CLASS qw$Revision: 1.2$; - ok ( $version eq "1.2.0", 'qw$Revision: 1.2$ eq 1.2.0' ); + ok ( $version == "1.2.0", 'qw$Revision: 1.2$ == 1.2.0' ); $version = new $CLASS qw$Revision: 1.2.3.4$; - ok ( $version eq "1.2.3.4", 'qw$Revision: 1.2.3.4$ eq 1.2.3.4' ); + ok ( $version == "1.2.3.4", 'qw$Revision: 1.2.3.4$ == 1.2.3.4' ); # test the CPAN style reduced significant digit form diag "testing CPAN-style versions" if $Verbose; $version = $CLASS->new("1.23_01"); - is ( "$version" , "1.23_0100", "CPAN-style alpha version" ); + is ( "$version" , "1.23_01", "CPAN-style alpha version" ); ok ( $version > 1.23, "1.23_01 > 1.23"); ok ( $version < 1.24, "1.23_01 < 1.24"); @@ -313,14 +292,14 @@ SKIP: { print F "package aaa;\n\$aaa::VERSION=0.58;\n1;\n"; close F; - $version = 0.58; $version = sprintf("%.3f",$version); + $version = 0.58; eval "use lib '.'; use aaa $version"; unlike($@, qr/aaa version $version/, 'Replacement eval works with exact version'); # test as class method $new_version = "aaa"->VERSION; - cmp_ok($new_version,'eq',$version, "Called as class method"); + cmp_ok($new_version,'==',$version, "Called as class method"); eval "print Completely::Unknown::Module->VERSION"; if ( $] < 5.008 ) { @@ -333,7 +312,7 @@ SKIP: { } # this should fail even with old UNIVERSAL::VERSION - $version += 0.01; $version = sprintf("%.3f",$version); + $version += 0.01; eval "use lib '.'; use aaa $version"; like($@, qr/aaa version $version/, 'Replacement eval works with incremented version'); @@ -345,7 +324,7 @@ SKIP: { 'Replacement eval works with single digit'); # this would fail with old UNIVERSAL::VERSION - $version += 0.1; $version = sprintf("%.3f",$version); + $version += 0.1; eval "use lib '.'; use aaa $version"; like($@, qr/aaa version $version/, 'Replacement eval works with incremented digit'); @@ -404,15 +383,14 @@ SKIP: { if $] < 5.006_000; diag "Tests with v-strings" if $Verbose; $version = $CLASS->new(1.2.3); - ok("$version" eq "v1.2.3", '"$version" eq 1.2.3'); + ok("$version" == "v1.2.3", '"$version" == 1.2.3'); $version = $CLASS->new(1.0.0); $new_version = $CLASS->new(1); ok($version == $new_version, '$version == $new_version'); - ok($version eq $new_version, '$version eq $new_version'); skip "version require'd instead of use'd, cannot test qv", 1 if defined $no_qv; $version = qv(1.2.3); - ok("$version" eq "v1.2.3", 'v-string initialized qv()'); + ok("$version" == "v1.2.3", 'v-string initialized qv()'); } diag "Tests with real-world (malformed) data" if $Verbose; @@ -436,8 +414,8 @@ SKIP: { ok($version->numify eq "1.700", "leading space ignored"); # RT 19517 - deal with undef and 'undef' initialization - ok($version ne 'undef', "Undef version comparison #1"); - ok($version ne undef, "Undef version comparison #2"); + ok("$version" ne 'undef', "Undef version comparison #1"); + ok("$version" ne undef, "Undef version comparison #2"); $version = $CLASS->new('undef'); unlike($warning, qr/^Version string 'undef' contains invalid data/, "Version string 'undef'"); @@ -445,12 +423,12 @@ SKIP: { $version = $CLASS->new(undef); like($warning, qr/^Use of uninitialized value/, "Version string 'undef'"); - ok($version eq 'undef', "Undef version comparison #3"); - ok($version eq undef, "Undef version comparison #4"); + ok($version == 'undef', "Undef version comparison #3"); + ok($version == undef, "Undef version comparison #4"); eval "\$version = \$CLASS->new()"; # no parameter at all unlike($@, qr/^Bizarre copy of CODE/, "No initializer at all"); - ok($version eq 'undef', "Undef version comparison #5"); - ok($version eq undef, "Undef version comparison #6"); + ok($version == 'undef', "Undef version comparison #5"); + ok($version == undef, "Undef version comparison #6"); $version = $CLASS->new(0.000001); unlike($warning, qr/^Version string '1e-06' contains invalid data/, @@ -471,10 +449,10 @@ EOF like ($@, qr/^www version 0.000008 required/, "Make sure very small versions don't freak"); eval "use lib '.'; use www 1;"; - like ($@, qr/^www version 1.000 required/, + like ($@, qr/^www version 1 required/, "Comparing vs. version with no decimal"); eval "use lib '.'; use www 1.;"; - like ($@, qr/^www version 1.000 required/, + like ($@, qr/^www version 1 required/, "Comparing vs. version with decimal only"); if ( $] < 5.006_000 ) { @@ -488,7 +466,7 @@ EOF $regex =~ s/8/4/; # set for second test eval "use lib '.'; use www v0.0.4;"; unlike($@, qr/$regex/, 'Succeed - required == VERSION'); - cmp_ok ( "www"->VERSION, 'eq', '0.000004', 'No undef warnings' ); + cmp_ok ( "www"->VERSION, 'eq', '0.0.4', 'No undef warnings' ); unlink 'www.pm'; } @@ -547,7 +525,7 @@ SKIP: { my $v = $CLASS->new($ver); unlike($warning,qr/Version string '1,23' contains invalid data/, "Process locale-dependent floating point"); - is ($v, "1.230", "Locale doesn't apply to version objects"); + is ($v, "1.23", "Locale doesn't apply to version objects"); ok ($v == $ver, "Comparison to locale floating point"); } |