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
|
package SlackBuild::Registry::Record;
use strict;
use warnings;
use Carp;
use SlackBuild::Base qw(package arch build date filename);
use SlackBuild::Registry::Version;
use Scalar::Util qw(blessed);
=head2 new
$x = new SlackBuild::Registry::Record(PACKAGE,
arch=>X, version=>Y, build=>Z, date=>D, filename=>F)
=cut
sub new {
my $class = shift;
my $self = bless {}, $class;
$self->build(1);
if (my $v = shift) {
$self->package($v);
if (@_) {
croak "bad number of arguments" if (@_ % 2);
local %_ = @_;
while (my ($k,$v) = each %_) {
$self->${\$k}($v);
}
}
}
return $self;
}
sub version {
my $self = shift;
if (@_) {
croak "too many arguments" if @_ > 1;
$self->{version} = new SlackBuild::Registry::Version(shift);
}
return $self->{version};
}
sub store {
my $self = shift;
croak "store not implemented";
}
sub as_string {
my $self = shift;
return $self->package . '-'
. ($self->version ? $self->version : '*') . '-'
. ($self->arch ? $self->arch : '*') . '-'
. ($self->build || '1');
}
sub cmp {
my ($self, $other) = @_;
my $v;
if ($v = ($self->package || '') cmp ($other->package || '')) {
return $v;
}
if ($self->version <=> $other->version) {
return $v;
}
if ($self->arch && $other->arch
&& ($v = $self->arch cmp $other->arch)) {
return $v;
}
return ($self->build || 1) <=> ($other->build || 1);
}
use overload
'""' => sub { shift->as_string },
'cmp' => sub {
my ($self, $other, $swap) = @_;
my $res = $self->cmp($other);
return $swap ? -$res : $res;
},
'<=>' => sub {
my ($self, $other, $swap) = @_;
my $res = $self->cmp($other);
return $swap ? -$res : $res;
},
'==' => sub {
my ($self, $other) = @_;
my $res = $self->cmp($other) == 0;
},
'!=' => sub {
my ($self, $other) = @_;
my $res = $self->cmp($other) != 0;
},
'<' => sub {
my ($self, $other, $swap) = @_;
my $res = $self->cmp($other) < 0;
return $swap ? !$res : $res;
},
'<=' => sub {
my ($self, $other, $swap) = @_;
my $res = $self->cmp($other) <= 0;
return $swap ? !$res : $res;
},
'>' => sub {
my ($self, $other, $swap) = @_;
my $res = $self->cmp($other) > 0;
return $swap ? !$res : $res;
},
'>=' => sub {
my ($self, $other, $swap) = @_;
my $res = $self->cmp($other) >= 0;
return $swap ? !$res : $res;
};
1;
|