Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

version

Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.

Native implementation of the version module

Provides version object parsing, comparison, and stringification. The perl5 version module is XS-based — this native implementation provides the core methods needed by modules like experimental.

Supported API

  • version->new("1.23") / version->new(v1.2.3)
  • version->parse("1.23")
  • version->declare("v1.2.3")
  • $v->numify / $v->stringify / $v->normal
  • $v->is_alpha / $v->is_qv
  • Comparison via <=> and cmp (overloaded)

Functions

_VERSION

boolean

Overload handler for boolean context; returns true if any version part is non-zero.

use version;
my $v = version->new("0.0.0");
if ($v) { ... }  # false

See also: vcmp, numify

declare

Parses a version string as dotted-decimal (v-string) form.

use version;
my $v = version->declare("v1.2.3");
my $v = version->declare("1.2.3");  # auto-prefixed with v

See also: new, qv

import

Sets up UNIVERSAL::VERSION override to use version.pm comparison logic.

use version;

See also: _VERSION, new

is_alpha

Returns true if the version contains an underscore (alpha/dev release).

use version;
my $v = version->new("1.23_01");
print $v->is_alpha;  # 1

See also: is_qv

is_qv

Returns true if the version was created in dotted-decimal (v-string) form.

use version;
my $v = version->new("v1.2.3");
print $v->is_qv;  # 1

See also: is_alpha

new

Constructs a new version object from a version string or number.

use version;
my $v = version->new("1.23");
my $v = version->new("v1.2.3");

See also: parse, declare, qv

noop

Overload fallback handler; returns undef for unsupported operations.

use version;
# Called internally when an unsupported operator is applied

See also: vcmp, boolean, stringify

normal

Returns the normalized dotted-decimal form (e.g., “v1.2.3”).

use version;
my $v = version->new("1.002003");
print $v->normal;  # "v1.2.3"

See also: numify, stringify

numify

Returns the numeric representation of the version (e.g., “1.002003”).

use version;
my $v = version->new("v1.2.3");
print $v->numify;  # "1.002003"

See also: stringify, normal

overload_cmp

Overload handler for version comparison operators, delegates to vcmp().

use version;
my $v1 = version->new("1.2");
if ($v1 > version->new("1.0")) { ... }

See also: vcmp, native_overload_stringify

overload_stringify

Overload handler for string interpolation, delegates to stringify().

use version;
my $v = version->new("1.23");
print "$v";

See also: stringify, native_overload_cmp

parse

Parses a version string into a version object, identical to new().

use version;
my $v = version->parse("1.23");

See also: new, declare

qv

Constructs a version object in dotted-decimal form, alias for declare().

use version;
my $v = version::qv("1.2.3");

See also: declare, new

stringify

Returns the string representation of the version, used by overloaded “”.

use version;
my $v = version->new("v1.2.3");
print "$v";  # "v1.2.3"

See also: numify, normal

vcmp

Compares two version objects, returning -1, 0, or 1 (spaceship operator).

use version;
my $v1 = version->new("1.2");
my $v2 = version->new("1.3");
print $v1 <=> $v2;  # -1

See also: new, stringify

version_check

Replacement for UNIVERSAL::VERSION that uses version.pm comparison logic.

use version;
Foo->VERSION("1.23");  # dies if Foo's $VERSION < 1.23

See also: vcmp, new, import