@ISA = qw(DynaLoader);
-$VERSION = (qw$Revision: 2.1 $)[1]/10;
+$VERSION = (qw$Revision: 2.2 $)[1]/10;
$CLASS = 'version';
version, as well as extending the "version as number" that is discussed
in the various editions of the Camel book.
+However, in order to be compatible with earlier Perl version styles,
+any use of versions of the form 5.006001 will be translated as 5.6.1,
+In other words a version with a single decimal place will be parsed
+as implicitely having three places between subversion.
+
+Any value passed to the new() operator will be parsed only so far as it
+contains a numeric, decimal, or underscore character. So, for example:
+
+ $v1 = new version "99 and 94/100 percent pure"; # $v1 == 99.0
+ $v2 = new version "something"; # $v2 == "" and $v2->numify == 0
+
+NOTE: it is strongly recommended that version objects only be created
+with numeric values based on the different types of versions in this
+documentation, see L<"Types of Versions Objects">. That way, there is
+no confusion about what constitutes the version.
+
=head2 Object Methods
Overloading has been used with version objects to provide a natural
your module version by using the Revision number from the primary
file in a distribution, see L<ExtUtils::MakeMaker/"VERSION_FROM">.
-In order to be compatible with earlier Perl version styles, any use
-of versions of the form 5.006001 will be translated as 5.6.1, In
-other words a version with a single decimal place will be parsed
-as implicitely having three places between subversion.
-
=item * Beta versions - For module authors using CPAN, the
convention has been to note unstable releases with an underscore
in the version string, see L<CPAN>. Beta releases will test as being
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
-# $Revision: 2.0 $
+# $Revision: 2.1 $
#########################
-use Test::More tests => 60;
+use Test::More tests => 64;
use_ok(version); # If we made it this far, we are ok.
my ($version, $new_version);
like($@, qr/underscores before decimal/,
"Invalid version format (underscores before decimal)");
+$version = new version "99 and 44/100 pure";
+ok ("$version" eq "99.0", '$version eq "99.0"');
+ok ($version->numify == 99.0, '$version->numify == 99.0');
+
+$version = new version "something";
+ok ("$version" eq "", '$version eq ""');
+ok ($version->numify == 0, '$version->numify == 99.0');
+
# Test boolean operator
ok ($version, 'boolean');
internally--subject to loss of precision errors in subsequent
operations.
+=item Integer overflow in version
+
+(F) Some portion of a version initialization is too large for the
+size of integers for your architecture. This is not a warning
+because there is no rational reason for a version to try and use a
+element larger than typically 2**32. This is usually caused by
+trying to use some odd mathematical operation as a version, like
+100/9.
+
=item Internal disaster in regex; marked by <-- HERE in m/%s/
(P) Something went badly wrong in the regular expression parser.
(W unpack) The given character is not a valid unpack type but used to be
silently ignored.
+=item Invalid version format (multiple underscores)
+
+(F) Versions may contain at most a single underscore, which signals
+that the version is a beta release. See L<version> for the allowed
+version formats.
+
+=item Invalid version format (underscores before decimal)
+
+(F) Versions may not contain decimals after the optional underscore.
+See L<version> for the allowed version formats.
+
=item ioctl is not implemented
(F) Your machine apparently doesn't implement ioctl(), which is pretty
if ( saw_under )
Perl_croak(aTHX_ "Invalid version format (underscores before decimal)");
saw_period++ ;
- }
+ }
else if ( *pos == '_' )
{
if ( saw_under )
if (*pos == 'v') pos++; /* get past 'v' */
while (isDIGIT(*pos))
- pos++;
+ pos++;
if (!isALPHA(*pos)) {
I32 rev;
mult = -1; /* beta version */
}
while (--end >= s) {
-
I32 orev;
orev = rev;
rev += (*end - '0') * mult;
break;
}
while ( isDIGIT(*pos) ) {
- if ( saw_period == 1 && pos-s == 3 )
+ if ( !saw_under && saw_period == 1 && pos-s == 3 )
break;
pos++;
}
if ( SvROK(vs) )
vs = SvRV(vs);
len = av_len((AV *)vs);
+ if ( len == -1 )
+ {
+ Perl_sv_catpv(aTHX_ sv,"0");
+ return sv;
+ }
digit = SvIVX(*av_fetch((AV *)vs, 0, 0));
Perl_sv_setpvf(aTHX_ sv,"%d.",abs(digit));
for ( i = 1 ; i <= len ; i++ )
if ( SvROK(vs) )
vs = SvRV(vs);
len = av_len((AV *)vs);
+ if ( len == -1 )
+ {
+ Perl_sv_catpv(aTHX_ sv,"");
+ return sv;
+ }
digit = SvIVX(*av_fetch((AV *)vs, 0, 0));
Perl_sv_setpvf(aTHX_ sv,"%d",digit);
for ( i = 1 ; i <= len ; i++ )
-{
+ {
digit = SvIVX(*av_fetch((AV *)vs, i, 0));
if ( digit < 0 )
Perl_sv_catpvf(aTHX_ sv,"_%d",-digit);