new#
Build a version object from any recognisable version string.
Synopsis#
my $v = version->new("1.0203");
my $v = version->parse("v1.2.3");
parse is an alias for new; the two are interchangeable. The
argument may be a decimal ("1.0203"), a dotted-integer
("1.2.3"), or a v-string ("v1.23.45"). Whichever form goes in,
$v understands all the comparison operators and prints back in
the form it came from.
What you get back#
A blessed version object. It is numeric, stringly, and boolean
all at once thanks to overloading: compare it with == or <=>,
concatenate it into a string, test it with if ($v). To pull the
normalised numeric form out as a plain Perl number, call numify;
for the canonical v1.2.3 string, call normal.
Examples#
A decimal version behaves the way old-style $VERSION did:
my $v = version->new("1.0203");
print $v; # 1.0203
print $v->numify; # 1.020300
A dotted-integer version keeps its components intact:
my $v = version->new("1.2.3");
print $v->normal; # v1.2.3
print $v->numify; # 1.002003
Cross-form comparison works — the whole point of the module:
version->new("1.2.3") == version->new("1.002003"); # true
An underscore marks an alpha release:
my $v = version->new("1.02_03");
print $v->is_alpha; # 1
Edge cases#
Called with no version argument — returns a version equivalent to
"0".Leading whitespace and a single leading
vare both accepted.Invocation as
version::new("version", $str)is accepted; the first argument is treated as the class name.
Differences from upstream#
Fully compatible with upstream version 0.9929.
See also#
declare— same idea, but always produces a dotted-integer objectqv— alias fordeclare, handy inside$VERSIONlinesnumify— plain-number form of an existing objectnormal— canonicalv1.2.3form of an existing objectis_alpha— test whether the string carried an underscore