From: John Peacock Date: Mon, 12 Feb 2007 21:51:23 +0000 (-0500) Subject: Fwd: CPAN Upload: J/JP/JPEACOCK/version-0.70.tar.gz X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f34c6aafbe054cce2cb8b032aa4ab346b5feaf96;p=p5sagit%2Fp5-mst-13.2.git Fwd: CPAN Upload: J/JP/JPEACOCK/version-0.70.tar.gz Message-ID: <45D127AB.3050904@rowman.com> p4raw-id: //depot/perl@30254 --- diff --git a/lib/version.pm b/lib/version.pm index 3291973..85be41d6 100644 --- a/lib/version.pm +++ b/lib/version.pm @@ -6,7 +6,7 @@ use strict; use vars qw(@ISA $VERSION $CLASS *qv); -$VERSION = 0.69; +$VERSION = "0.70"; $CLASS = 'version'; diff --git a/lib/version.pod b/lib/version.pod index 6874fa2..b0dcc84 100644 --- a/lib/version.pod +++ b/lib/version.pod @@ -158,7 +158,7 @@ if required: $v = version->new(1.002); # 1.002, but compares like 1.2.0 $v = version->new(1.002003); # 1.002003 - $v2 = version->new( "1.2.3"); # v1.2.3 + $v2 = version->new("1.2.3"); # v1.2.3 In specific, version numbers initialized as L will stringify in Numeric form. Version numbers initialized as L @@ -209,7 +209,7 @@ a single decimal point, e.g.: # Prints $v = version->new( "v1.200"); # v1.200.0 $v = version->new("v1.20.0"); # v1.20.0 - $v = qv("v1.2.3); # v1.2.3 + $v = qv("v1.2.3"); # v1.2.3 $v = qv("1.2.3"); # v1.2.3 $v = qv("1.20"); # v1.20.0 @@ -248,7 +248,10 @@ equivalent and sorts alpha-numerically as would be expected. Overloading has been used with version objects to provide a natural interface for their use. All mathematical operations are forbidden, -since they don't make any sense for base version objects. +since they don't make any sense for base version objects. Consequently, +there is no overloaded numification available. If you want to use a +version object in a numeric context for some reason, see the L +object method. =over 4 @@ -284,9 +287,15 @@ object, either as a class method: or as an object method: $v1 = version->new(12.3); + $v2 = $v1->new(12.3); + +and in each case, $v1 and $v2 will be identical. NOTE: if you create +a new object using an existing object like this: + $v2 = $v1->new(); -and in each case, $v1 and $v2 will be identical. +the new object B be a clone of the existing object. In the +example case, $v2 will be an empty object of the same type as $v1. =back @@ -512,13 +521,22 @@ leading 'v' character (also bare). For example: $vs1 = 1.2.3; # encoded as \1\2\3 $vs2 = v1.2; # encoded as \1\2 -However, the use of v-strings to initialize version objects with this -module is only possible with Perl 5.8.1 or better (which contain special -code to enable it). Their use is B discouraged in all -circumstances (especially the leading 'v' style), since the meaning will -change depending on which Perl you are running. It is better to directly -use L<"Extended Versions"> to ensure the proper interpretation. +However, the use of bare v-strings to initialize version objects is +B discouraged in all circumstances (especially the leading +'v' style), since the meaning will change depending on which Perl you +are running. It is better to directly use L<"Extended Versions"> to +ensure the proper interpretation. + +If you insist on using bare v-strings with Perl > 5.6.0, be aware of the +following limitations: +1) For Perl releases 5.6.0 through 5.8.0, the v-string code merely guesses, +based on some characteristics of v-strings. You B use a three part +version, e.g. 1.2.3 or v1.2.3 in order for this heuristic to be successful. + +2) For Perl releases 5.8.1 and later, v-strings have changed in the Perl +core to be magical, which means that the version.pm code can automatically +determine whether the v-string encoding was used. =head2 Types of Versions Objects @@ -571,6 +589,8 @@ trailing (or leading) zeros, in the L form. For example, $newver = version->new("12.3.1_1"); print $newver; # v12.3.1_1 +=back + =head2 Replacement UNIVERSAL::VERSION In addition to the version objects, this modules also replaces the core diff --git a/lib/version.t b/lib/version.t index bb5a8f8..2438a30 100644 --- a/lib/version.t +++ b/lib/version.t @@ -119,6 +119,7 @@ sub BaseTests { "Version string contains invalid data; ignoring"); # from here on out capture the warning and test independently + { my $warning; local $SIG{__WARN__} = sub { $warning = $_[0] }; $version = $CLASS->new("99 and 44/100 pure"); @@ -302,56 +303,73 @@ SKIP: { # test reformed UNIVERSAL::VERSION diag "Replacement UNIVERSAL::VERSION tests" if $Verbose; + + my $error_regex = $] < 5.006 + ? 'version \d required' + : 'does not define \$...::VERSION'; - # we know this file is here since we require it ourselves - $version = $Test::More::VERSION; - eval "use Test::More $version"; - unlike($@, qr/Test::More version $version/, - 'Replacement eval works with exact version'); - - # test as class method - $new_version = Test::More->VERSION; - cmp_ok($new_version,'cmp',$version, "Called as class method"); - - # this should fail even with old UNIVERSAL::VERSION - $version = $Test::More::VERSION+0.01; - eval "use Test::More $version"; - like($@, qr/Test::More version $version/, - 'Replacement eval works with incremented version'); - - TODO: { - local $TODO = "Test fails with Test::More versions ending in _0X"; - $version =~ s/\.0$//; #convert to string and remove trailing '.0' - chop($version); # shorten by 1 digit, should still succeed - eval "use Test::More $version"; - unlike($@, qr/Test::More version $version/, - 'Replacement eval works with single digit'); - } + { + open F, ">aaa.pm" or die "Cannot open aaa.pm: $!\n"; + print F "package aaa;\n\$aaa::VERSION=0.58;\n1;\n"; + close F; + + $version = 0.58; $version = sprintf("%.3f",$version); + 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"); - $version += 0.1; # this would fail with old UNIVERSAL::VERSION - eval "use Test::More $version"; - like($@, qr/Test::More version $version/, - 'Replacement eval works with incremented digit'); + eval "print Completely::Unknown::Module->VERSION"; + if ( $] < 5.008 ) { + unlike($@, qr/$error_regex/, + "Don't freak if the module doesn't even exist"); + } + else { + unlike($@, qr/defines neither package nor VERSION/, + "Don't freak if the module doesn't even exist"); + } + + # this should fail even with old UNIVERSAL::VERSION + $version += 0.01; $version = sprintf("%.3f",$version); + eval "use lib '.'; use aaa $version"; + like($@, qr/aaa version $version/, + 'Replacement eval works with incremented version'); + + $version =~ s/0+$//; #convert to string and remove trailing 0's + chop($version); # shorten by 1 digit, should still succeed + eval "use lib '.'; use aaa $version"; + unlike($@, qr/aaa version $version/, + 'Replacement eval works with single digit'); + + # this would fail with old UNIVERSAL::VERSION + $version += 0.1; $version = sprintf("%.3f",$version); + eval "use lib '.'; use aaa $version"; + like($@, qr/aaa version $version/, + 'Replacement eval works with incremented digit'); + unlink 'aaa.pm'; + } { # dummy up some variously broken modules for testing open F, ">xxx.pm" or die "Cannot open xxx.pm: $!\n"; print F "1;\n"; close F; - my $error_regex; + + eval "use lib '.'; use xxx 3;"; if ( $] < 5.008 ) { - $error_regex = 'xxx does not define \$xxx::VERSION'; + like($@, qr/$error_regex/, + 'Replacement handles modules without package or VERSION'); } else { - $error_regex = 'xxx defines neither package nor VERSION'; + like($@, qr/defines neither package nor VERSION/, + 'Replacement handles modules without package or VERSION'); } - - eval "use lib '.'; use xxx 3;"; - like ($@, qr/$error_regex/, - 'Replacement handles modules without package or VERSION'); - eval "use lib '.'; use xxx; $version = xxx->VERSION"; + eval "use lib '.'; use xxx; \$version = xxx->VERSION"; unlike ($@, qr/$error_regex/, 'Replacement handles modules without package or VERSION'); - ok (defined($version), "Called as class method"); + ok (!defined($version), "Called as class method"); unlink 'xxx.pm'; } @@ -360,10 +378,10 @@ SKIP: { print F "package yyy;\n#look ma no VERSION\n1;\n"; close F; eval "use lib '.'; use yyy 3;"; - like ($@, qr/^yyy does not define \$yyy::VERSION/, + like ($@, qr/$error_regex/, 'Replacement handles modules without VERSION'); eval "use lib '.'; use yyy; print yyy->VERSION"; - unlike ($@, qr/^yyy does not define \$yyy::VERSION/, + unlike ($@, qr/$error_regex/, 'Replacement handles modules without VERSION'); unlink 'yyy.pm'; } @@ -373,10 +391,10 @@ SKIP: { print F "package zzz;\n\@VERSION = ();\n1;\n"; close F; eval "use lib '.'; use zzz 3;"; - like ($@, qr/^zzz does not define \$zzz::VERSION/, + like ($@, qr/$error_regex/, 'Replacement handles modules without VERSION'); eval "use lib '.'; use zzz; print zzz->VERSION"; - unlike ($@, qr/^zzz does not define \$zzz::VERSION/, + unlike ($@, qr/$error_regex/, 'Replacement handles modules without VERSION'); unlink 'zzz.pm'; } @@ -437,6 +455,7 @@ SKIP: { $version = $CLASS->new(0.000001); unlike($warning, qr/^Version string '1e-06' contains invalid data/, "Very small version objects"); + } SKIP: { # dummy up a legal module for testing RT#19017 @@ -491,6 +510,8 @@ EOF SKIP: { # test locale handling + my $warning; + local $SIG{__WARN__} = sub { $warning = $_[0] }; my $ver = 1.23; # has to be floating point number my $loc; while () { @@ -509,6 +530,10 @@ SKIP: { is ($v, "1.230", "Locale doesn't apply to version objects"); ok ($v == $ver, "Comparison to locale floating point"); } + + eval 'my $v = $CLASS->new("1._1");'; + unlike($@, qr/^Invalid version format \(alpha with zero width\)/, + "Invalid version format 1._1"); } 1; diff --git a/util.c b/util.c index a8b83f7..d23dc8a 100644 --- a/util.c +++ b/util.c @@ -4141,6 +4141,9 @@ Perl_scan_version(pTHX_ const char *s, SV *rv, bool qv) if ( alpha && !saw_period ) Perl_croak(aTHX_ "Invalid version format (alpha without decimal)"); + if ( alpha && saw_period && width == 0 ) + Perl_croak(aTHX_ "Invalid version format (misplaced _ in number)"); + if ( saw_period > 1 ) qv = 1; /* force quoted version processing */