This file is indexed.

/usr/share/perl5/Lintian/Relation/Version.pm is in lintian 2.5.43ubuntu0.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# -*- perl -*-
# Lintian::Relation::Version -- comparison operators on Debian versions

# Copyright (C) 1998 Christian Schwarz and Richard Braakman
# Copyright (C) 2004-2009 Russ Allbery <rra@debian.org>
# Copyright (C) 2009 Adam D. Barratt <adam@adam-barratt.org.uk>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program.  If not, see <http://www.gnu.org/licenses/>.

package Lintian::Relation::Version;

use strict;
use warnings;

use Carp qw(croak);
use Exporter qw(import);

BEGIN {
    our @EXPORT_OK = qw(versions_equal versions_lte versions_gte versions_lt
      versions_gt versions_compare versions_comparator);
    our %EXPORT_TAGS = ('all' => \@EXPORT_OK);
}

use AptPkg::Config '$_config';
my $versioning = $_config->system->versioning;

=head1 NAME

Lintian::Relation::Version - Comparison operators on Debian versions

=head1 SYNOPSIS

    print "yes\n" if versions_equal('1.0', '1.00');
    print "yes\n" if versions_gte('1.1', '1.0');
    print "no\n" if versions_lte('1.1', '1.0');
    print "yes\n" if versions_gt('1.1', '1.0');
    print "no\n" if versions_lt('1.1', '1.1');
    print "yes\n" if versions_compare('1.1', '<=', '1.1');

=head1 DESCRIPTION

This module provides five functions for comparing version numbers.  The
underlying implementation uses C<libapt-pkg-perl> to ensure that
the results match what dpkg will expect.

=head1 FUNCTIONS

=over 4

=item versions_equal(A, B)

Returns true if A is equal to B (C<=>) and false otherwise.

=cut

sub versions_equal {
    my ($p, $q) = @_;
    my $result;

    return 1 if $p eq $q;

    $result = $versioning->compare($p, $q);

    return ($result == 0);
}

=item versions_lte(A, B)

Returns true if A is less than or equal (C<< <= >>) to B and false
otherwise.

=cut

sub versions_lte {
    my ($p, $q) = @_;
    my $result;

    return 1 if $p eq $q;

    $result = $versioning->compare($p, $q);

    return ($result <= 0);
}

=item versions_gte(A, B)

Returns true if A is greater than or equal (C<< >= >>) to B and false
otherwise.

=cut

sub versions_gte {
    my ($p, $q) = @_;
    my $result;

    return 1 if $p eq $q;

    $result = $versioning->compare($p, $q);

    return ($result >= 0);
}

=item versions_lt(A, B)

Returns true if A is less than (C<<< << >>>) B and false otherwise.

=cut

sub versions_lt {
    my ($p, $q) = @_;
    my $result;

    return 0 if $p eq $q;

    $result = $versioning->compare($p, $q);

    return ($result < 0);
}

=item versions_gt(A, B)

Returns true if A is greater than (C<<< >> >>>) B and false otherwise.

=cut

sub versions_gt {
    my ($p, $q) = @_;
    my $result;

    return 0 if $p eq $q;

    $result = $versioning->compare($p, $q);

    return ($result > 0);
}

=item versions_compare(A, OP, B)

Returns true if A OP B, where OP is one of C<=>, C<< <= >>, C<< >= >>,
C<<< << >>>, or C<<< >> >>>, and false otherwise.

=cut

sub versions_compare {
    my ($p, $op, $q) = @_;
    if    ($op eq  '=') { return versions_equal($p, $q) }
    elsif ($op eq '<=') { return versions_lte($p, $q) }
    elsif ($op eq '>=') { return versions_gte($p, $q) }
    elsif ($op eq '<<') { return versions_lt($p, $q) }
    elsif ($op eq '>>') { return versions_gt($p, $q) }
    else { croak("unknown operator $op") }
}

=item versions_comparator (A, B)

Returns -1, 0 or 1 if the version A is (respectively) less than, equal
to or greater than B.  This is useful for (e.g.) sorting a list of
versions:

 foreach my $version (sort versions_comparator @versions) {
    ...
 }

=cut

# Use a prototype to avoid confusing Perl when used with sort.

sub versions_comparator ($$) {
    my ($p, $q) = @_;
    return $versioning->compare($p, $q);
}

=back

=head1 AUTHOR

Originally written by Russ Allbery <rra@debian.org> for Lintian and adapted
to use libapt-pkg-perl by Adam D. Barratt <adam@adam-barratt-org.uk>.

=head1 SEE ALSO

lintian(1)

=cut

1;

# Local Variables:
# indent-tabs-mode: nil
# cperl-indent-level: 4
# End:
# vim: syntax=perl sw=4 sts=4 sr et