Debian Codegraph @

upstream/opensuse-tumbleweed/man3/version.3pm

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