1Dpkg::Version(3) libdpkg-perl Dpkg::Version(3)
2
3
4
6 Dpkg::Version - handling and comparing dpkg-style version numbers
7
9 The Dpkg::Version module provides pure-Perl routines to compare dpkg-
10 style version numbers (as used in Debian packages) and also an object
11 oriented interface overriding perl operators to do the right thing when
12 you compare Dpkg::Version object between them.
13
15 $v = Dpkg::Version->new($version, %opts)
16 Create a new Dpkg::Version object corresponding to the version
17 indicated in the string (scalar) $version. By default it will
18 accepts any string and consider it as a valid version. If you pass
19 the option "check => 1", it will return undef if the version is
20 invalid (see version_check for details).
21
22 You can always call $v->is_valid() later on to verify that the
23 version is valid.
24
25 boolean evaluation
26 When the Dpkg::Version object is used in a boolean evaluation (for
27 example in "if ($v)" or "$v || 'default'") it returns its string
28 representation if the version stored is valid ($v->is_valid()) and
29 undef otherwise.
30
31 $v->is_valid()
32 Returns true if the version is valid, false otherwise.
33
34 $v->epoch(), $v->version(), $v->revision()
35 Returns the corresponding part of the full version string.
36
37 $v->is_native()
38 Returns true if the version is native, false if it has a revision.
39
40 $v1 <=> $v2, $v1 < $v2, $v1 <= $v2, $v1 > $v2, $v1 >= $v2
41 Numerical comparison of various versions numbers. One of the two
42 operands needs to be a Dpkg::Version, the other one can be anything
43 provided that its string representation is a version number.
44
45 "$v", $v->as_string(), $v->as_string(%options)
46 Accepts an optional option hash reference, affecting the string
47 conversion.
48
49 Options:
50
51 omit_epoch (defaults to 0)
52 Omit the epoch, if present, in the output string.
53
54 omit_revision (defaults to 0)
55 Omit the revision, if present, in the output string.
56
57 Returns the string representation of the version number.
58
60 All the functions are exported by default.
61
62 version_compare($a, $b)
63 Returns -1 if $a is earlier than $b, 0 if they are equal and 1 if
64 $a is later than $b.
65
66 If $a or $b are not valid version numbers, it dies with an error.
67
68 version_compare_relation($a, $rel, $b)
69 Returns the result (0 or 1) of the given comparison operation. This
70 function is implemented on top of version_compare().
71
72 Allowed values for $rel are the exported constants REL_GT, REL_GE,
73 REL_EQ, REL_LE, REL_LT. Use version_normalize_relation() if you
74 have an input string containing the operator.
75
76 $rel = version_normalize_relation($rel_string)
77 Returns the normalized constant of the relation $rel (a value among
78 REL_GT, REL_GE, REL_EQ, REL_LE and REL_LT). Supported relations
79 names in input are: "gt", "ge", "eq", "le", "lt", ">>", ">=", "=",
80 "<=", "<<". ">" and "<" are also supported but should not be used
81 as they are obsolete aliases of ">=" and "<=".
82
83 version_compare_string($a, $b)
84 String comparison function used for comparing non-numerical parts
85 of version numbers. Returns -1 if $a is earlier than $b, 0 if they
86 are equal and 1 if $a is later than $b.
87
88 The "~" character always sort lower than anything else. Digits sort
89 lower than non-digits. Among remaining characters alphabetic
90 characters (A-Z, a-z) sort lower than the other ones. Within each
91 range, the ASCII decimal value of the character is used to sort
92 between characters.
93
94 version_compare_part($a, $b)
95 Compare two corresponding sub-parts of a version number (either
96 upstream version or debian revision).
97
98 Each parameter is split by version_split_digits() and resulting
99 items are compared together. As soon as a difference happens, it
100 returns -1 if $a is earlier than $b, 0 if they are equal and 1 if
101 $a is later than $b.
102
103 @items = version_split_digits($version)
104 Splits a string in items that are each entirely composed either of
105 digits or of non-digits. For instance for "1.024~beta1+svn234" it
106 would return ("1", ".", "024", "~beta", "1", "+svn", "234").
107
108 ($ok, $msg) = version_check($version)
109 $ok = version_check($version)
110 Checks the validity of $version as a version number. Returns 1 in
111 $ok if the version is valid, 0 otherwise. In the latter case, $msg
112 contains a description of the problem with the $version scalar.
113
115 Version 1.01 (dpkg 1.17.0)
116 New argument: Accept an options argument in $v->as_string().
117
118 New method: $v->is_native().
119
120 Version 1.00 (dpkg 1.15.6)
121 Mark the module as public.
122
123
124
1251.18.25 2019-07-24 Dpkg::Version(3)