version#
Turn a version string into an object you can compare, print, and introspect.
Perl has three spellings for a version, and mixing them in one program is normal. version gives you a single object type that handles all three so $a <=> $b always does the right thing.
Decimal - a plain number like
1.023or"1.02_03". One integer part, then three-digit chunks after the dot. An underscore marks an alpha release.Dotted-integer - two or more integers separated by dots, e.g.
1.2.3. Novprefix required, but three or more components are treated as dotted-integer regardless.v-string - an explicit
vprefix, e.g.v1.23.45. This form is recommended for$VERSIONdeclarations and is required to passis_strict.
Synopsis#
use version 0.77;
our $VERSION = version->declare("v1.2.3");
my $v = version->parse("1.0203");
if ($v1 == $v2) { ... } # numeric equality
@sorted = sort { $a <=> $b } @versions; # ordering
use version imports qv into the caller’s package and installs an overloaded UNIVERSAL::VERSION so $module->VERSION returns a version object rather than a raw string.
Operators#
version objects are overloaded so you can use the normal Perl comparison operators directly:
==,!=- numeric equality<,<=,>,>=,<=>- numeric orderingeq,ne,cmp- same thing, stringwise spelling""- stringifies to original form (dotted) or decimal, whichever the object was created with0+- numifies to a decimal
The overload fallback is on, so any relational operator not listed above works by auto-generation from <=>.
Functions#
Introspection#
is_lax#
Test whether a string is acceptable to parse / new as a version.
is_strict#
Test whether a string is a strict version suitable for CPAN indexing.