/usr/share/perl5/DPKG/Log/Analyse/Package.pm is in libdpkg-log-perl 1.20-2.
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | package DPKG::Log::Analyse::Package;
BEGIN {
$DPKG::Log::Analyse::Package::VERSION = '1.20';
}
=head1 NAME
DPKG::Log::Analyse::Package - Describe a package as analysed from a dpkg.log
=head1 VERSION
version 1.20
=head1 SYNOPSIS
use DPKG::Log;
my $package = DPKG::Log::Analyse::Package->new('package' => 'foobar');
=head1 DESCRIPTION
This module is used to analyse a dpkg log.
=head1 METHODS
=over 4
=cut
use strict;
use warnings;
use 5.010;
use Carp;
use DPKG::Log;
use Dpkg::Version;
use Params::Validate qw(:all);
use overload (
'""' => 'as_string',
'eq' => 'equals',
'cmp' => 'compare',
'<=>' => 'compare'
);
=item $package = DPKG::Log::Analyse::Package->new('package' => 'foobar')
Returns a new DPKG::Log::Analyse::Package object.
=cut
sub new {
my $package = shift;
$package = ref($package) if ref($package);
my %params = validate(
@_, {
'package' => { 'type' => SCALAR },
'version' => 0,
'previous_version' => 0,
'status' => 0
}
);
my $self = {
version => "",
previous_version => "",
status => "",
%params
};
bless($self, $package);
return $self;
}
=item $package_name = $package->name;
Returns the name of this package.
=cut
sub name {
my $self = shift;
return $self->{package};
}
=item $package->version
Return or set the version of this package.
=cut
sub version {
my ($self, $version) = @_;
if ($version) {
my $version_obj = Dpkg::Version->new($version);
$self->{version} = $version_obj;
} else {
$version = $self->{version};
}
return $version;
}
=item $package->previous_version
Return or set the previous version of this package.
=cut
sub previous_version {
my ($self, $previous_version) = @_;
if ($previous_version) {
my $version_obj = Dpkg::Version->new($previous_version);
$self->{previous_version} = $version_obj;
} else {
$previous_version = $self->{previous_version};
}
return $previous_version;
}
=item $package->status
Return or set the status of this package.
=cut
sub status {
my ($self, $status) = @_;
if ($status) {
$self->{status} = $status;
} else {
$status = $self->{status}
}
return $status;
}
=item equals($package1, $package2);
=item print "equal" if $package1 eq $package2
Compares two packages in their string representation.
=cut
sub equals {
my ($first, $second) = @_;
return ($first->as_string eq $second->as_string);
}
=item compare($package1, $package2)
=item print "greater" if $package1 > $package2
Compare two packages. See B<OVERLOADING> for details on how
the comparison works.
=cut
sub compare {
my ($first, $second) = @_;
return -1 if ($first->name ne $second->name);
if ((not $first->previous_version) and (not $second->previous_version)) {
return ($first->version <=> $second->version);
} elsif ((not $first->previous_version) or (not $second->previous_version)) {
return -1;
} elsif ($first->previous_version != $second->previous_version) {
return -1;
}
return (($first->version <=> $second->version));
}
=item $package_str = $package->as_string
=item printf("Package name: %s", $package);
Return this package as a string. This will return the package name
and the version (if set) in the form package_name/version.
If version is not set, it will return the package name only.
=cut
sub as_string {
my $self = shift;
my $string = $self->{package};
if ($self->version) {
$string = $string . "/" . $self->version;
}
return $string;
}
=back
=head1 Overloading
This module explicitly overloads some operators.
Each operand is expected to be a DPKG::Log::Analyse::Package object.
The string comparison operators, "eq" or "ne" will use the string value for the
comparison.
The numerical operators will use the package name and package version for
comparison. That means a package1 == package2 if package1->name equals
package2->name AND package1->version == package2->version.
The module stores versions as Dpkg::Version objects, therefore sorting
different versions of the same package will work.
This module also overloads stringification returning either the package
name if no version is set or "package_name/version" if a version is set.
=cut
=head1 SEE ALSO
L<DPKG::Log>, L<DPKG::Version>
=head1 AUTHOR
Patrick Schoenfeld <schoenfeld@debian.org>.
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 Patrick Schoenfeld <schoenfeld@debian.org>
This library is free software.
You can redistribute it and/or modify it under the same terms as perl itself.
=cut
1;
# vim: expandtab:ts=4:sw=4
|