| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "version 3perl" |
| 58 |
.TH version 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
version \- Perl extension for Version Objects |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& # Parsing version strings (decimal or dotted\-decimal) |
| 69 |
\& |
| 70 |
\& use version 0.77; # get latest bug\-fixes and API |
| 71 |
\& $ver = version\->parse($string) |
| 72 |
\& |
| 73 |
\& # Declaring a dotted\-decimal $VERSION (keep on one line!) |
| 74 |
\& |
| 75 |
\& use version; our $VERSION = version\->declare("v1.2.3"); # formal |
| 76 |
\& use version; our $VERSION = qv("v1.2.3"); # deprecated |
| 77 |
\& use version; our $VERSION = qv("v1.2_3"); # deprecated |
| 78 |
\& |
| 79 |
\& # Declaring an old\-style decimal $VERSION (use quotes!) |
| 80 |
\& |
| 81 |
\& our $VERSION = "1.0203"; # recommended |
| 82 |
\& use version; our $VERSION = version\->parse("1.0203"); # formal |
| 83 |
\& use version; our $VERSION = version\->parse("1.02_03"); # alpha |
| 84 |
\& |
| 85 |
\& # Comparing mixed version styles (decimals, dotted\-decimals, objects) |
| 86 |
\& |
| 87 |
\& if ( version\->parse($v1) == version\->parse($v2) ) { |
| 88 |
\& # do stuff |
| 89 |
\& } |
| 90 |
\& |
| 91 |
\& # Sorting mixed version styles |
| 92 |
\& |
| 93 |
\& @ordered = sort { version\->parse($a) <=> version\->parse($b) } @list; |
| 94 |
.Ve |
| 95 |
.SH DESCRIPTION |
| 96 |
.IX Header "DESCRIPTION" |
| 97 |
Version objects were added to Perl in 5.10. This module implements version |
| 98 |
objects for older version of Perl and provides the version object API for all |
| 99 |
versions of Perl. All previous releases before 0.74 are deprecated and should |
| 100 |
not be used due to incompatible API changes. Version 0.77 introduces the new |
| 101 |
\&'parse' and 'declare' methods to standardize usage. You are strongly urged to |
| 102 |
set 0.77 as a minimum in your code, e.g. |
| 103 |
.PP |
| 104 |
.Vb 1 |
| 105 |
\& use version 0.77; # even for Perl v.5.10.0 |
| 106 |
.Ve |
| 107 |
.SH "TYPES OF VERSION OBJECTS" |
| 108 |
.IX Header "TYPES OF VERSION OBJECTS" |
| 109 |
There are two different types of version objects, corresponding to the two |
| 110 |
different styles of versions in use: |
| 111 |
.IP "Decimal Versions" 2 |
| 112 |
.IX Item "Decimal Versions" |
| 113 |
The classic floating-point number \f(CW$VERSION\fR. The advantage to this style is |
| 114 |
that you don't need to do anything special, just type a number into your |
| 115 |
source file. Quoting is recommended, as it ensures that trailing zeroes |
| 116 |
("1.50") are preserved in any warnings or other output. |
| 117 |
.IP "Dotted Decimal Versions" 2 |
| 118 |
.IX Item "Dotted Decimal Versions" |
| 119 |
The more modern form of version assignment, with 3 (or potentially more) |
| 120 |
integers separated by decimal points (e.g. v1.2.3). This is the form that |
| 121 |
Perl itself has used since 5.6.0 was released. The leading 'v' is now |
| 122 |
strongly recommended for clarity, and will throw a warning in a future |
| 123 |
release if omitted. A leading 'v' character is required to pass the |
| 124 |
"\fBis_strict()\fR" test. |
| 125 |
.SH "DECLARING VERSIONS" |
| 126 |
.IX Header "DECLARING VERSIONS" |
| 127 |
If you have a module that uses a decimal \f(CW$VERSION\fR (floating point), and you |
| 128 |
do not intend to ever change that, this module is not for you. There is |
| 129 |
nothing that version.pm gains you over a simple \f(CW$VERSION\fR assignment: |
| 130 |
.PP |
| 131 |
.Vb 1 |
| 132 |
\& our $VERSION = "1.02"; |
| 133 |
.Ve |
| 134 |
.PP |
| 135 |
Since Perl v5.10.0 includes the version.pm comparison logic anyways, |
| 136 |
you don't need to do anything at all. |
| 137 |
.SS "How to convert a module from decimal to dotted-decimal" |
| 138 |
.IX Subsection "How to convert a module from decimal to dotted-decimal" |
| 139 |
If you have used a decimal \f(CW$VERSION\fR in the past and wish to switch to a |
| 140 |
dotted-decimal \f(CW$VERSION\fR, then you need to make a one-time conversion to |
| 141 |
the new format. |
| 142 |
.PP |
| 143 |
\&\fBImportant Note\fR: you must ensure that your new \f(CW$VERSION\fR is numerically |
| 144 |
greater than your current decimal \f(CW$VERSION\fR; this is not always obvious. First, |
| 145 |
convert your old decimal version (e.g. 1.02) to a normalized dotted-decimal |
| 146 |
form: |
| 147 |
.PP |
| 148 |
.Vb 2 |
| 149 |
\& $ perl \-Mversion \-e \*(Aqprint version\->parse("1.02")\->normal\*(Aq |
| 150 |
\& v1.20.0 |
| 151 |
.Ve |
| 152 |
.PP |
| 153 |
Then increment any of the dotted-decimal components (v1.20.1 or v1.21.0). |
| 154 |
.ie n .SS "How to declare() a dotted-decimal version" |
| 155 |
.el .SS "How to \f(CWdeclare()\fP a dotted-decimal version" |
| 156 |
.IX Subsection "How to declare() a dotted-decimal version" |
| 157 |
.Vb 1 |
| 158 |
\& use version; our $VERSION = version\->declare("v1.2.3"); |
| 159 |
.Ve |
| 160 |
.PP |
| 161 |
The \f(CWdeclare()\fR method always creates dotted-decimal version objects. When |
| 162 |
used in a module, you \fBmust\fR put it on the same line as "use version" to |
| 163 |
ensure that \f(CW$VERSION\fR is read correctly by PAUSE and installer tools. You |
| 164 |
should also add 'version' to the 'configure_requires' section of your |
| 165 |
module metadata file. See instructions in ExtUtils::MakeMaker or |
| 166 |
Module::Build for details. |
| 167 |
.PP |
| 168 |
\&\fBImportant Note\fR: Even if you pass in what looks like a decimal number |
| 169 |
("1.2"), a dotted-decimal will be created ("v1.200.0"). To avoid confusion |
| 170 |
or unintentional errors on older Perls, follow these guidelines: |
| 171 |
.IP \(bu 2 |
| 172 |
Always use a dotted-decimal with (at least) three components |
| 173 |
.IP \(bu 2 |
| 174 |
Always use a leading-v |
| 175 |
.IP \(bu 2 |
| 176 |
Always quote the version |
| 177 |
.PP |
| 178 |
If you really insist on using version.pm with an ordinary decimal version, |
| 179 |
use \f(CWparse()\fR instead of declare. See the "PARSING AND COMPARING VERSIONS" |
| 180 |
for details. |
| 181 |
.PP |
| 182 |
See also version::Internals for more on version number conversion, |
| 183 |
quoting, calculated version numbers and declaring developer or "alpha" version |
| 184 |
numbers. |
| 185 |
.SH "PARSING AND COMPARING VERSIONS" |
| 186 |
.IX Header "PARSING AND COMPARING VERSIONS" |
| 187 |
If you need to compare version numbers, but can't be sure whether they are |
| 188 |
expressed as numbers, strings, v\-strings or version objects, then you should |
| 189 |
use version.pm to parse them all into objects for comparison. |
| 190 |
.ie n .SS "How to parse() a version" |
| 191 |
.el .SS "How to \f(CWparse()\fP a version" |
| 192 |
.IX Subsection "How to parse() a version" |
| 193 |
The \f(CWparse()\fR method takes in anything that might be a version and returns |
| 194 |
a corresponding version object, doing any necessary conversion along the way. |
| 195 |
.IP \(bu 2 |
| 196 |
Dotted-decimal: bare v\-strings (v1.2.3) and strings with more than one |
| 197 |
decimal point and a leading 'v' ("v1.2.3"); NOTE you can technically use a |
| 198 |
v\-string or strings with a leading-v and only one decimal point (v1.2 or |
| 199 |
"v1.2"), but you will confuse both yourself and others. |
| 200 |
.IP \(bu 2 |
| 201 |
Decimal: regular decimal numbers (literal or in a string) |
| 202 |
.PP |
| 203 |
Some examples: |
| 204 |
.PP |
| 205 |
.Vb 8 |
| 206 |
\& $variable version\->parse($variable) |
| 207 |
\& \-\-\-\-\-\-\-\-\- \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- |
| 208 |
\& 1.23 v1.230.0 |
| 209 |
\& "1.23" v1.230.0 |
| 210 |
\& v1.23 v1.23.0 |
| 211 |
\& "v1.23" v1.23.0 |
| 212 |
\& "1.2.3" v1.2.3 |
| 213 |
\& "v1.2.3" v1.2.3 |
| 214 |
.Ve |
| 215 |
.PP |
| 216 |
See version::Internals for more on version number conversion. |
| 217 |
.SS "How to check for a legal version string" |
| 218 |
.IX Subsection "How to check for a legal version string" |
| 219 |
If you do not want to actually create a full blown version object, but |
| 220 |
would still like to verify that a given string meets the criteria to |
| 221 |
be parsed as a version, there are two helper functions that can be |
| 222 |
employed directly: |
| 223 |
.ie n .IP is_lax() 4 |
| 224 |
.el .IP \f(CWis_lax()\fR 4 |
| 225 |
.IX Item "is_lax()" |
| 226 |
The lax criteria corresponds to what is currently allowed by the |
| 227 |
version parser. All of the following formats are acceptable |
| 228 |
for dotted-decimal formats strings: |
| 229 |
.Sp |
| 230 |
.Vb 5 |
| 231 |
\& v1.2 |
| 232 |
\& 1.2345.6 |
| 233 |
\& v1.23_4 |
| 234 |
\& 1.2345 |
| 235 |
\& 1.2345_01 |
| 236 |
.Ve |
| 237 |
.ie n .IP is_strict() 4 |
| 238 |
.el .IP \f(CWis_strict()\fR 4 |
| 239 |
.IX Item "is_strict()" |
| 240 |
If you want to limit yourself to a much more narrow definition of what |
| 241 |
a version string constitutes, \f(CWis_strict()\fR is limited to version |
| 242 |
strings like the following list: |
| 243 |
.Sp |
| 244 |
.Vb 2 |
| 245 |
\& v1.234.5 |
| 246 |
\& 2.3456 |
| 247 |
.Ve |
| 248 |
.PP |
| 249 |
See version::Internals for details of the regular expressions |
| 250 |
that define the legal version string forms, as well as how to use |
| 251 |
those regular expressions in your own code if \f(CWis_lax()\fR and |
| 252 |
\&\f(CWis_strict()\fR are not sufficient for your needs. |
| 253 |
.SS "How to compare version objects" |
| 254 |
.IX Subsection "How to compare version objects" |
| 255 |
Version objects overload the \f(CW\*(C`cmp\*(C'\fR and \f(CW\*(C`<=>\*(C'\fR operators. Perl |
| 256 |
automatically generates all of the other comparison operators based on those |
| 257 |
two so all the normal logical comparisons will work. |
| 258 |
.PP |
| 259 |
.Vb 3 |
| 260 |
\& if ( version\->parse($v1) == version\->parse($v2) ) { |
| 261 |
\& # do stuff |
| 262 |
\& } |
| 263 |
.Ve |
| 264 |
.PP |
| 265 |
If a version object is compared against a non-version object, the non-object |
| 266 |
term will be converted to a version object using \f(CWparse()\fR. This may give |
| 267 |
surprising results: |
| 268 |
.PP |
| 269 |
.Vb 2 |
| 270 |
\& $v1 = version\->parse("v0.95.0"); |
| 271 |
\& $bool = $v1 < 0.94; # TRUE since 0.94 is v0.940.0 |
| 272 |
.Ve |
| 273 |
.PP |
| 274 |
Always comparing to a version object will help avoid surprises: |
| 275 |
.PP |
| 276 |
.Vb 1 |
| 277 |
\& $bool = $v1 < version\->parse("v0.94.0"); # FALSE |
| 278 |
.Ve |
| 279 |
.PP |
| 280 |
Note that "alpha" version objects (where the version string contains |
| 281 |
a trailing underscore segment) compare as less than the equivalent |
| 282 |
version without an underscore: |
| 283 |
.PP |
| 284 |
.Vb 1 |
| 285 |
\& $bool = version\->parse("1.23_45") < version\->parse("1.2345"); # TRUE |
| 286 |
.Ve |
| 287 |
.PP |
| 288 |
See version::Internals for more details on "alpha" versions. |
| 289 |
.SH "OBJECT METHODS" |
| 290 |
.IX Header "OBJECT METHODS" |
| 291 |
.SS \fBis_alpha()\fP |
| 292 |
.IX Subsection "is_alpha()" |
| 293 |
True if and only if the version object was created with a underscore, e.g. |
| 294 |
.PP |
| 295 |
.Vb 2 |
| 296 |
\& version\->parse(\*(Aq1.002_03\*(Aq)\->is_alpha; # TRUE |
| 297 |
\& version\->declare(\*(Aq1.2.3_4\*(Aq)\->is_alpha; # TRUE |
| 298 |
.Ve |
| 299 |
.SS \fBis_qv()\fP |
| 300 |
.IX Subsection "is_qv()" |
| 301 |
True only if the version object is a dotted-decimal version, e.g. |
| 302 |
.PP |
| 303 |
.Vb 4 |
| 304 |
\& version\->parse(\*(Aqv1.2.0\*(Aq)\->is_qv; # TRUE |
| 305 |
\& version\->declare(\*(Aqv1.2\*(Aq)\->is_qv; # TRUE |
| 306 |
\& qv(\*(Aq1.2\*(Aq)\->is_qv; # TRUE |
| 307 |
\& version\->parse(\*(Aq1.2\*(Aq)\->is_qv; # FALSE |
| 308 |
.Ve |
| 309 |
.SS \fBnormal()\fP |
| 310 |
.IX Subsection "normal()" |
| 311 |
Returns a string with a standard 'normalized' dotted-decimal form with a |
| 312 |
leading-v and at least 3 components. |
| 313 |
.PP |
| 314 |
.Vb 2 |
| 315 |
\& version\->declare(\*(Aqv1.2\*(Aq)\->normal; # v1.2.0 |
| 316 |
\& version\->parse(\*(Aq1.2\*(Aq)\->normal; # v1.200.0 |
| 317 |
.Ve |
| 318 |
.SS \fBnumify()\fP |
| 319 |
.IX Subsection "numify()" |
| 320 |
Returns a value representing the object in a pure decimal. |
| 321 |
.PP |
| 322 |
.Vb 2 |
| 323 |
\& version\->declare(\*(Aqv1.2\*(Aq)\->numify; # 1.002000 |
| 324 |
\& version\->parse(\*(Aq1.2\*(Aq)\->numify; # 1.200 |
| 325 |
.Ve |
| 326 |
.SS \fBstringify()\fP |
| 327 |
.IX Subsection "stringify()" |
| 328 |
Returns a string that is as close to the original representation as possible. |
| 329 |
If the original representation was a numeric literal, it will be returned the |
| 330 |
way perl would normally represent it in a string. This method is used whenever |
| 331 |
a version object is interpolated into a string. |
| 332 |
.PP |
| 333 |
.Vb 3 |
| 334 |
\& version\->declare(\*(Aqv1.2\*(Aq)\->stringify; # v1.2 |
| 335 |
\& version\->parse(\*(Aq1.200\*(Aq)\->stringify; # 1.2 |
| 336 |
\& version\->parse(1.02_30)\->stringify; # 1.023 |
| 337 |
.Ve |
| 338 |
.SH "EXPORTED FUNCTIONS" |
| 339 |
.IX Header "EXPORTED FUNCTIONS" |
| 340 |
.SS \fBqv()\fP |
| 341 |
.IX Subsection "qv()" |
| 342 |
This function is no longer recommended for use, but is maintained for |
| 343 |
compatibility with existing code. If you do not want to have it exported |
| 344 |
to your namespace, use this form: |
| 345 |
.PP |
| 346 |
.Vb 1 |
| 347 |
\& use version 0.77 (); |
| 348 |
.Ve |
| 349 |
.SS \fBis_lax()\fP |
| 350 |
.IX Subsection "is_lax()" |
| 351 |
(Not exported by default) |
| 352 |
.PP |
| 353 |
This function takes a scalar argument and returns a boolean value indicating |
| 354 |
whether the argument meets the "lax" rules for a version number. Leading and |
| 355 |
trailing spaces are not allowed. |
| 356 |
.SS \fBis_strict()\fP |
| 357 |
.IX Subsection "is_strict()" |
| 358 |
(Not exported by default) |
| 359 |
.PP |
| 360 |
This function takes a scalar argument and returns a boolean value indicating |
| 361 |
whether the argument meets the "strict" rules for a version number. Leading |
| 362 |
and trailing spaces are not allowed. |
| 363 |
.SH AUTHOR |
| 364 |
.IX Header "AUTHOR" |
| 365 |
John Peacock <[email protected]> |
| 366 |
.SH "SEE ALSO" |
| 367 |
.IX Header "SEE ALSO" |
| 368 |
version::Internals. |
| 369 |
.PP |
| 370 |
perl. |