aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Youri/Package.pm
blob: 5ba866aeedef418f286a9771321646f5a4d77fd2 (plain)
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# $Id: Package.pm 223952 2007-06-23 13:54:13Z pixel $
package Youri::Package;

=head1 NAME

Youri::Package - Abstract package class

=head1 DESCRIPTION

This abstract class defines Youri::Package interface.

=cut

use Carp;
use strict;
use warnings;

use constant DEPENDENCY_NAME  => 0;
use constant DEPENDENCY_RANGE => 1;

use constant FILE_NAME   => 0;
use constant FILE_MODE   => 1;
use constant FILE_MD5SUM => 2;

use constant CHANGE_AUTHOR => 0;
use constant CHANGE_TIME   => 1;
use constant CHANGE_TEXT   => 2;

=head1 CLASS METHODS

=head2 new(%args)

Creates and returns a new Youri::Package object.

Warning: do not call directly, call subclass constructor instead.

=cut

sub new {
    my $class = shift;
    croak "Abstract class" if $class eq __PACKAGE__;

    my %options = (
        @_
    );

    my $self = bless {
    }, $class;

    $self->_init(%options);

    return $self;
}

sub _init {
    # do nothing
}

=head2 get_pattern($name, $version, $release, $arch)

Returns a pattern matching a file for a package, using available informations.

=head2 compare_revisions($revision1, $revision2)

Compares two revision tokens, and returns a numeric value:

=over

=item positive if first revision is higher

=item null if both revisions are equal

=item negative if first revision is lower

=back

=head2 check_ranges_compatibility($range1, $range2)

Returns a true value if given revision ranges are compatible.

=head1 INSTANCE METHODS

=head2 as_file()

Returns the file corresponding to this package.

=head2 as_string()

Returns a string representation of this package.

=head2 as_formated_string(I<format>)

Returns a string representation of this package, formated according to
I<format>. Format is a string, where each %{foo} token will get replaced by
equivalent tag value.

=head2 get_name()

Returns the name of this package.

=head2 get_version()

Returns the version of this package.

=head2 get_release()

Returns the release of this package.

=head2 get_revision()

Returns the revision of this package.

=head2 get_arch()

Returns the architecture of this package.

=head2 get_file_name()

Returns the file name of this package (name-version-release.arch.extension).

=head2 is_source()

Returns true if this package is a source package.

=head2 is_binary()

Returns true if this package is a binary package.

=head2 is_debug()

Returns true if this package is a debug package.

=head2 get_type()

Returns the type (binary/source) of this package.

=head2 get_age()

Returns the age of this package

=head2 get_url()

Returns the URL of this package

=head2 get_summary()

Returns the summary of this package

=head2 get_description()

Returns the description of this package

=head2 get_packager()

Returns the packager of this package.

=head2 get_source_package()

Returns the name of the source package of this package.

=head2 get_tag($tag)

Returns the value of tag $tag of this package.

=head2 get_canonical_name()

Returns the canonical name of this package, shared by its multiple components,
usually the one from the source package.

=head2 get_requires()

Returns the list of dependencies required by this package, each dependency
being represented as an array reference, with the following informations:

=over

=item B<name>

Name of the dependency (index DEPENDENCY_NAME)

=item B<range>

Range of the dependency (index DEPENDENCY_RANGE)

=back

For more conveniency, fields index are available as constant in this package.

=head2 get_provides()

Returns the list of dependencies provided by this package, each dependency
being represented as an array reference, using the same structure as previous method.

=head2 get_obsoletes()

Returns the list of other packages obsoleted by this one, each one
being represented as an array reference, using the same structure as previous method.

=head2 get_conflicts()

Returns the list of other packages conflicting with this one.

=head2 get_files()

Returns the list of files contained in this package, each file being
represented as an array reference, with the following informations:

=over

=item B<name>

Name of the file (index FILE_NAME).

=item B<mode>

Mode of the file (index FILE_MODE).

=item B<md5sum>

Md5sum of the file (index FILE_MD5SUM).

=back

For more conveniency, fields index are available as constant in this package.

=head2 get_gpg_key()

Returns the gpg key id of package signature.

=head2 get_information()

Returns formated informations about the package.

=head2 get_changes()

Returns the list of changes for this package, each change being
represented as an array reference, with the following informations:

=over

=item B<author>

Author of the change (index CHANGE_AUTHOR).

=item B<time>

Time of the change (index CHANGE_TIME).

=item B<text>

Raw textual description of the change (index CHANGE_TEXT).

=back

For more conveniency, fields index are available as constant in this package.

=head2 get_last_change()

Returns the last change for this package, as as structure described before.

=head2 compare($package)

Compares ordering with other package, according to their corresponding revision
tokens, and returns a numeric value:

=over

=item positive if this package is newer

=item null if both have same revision

=item negative if this package is older

=back

=head2 satisfy_range($range)

Returns a true value if this package revision satisfies given revision range.

=head2 sign($name, $path, $passphrase)

Signs the package with given name, keyring path and passphrase.

=head2 extract()

Extract package content in local directory.

=head1 SUBCLASSING

All instances methods have to be implemented.

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2002-2006, YOURI project

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

=cut

sub get_file {
    my ($self) = @_;
    carp "Deprecated method, use as_file now";

    return $self->as_file();
}

sub get_full_name {
    my ($self) = @_;
    carp "Deprecated method, use as_string now";

    return $self->as_string();
}

sub compare_versions {
    my ($self, $version1, $version2) = @_;
    carp "Deprecated method, use compare_revisions now";

    return $self->compare_revisions($version1, $version2);
}

sub compare_ranges {
    my ($self, $range1, $range2) = @_;
    carp "Deprecated method, use are_range_compatible now";

    return $self->check_ranges_compatibility($range1, $range2);
}

sub get_revision_name {
    my ($self) = @_;
    carp "Deprecated method, use as_formated_string('%name-%version-%release') now";

    return $self->as_formated_string('%{name}-%{version}-%{release}');
}


1;