new#

Build a version object from any recognisable version string.

תקציר#

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.

מה מוחזר#

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.

דוגמאות#

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

מקרי קצה#

  • Called with no version argument - returns a version equivalent to "0".

  • Leading whitespace and a single leading v are both accepted.

  • Invocation as version::new("version", $str) is accepted; the first argument is treated as the class name.

הבדלים מן ה-upstream#

Fully compatible with upstream version 0.9929.

ראו גם#

  • declare - same idea, but always produces a dotted-integer object

  • qv - alias for declare, handy inside $VERSION lines

  • numify - plain-number form of an existing object

  • normal - canonical v1.2.3 form of an existing object

  • is_alpha - test whether the string carried an underscore