NAME
version - Perl extension for Version Objects
SYNOPSIS
# Parsing version strings (decimal or dotted-decimal)
use version;
$ver = version->parse($string)
# Declaring a dotted-decimal $VERSION (keep on one line!)
use version; our $VERSION = version->declare("v1.2.3"); # formal
use version; our $VERSION = qv("v1.2.3"); # shorthand
use version; our $VERSION = qv("v1.2_3"); # alpha
# Declaring an old-style decimal $VERSION (use quotes!)
use version; our $VERSION = version->parse("1.0203"); # formal
use version; our $VERSION = version->parse("1.02_03"); # alpha
# Comparing mixed version styles (decimals, dotted-decimals, objects)
if ( version->parse($v1) == version->parse($v2) ) {
# do stuff
}
# Sorting mixed version styles
@ordered = sort { version->parse($a) <=> version->parse($b) } @list;
DESCRIPTION
Overloaded version objects for all modern versions of Perl. This module implements all of the features of version objects which are part of Perl 5.10.0. All previous releases (i.e. before 0.74) are deprecated and should not be used due to incompatible API changes. If you 'use version' in your code, you are strongly urged to set a minimum, e.g.
use version 0.74; # to remain compatible with Perl v5.10.0
If you use either of the two new methods, <version-
parse>> or <version-
declare>>, you must use this instead:
use version 0.77; # requires an update even for Perl v.5.10.0
For CPAN Authors
If you have a module that uses a decimal $VERSION (floating point), and you do not intend to ever change that, this module is not for you. There is nothing that version.pm gains you over a simple $VERSION assignment:
our $VERSION = 1.02;
and since Perl v5.10.0 includes the version.pm comparison logic anyways, you don't need to do anything at all.
If you have used a decimal $VERSION in the past and wish to switch to a dotted-decimal $VERSION, then you need to make a one-time conversion to the new format. IMPORTANT NOTE: you must ensure that your new $VERSION is numerically greater than your current decimal $VERSION; this is not always obvious. See "Comparing Different Versions" for details. The PAUSE script will enforce this stricture, but you should understand the reasoning behind the conversion. Once you convert, you are free to increment $VERSION to your heart's content.
If you have always used a dotted-decimal $VERSION for your module releases, then version.pm is the way to ensure that this $VERSION works in any release of Perl from 5.005_04 to the present.
No matter which type of $VERSION you use with version.pm, if you quote your initializer, then whatever you type in will be exactly what comes out when your $VERSION is printed (stringified). If you do not quote your value, Perl's normal numeric handling comes into play and you may not get back what you were expecting. See "Quoting Rules" for more details.
Types of version objects
There are two different types of version objects, corresponding to the two different styles of versions in use:
Converting between Decimal and Dotted-Decimal Versions
When Perl 5.6.0 was released, the decision was made to provide a transformation between the old-style decimal versions and new-style dotted-decimal versions:
5.6.0 == 5.006000
5.005_04 == 5.5.40
The floating point number is taken and split first on the single decimal place, then each group of three digits to the right of the decimal makes up the next digit, and so on until the number of significant digits is exhausted, plus enough trailing zeros to reach the next multiple of three.
IMPORTANT NOTE: There is no significance to the underscore in the last example above. Perl has always allowed you to included underscores in bare numbers (not quoted) for visual formatting purposes. So these are all equivalent:
$v1 = 1.000000;
$v2 = 1.000_000;
$v3 = 1.0_0_0_0_0_0;
What is important is that 5.005_04 == 5.00504 == 5.005040. And hence 5.005_04 == 5.5.40.
This was the method that version.pm adopted as well. The internal representation of a version object is discussed in version::Internals, but suffice it to say that for comparison purposes, all version objects are compared as an array of digits.
Some examples may be helpful:
equivalent
decimal zero-padded dotted-decimal
------- ----------- --------------
1.2 1.200 v1.200.0
1.02 1.020 v1.20.0
1.002 1.002 v1.2.0
1.0023 1.002300 v1.2.300
1.00203 1.002030 v1.2.30
1.002003 1.002003 v1.2.3
Since many CPAN authors have used a 2 digit decimal $VERSION, they can be surprised to discover that the equivalent dotted-decimal version appears to be 10 times larger than they expected. For this reason, if you are converting from a decimal to a dotted-decimal $VERSION, it is best if you bump the major release:
Old $VERSION = 1.13;
New $VERSION = 2.0.0;
to prevent any confusion.
Quoting Rules
Because of the nature of the Perl parsing and tokenizing routines, certain initialization values must be quoted in order to correctly parse as the intended version, especially when using the declare or qv methods. While you do not have to quote decimal numbers when creating version objects, it is always safe to quote all initial values when using version.pm methods, as this will ensure that what you type is what is used.
If you use a mathematic formula that resolves to a floating point number, you are dependent on Perl's conversion routines to yield the version you expect. You are pretty safe by dividing by a power of 10, for example, but other operations are not likely to be what you intend. For example:
$VERSION = version->new((qw$Revision: 1.4)[1]/10);
print $VERSION; # yields 0.14
$V2 = version->new(100/9); # Integer overflow in decimal number
print $V2; # yields something like 11.111.111.100
Perl 5.8.1 and beyond are able to automatically quote v-strings but that is not possible in earlier versions of Perl. In other words:
$version = version->new("v2.5.4"); # legal in all versions of Perl
$newvers = version->new(v2.5.4); # legal only in Perl >= 5.8.1
What about v-strings?
There are two ways to enter v-strings: a bare number with two or more decimal points, or a bare number with one or more decimal points and a 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 bare v-strings to initialize version objects is strongly 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 "Dotted Decimal 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 must 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.
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.
CLASS METHODS
- parse
-
This is the generic way to create version objects, equivalent to using <version-new()>>. No special interpretation of the value is done; what you type is what you get (as long as you quote the value). You can use this to create version objects using either decimal or dotted-decimal (with or without leading 'v').
- declare
-
This method always creates dotted-decimal version objects and is equivalent to the exported qv function. Even if you pass in what looks like a decimal number, a dotted-decimal will be formed, using the rules given in the discussion about "Converting between Decimal and Dotted-Decimal Versions" above. For this reason, you are STRONGLY encouraged to always pass a dotted-decimal, e.g.
<version-
declare("1.2.3")>>, so that there is no opportunity for confusion. - new
-
Equivalent to <version-parse()>>, use of this method is no longer encouraged.
- qv
-
A class method equivalent to the exported qv function; you are urged to use <version-declare()>> instead for future development.
- is_qv
-
True only if the version object is a dotted-decimal version, e.g.
version->parse('1.2.0') == qv('1.2') == version->declare('v1.2');
- is_alpha
-
True if and only if the version object was created with a underscore, e.g.
version->parse('1.002_03'); version->declare('1.2.3_4');
EXPORT
qv - Dotted Decimal Version initialization operator
This function is no longer recommended for use, but is maintained for compatibility with existing code. If you do not want to have it exported to your namespace, use this form:
use version 0.77 ();
AUTHOR
John Peacock <jpeacock@cpan.org>
SEE ALSO
perl.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 89:
You forgot a '=back' before '=head2'