```{index} single: new; version function ``` ```{index} single: version::new; Perl function ``` # new Build a version object from any recognisable version string. ## Synopsis ```perl 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: ```perl my $v = version->new("1.0203"); print $v; # 1.0203 print $v->numify; # 1.020300 ``` A dotted-integer version keeps its components intact: ```perl 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: ```perl version->new("1.2.3") == version->new("1.002003"); # true ``` An underscore marks an alpha release: ```perl 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 `v` are 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 {{ upstream.version }}. ## See also - `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