blib/lib/Slackware/Slackget/Package.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 148 | 430 | 34.4 |
branch | 46 | 244 | 18.8 |
condition | 10 | 48 | 20.8 |
subroutine | 28 | 43 | 65.1 |
pod | 37 | 37 | 100.0 |
total | 269 | 802 | 33.5 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package Slackware::Slackget::Package; | ||||||
2 | |||||||
3 | 5 | 5 | 76785 | use warnings; | |||
5 | 14 | ||||||
5 | 198 | ||||||
4 | 5 | 5 | 31 | use strict; | |||
5 | 11 | ||||||
5 | 296 | ||||||
5 | use overload | ||||||
6 | 5 | 55 | 'cmp' => \&compare_version, | ||||
7 | '<=>' => \&compare_version, | ||||||
8 | 5 | 5 | 3826 | 'fallback' => 1; | |||
5 | 2792 | ||||||
9 | |||||||
10 | require Slackware::Slackget::MD5; | ||||||
11 | 5 | 5 | 17745 | use Data::Dumper; | |||
5 | 70691 | ||||||
5 | 637 | ||||||
12 | |||||||
13 | use constant { | ||||||
14 | 5 | 67529 | PKG_VER_EQ => 0, | ||||
15 | PKG_VER_LT => -1, | ||||||
16 | PKG_VER_GT => 1, | ||||||
17 | 5 | 5 | 50 | }; | |||
5 | 11 | ||||||
18 | |||||||
19 | =head1 NAME | ||||||
20 | |||||||
21 | Slackware::Slackget::Package - This class is the internal representation of a package for slack-get 1.0 | ||||||
22 | |||||||
23 | =head1 VERSION | ||||||
24 | |||||||
25 | Version 1.0.3 | ||||||
26 | |||||||
27 | =cut | ||||||
28 | |||||||
29 | our @ISA = qw( Slackware::Slackget::MD5 ); | ||||||
30 | our $VERSION = '1.0.3'; | ||||||
31 | |||||||
32 | =head1 SYNOPSIS | ||||||
33 | |||||||
34 | This module is used to represent a package for slack-get | ||||||
35 | |||||||
36 | use Slackware::Slackget::Package; | ||||||
37 | |||||||
38 | my $package = Slackware::Slackget::Package->new('package-1.0.0-noarch-1'); | ||||||
39 | $package->set_value('description',"This is a test of the Slackware::Slackget::Package object"); | ||||||
40 | $package->fill_object_from_package_name(); | ||||||
41 | |||||||
42 | This class inheritate from Slackware::Slackget::MD5, so you can use : | ||||||
43 | |||||||
44 | $sgo->installpkg($package) if($package->verify_md5); | ||||||
45 | |||||||
46 | Isn't it great ? | ||||||
47 | |||||||
48 | =head1 CONSTRUCTOR | ||||||
49 | |||||||
50 | =head2 new | ||||||
51 | |||||||
52 | The constructor take two parameters : a package name, and an id (the namespace of the package like 'slackware' or 'linuxpackages') | ||||||
53 | |||||||
54 | my $package = new Slackware::Slackget::Package ('aaa_base-10.0.0-noarch-1','slackware'); | ||||||
55 | |||||||
56 | The constructor automatically call the fill_object_from_package_name() method. | ||||||
57 | |||||||
58 | You also can pass some extra arguments like that : | ||||||
59 | |||||||
60 | my $package = new Slackware::Slackget::Package ('aaa_base-10.0.0-noarch-1', 'package-object-version' => '1.0.0'); | ||||||
61 | |||||||
62 | The constructor return undef if the id is not defined. | ||||||
63 | |||||||
64 | =cut | ||||||
65 | |||||||
66 | sub new | ||||||
67 | { | ||||||
68 | 16 | 16 | 1 | 19302 | my ($class,$id,@args) = @_ ; | ||
69 | 16 | 50 | 59 | return undef unless($id); | |||
70 | 16 | 31 | my %args = (); | ||||
71 | 16 | 33 | my $self = {}; | ||||
72 | 16 | 100 | 56 | if(scalar(@args)%2 == 0){ | |||
73 | 12 | 23 | %args = @args ; | ||||
74 | 12 | 26 | $self={%args} ; | ||||
75 | }else{ | ||||||
76 | 4 | 12 | $self->{SOURCE} = $args[0]; | ||||
77 | } | ||||||
78 | 16 | 45 | $self->{ROOT} = $id ; | ||||
79 | 16 | 63 | $self->{STATS} = {hw => [], dwc => 0}; | ||||
80 | 16 | 50 | bless($self,$class); | ||||
81 | 16 | 51 | $self->fill_object_from_package_name(); | ||||
82 | 16 | 162 | return $self; | ||||
83 | } | ||||||
84 | |||||||
85 | =head1 FUNCTIONS | ||||||
86 | |||||||
87 | =head2 merge | ||||||
88 | |||||||
89 | This method merge $another_package with $package. | ||||||
90 | |||||||
91 | ** WARNING ** : $another_package will be destroy in the operation (this is a collateral damage ;-), for some dark preocupation of memory. | ||||||
92 | |||||||
93 | ** WARNING 2 ** : the merge keep the id from $package, this mean that an inconsistency can be found between the id and the version number. | ||||||
94 | |||||||
95 | This method overwrite existing value. | ||||||
96 | |||||||
97 | $package->merge($another_package); | ||||||
98 | |||||||
99 | =cut | ||||||
100 | |||||||
101 | sub merge { | ||||||
102 | 2 | 2 | 1 | 4 | my ($self,$package) = @_ ; | ||
103 | 2 | 50 | 14 | return unless($package); | |||
104 | 2 | 3 | foreach (keys(%{$package->{PACK}})){ | ||||
2 | 18 | ||||||
105 | 10 | 25 | $self->{PACK}->{$_} = $package->{PACK}->{$_} ; | ||||
106 | } | ||||||
107 | 2 | 6 | $self->{STATS} = {hw => [@{ $package->{STATS}->{hw} }], dwc => $package->{STATS}->{dwc}} ; | ||||
2 | 14 | ||||||
108 | 2 | 8 | $package = undef; | ||||
109 | } | ||||||
110 | |||||||
111 | =head2 is_heavy_word | ||||||
112 | |||||||
113 | This method return true (1) if the first argument is an "heavy word" and return false (0) otherwise. | ||||||
114 | |||||||
115 | print "heavy word found !\n" if($package->is_heavy_word($request[$i])); | ||||||
116 | |||||||
117 | =cut | ||||||
118 | |||||||
119 | sub is_heavy_word | ||||||
120 | { | ||||||
121 | 2 | 2 | 1 | 7 | my ($self,$w) = @_ ; | ||
122 | 2 | 50 | 19 | return undef unless($w); | |||
123 | 2 | 6 | foreach my $hw (@{$self->{STATS}->{hw}}){ | ||||
2 | 12 | ||||||
124 | 2 | 50 | 21 | return 1 if($w eq $hw); | |||
125 | } | ||||||
126 | 0 | 0 | return 0; | ||||
127 | } | ||||||
128 | |||||||
129 | =head2 get_statistic | ||||||
130 | |||||||
131 | Return a given statistic about the description of the package. Currently available are : dwc (description words count) and hw (heavy words, a list of important words). | ||||||
132 | |||||||
133 | Those are for the optimisation of the search speed. | ||||||
134 | |||||||
135 | =cut | ||||||
136 | |||||||
137 | sub get_statistic | ||||||
138 | { | ||||||
139 | 0 | 0 | 1 | 0 | my ($self,$w) = @_ ; | ||
140 | 0 | 0 | return $self->{PACK}->{statistics}->{$w}; | ||||
141 | } | ||||||
142 | |||||||
143 | =head2 compare_version | ||||||
144 | |||||||
145 | This method take another Slackware::Slackget::Package as argument and compare it's version to the current object. | ||||||
146 | |||||||
147 | if( $package->compare_version( $another_package ) == -1 ) | ||||||
148 | { | ||||||
149 | print $another_package->get_id," is newer than ",$package->get_id ,"\n"; | ||||||
150 | } | ||||||
151 | |||||||
152 | Returned code : | ||||||
153 | |||||||
154 | -1 => $package version is lesser than $another_package's one | ||||||
155 | 0 => $package version is equal to $another_package's one | ||||||
156 | 1 => $package version is greater than $another_package's one | ||||||
157 | undef => an error occured. | ||||||
158 | |||||||
159 | =cut | ||||||
160 | |||||||
161 | sub compare_version | ||||||
162 | { | ||||||
163 | 24 | 24 | 1 | 910 | my ($self,$o_pack) = @_ ; | ||
164 | # warn "$o_pack is not a Slackware::Slackget::Package !" if(ref($o_pack) ne 'Slackware::Slackget::Package') ; | ||||||
165 | 24 | 50 | 548 | if($o_pack->can('version')) | |||
166 | { | ||||||
167 | # print "compare_version ",$self->get_id()," v. ",$self->version()," and ",$o_pack->get_id()," v. ",$o_pack->version(),"\n"; | ||||||
168 | 24 | 50 | 51 | $o_pack->set_value('version','0.0.0') unless(defined($o_pack->version())); | |||
169 | 24 | 50 | 106 | $self->set_value('version','0.0.0') unless(defined($self->version())); | |||
170 | 24 | 54 | my @o_pack_version = split(/\./, $o_pack->version()) ; | ||||
171 | 24 | 116 | my @self_version = split(/\./, $self->version()) ; | ||||
172 | 24 | 81 | for(my $k=0; $k<=$#self_version; $k++) | ||||
173 | { | ||||||
174 | # print "\t cmp $self_version[$k] and $o_pack_version[$k]\n"; | ||||||
175 | 32 | 50 | 96 | $self_version[$k] = 0 unless(defined($self_version[$k])); | |||
176 | 32 | 50 | 66 | $o_pack_version[$k] = 0 unless(defined($o_pack_version[$k])); | |||
177 | 32 | 50 | 33 | 391 | if($self_version[$k] =~ /^\d+$/ && $o_pack_version[$k] =~ /^\d+$/) | ||
178 | { | ||||||
179 | 32 | 100 | 140 | if($self_version[$k] > $o_pack_version[$k]) | |||
100 | |||||||
180 | { | ||||||
181 | 8 | 50 | 24 | print "\t",$self->get_id()," > ",$o_pack->get_id(),"\n" if($ENV{SG_DAEMON_DEBUG}); | |||
182 | 8 | 47 | return 1; | ||||
183 | } | ||||||
184 | elsif($self_version[$k] < $o_pack_version[$k]) | ||||||
185 | { | ||||||
186 | 12 | 50 | 34 | print "\t",$self->get_id()," < ",$o_pack->get_id(),"\n" if($ENV{SG_DAEMON_DEBUG}); | |||
187 | 12 | 77 | return -1; | ||||
188 | } | ||||||
189 | } | ||||||
190 | else | ||||||
191 | { | ||||||
192 | 0 | 0 | 0 | if($self_version[$k] gt $o_pack_version[$k]) | |||
0 | |||||||
193 | { | ||||||
194 | 0 | 0 | 0 | print "\t",$self->get_id()," greater than ",$o_pack->get_id(),"\n" if($ENV{SG_DAEMON_DEBUG}); | |||
195 | 0 | 0 | return 1; | ||||
196 | } | ||||||
197 | elsif($self_version[$k] lt $o_pack_version[$k]) | ||||||
198 | { | ||||||
199 | 0 | 0 | 0 | print "\t",$self->get_id()," lesser than ",$o_pack->get_id(),"\n" if($ENV{SG_DAEMON_DEBUG}); | |||
200 | 0 | 0 | return -1; | ||||
201 | } | ||||||
202 | } | ||||||
203 | } | ||||||
204 | 4 | 50 | 33 | 16 | if( $self->getValue('package-version') && $o_pack->getValue('package-version') ){ | ||
205 | 4 | 50 | 12 | if( $self->getValue('package-version') gt $o_pack->getValue('package-version') ){ | |||
50 | |||||||
206 | 0 | 0 | 0 | print "\t",$self->get_id()," greater than ",$o_pack->get_id()," (package-version)\n" if($ENV{SG_DAEMON_DEBUG}); | |||
207 | 0 | 0 | return 1; | ||||
208 | } | ||||||
209 | elsif( $self->getValue('package-version') lt $o_pack->getValue('package-version') ){ | ||||||
210 | 0 | 0 | 0 | print "\t",$self->get_id()," lesser than ",$o_pack->get_id()," (package-version)\n" if($ENV{SG_DAEMON_DEBUG}); | |||
211 | 0 | 0 | return -1 ; | ||||
212 | } | ||||||
213 | } | ||||||
214 | 4 | 50 | 17 | print "\t",$self->get_id()," equal to ",$o_pack->get_id(),"\n" if($ENV{SG_DAEMON_DEBUG}); | |||
215 | 4 | 25 | return 0; | ||||
216 | } | ||||||
217 | else | ||||||
218 | { | ||||||
219 | 0 | 0 | return undef; | ||||
220 | } | ||||||
221 | } | ||||||
222 | |||||||
223 | =head2 fill_object_from_package_name | ||||||
224 | |||||||
225 | Try to extract the maximum informations from the name of the package. The constructor automatically call this method. | ||||||
226 | |||||||
227 | $package->fill_object_from_package_name(); | ||||||
228 | |||||||
229 | =cut | ||||||
230 | |||||||
231 | sub fill_object_from_package_name{ | ||||||
232 | 16 | 16 | 1 | 26 | my $self = shift; | ||
233 | 16 | 50 | 645 | if($self->{ROOT}=~ /^(.*)-([0-9].*)-(i[0-9]86|noarch)-(\d{1,2})(\.tgz)?$/) | |||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
234 | { | ||||||
235 | 16 | 50 | 53 | print "Slackware::Slackget->fill_object_from_package_name() : rg1 matched\n" if($ENV{SG_DAEMON_DEBUG}); | |||
236 | 16 | 51 | $self->set_value('name',$1); | ||||
237 | 16 | 35 | $self->set_value('version',$2); | ||||
238 | 16 | 37 | $self->set_value('architecture',$3); | ||||
239 | 16 | 42 | $self->set_value('package-version',$4); | ||||
240 | 16 | 100 | 66 | 202 | $self->set_value('package-maintener','Slackware team') if(defined($self->{SOURCE}) && $self->{SOURCE}=~/^slackware$/i); | ||
241 | } | ||||||
242 | elsif($self->{ROOT}=~ /^(.*)-([0-9].*)-(i[0-9]86|noarch)-([^\-]+)(\.tgz)?$/) | ||||||
243 | { | ||||||
244 | 0 | 0 | 0 | print "Slackware::Slackget->fill_object_from_package_name() : rg2 matched\n" if($ENV{SG_DAEMON_DEBUG}); | |||
245 | 0 | 0 | $self->set_value('name',$1); | ||||
246 | 0 | 0 | $self->set_value('version',$2); | ||||
247 | 0 | 0 | $self->set_value('architecture',$3); | ||||
248 | 0 | 0 | $self->set_value('package-version',$4); | ||||
249 | # $self->set_value('package-maintener',$5) if(!defined($self->getValue('package-maintener'))); | ||||||
250 | } | ||||||
251 | elsif($self->{ROOT}=~ /^(.*)-([0-9].*)-(i[0-9]86|noarch)-(\d{1,2})(\w*)(\.tgz)?$/) | ||||||
252 | { | ||||||
253 | 0 | 0 | 0 | print "Slackware::Slackget->fill_object_from_package_name() : rg3 matched\n" if($ENV{SG_DAEMON_DEBUG}); | |||
254 | 0 | 0 | $self->set_value('name',$1); | ||||
255 | 0 | 0 | $self->set_value('version',$2); | ||||
256 | 0 | 0 | $self->set_value('architecture',$3); | ||||
257 | 0 | 0 | $self->set_value('package-version',$4); | ||||
258 | # $self->set_value('package-maintener',$5) if(!defined($self->getValue('package-maintener'))); | ||||||
259 | } | ||||||
260 | elsif($self->{ROOT}=~ /^(.*)-([^-]+)-(i[0-9]86|noarch)-(\d{1,2})(\.tgz)?$/) | ||||||
261 | { | ||||||
262 | 0 | 0 | 0 | print "Slackware::Slackget->fill_object_from_package_name() : rg4 matched\n" if($ENV{SG_DAEMON_DEBUG}); | |||
263 | 0 | 0 | $self->set_value('name',$1); | ||||
264 | 0 | 0 | $self->set_value('version',$2); | ||||
265 | 0 | 0 | $self->set_value('architecture',$3); | ||||
266 | 0 | 0 | $self->set_value('package-version',$4); | ||||
267 | 0 | 0 | 0 | 0 | $self->set_value('package-maintener','Slackware team') if(defined($self->{SOURCE}) && $self->{SOURCE}=~/^slackware$/i); | ||
268 | } | ||||||
269 | elsif($self->{ROOT}=~ /^(.*)-([^-]+)-(i[0-9]86|noarch)-(\d{1,2})(\w*)(\.tgz)?$/) | ||||||
270 | { | ||||||
271 | 0 | 0 | 0 | print "Slackware::Slackget->fill_object_from_package_name() : rg5 matched\n" if($ENV{SG_DAEMON_DEBUG}); | |||
272 | 0 | 0 | $self->set_value('name',$1); | ||||
273 | 0 | 0 | $self->set_value('version',$2); | ||||
274 | 0 | 0 | $self->set_value('architecture',$3); | ||||
275 | 0 | 0 | $self->set_value('package-version',$4); | ||||
276 | # $self->set_value('package-maintener',$5) if(!defined($self->getValue('package-maintener'))); | ||||||
277 | } | ||||||
278 | else | ||||||
279 | { | ||||||
280 | 0 | 0 | 0 | print "Slackware::Slackget->fill_object_from_package_name() : no regexp match possible !!\n" if($ENV{SG_DAEMON_DEBUG}); | |||
281 | 0 | 0 | $self->set_value('name',$self->{ROOT}); | ||||
282 | } | ||||||
283 | 16 | 48 | $self->{STATS}->{hw} = [split(/-/,$self->getValue('name'))]; | ||||
284 | } | ||||||
285 | |||||||
286 | =head2 extract_informations | ||||||
287 | |||||||
288 | Extract informations about a package from a string. This string must be a line of the description of a package. | ||||||
289 | |||||||
290 | $package->extract_informations($data); | ||||||
291 | |||||||
292 | This method is designe to be called by the Slackware::Slackget::SpecialFiles::PACKAGES class, and automatically call the clean_description() method. | ||||||
293 | |||||||
294 | =cut | ||||||
295 | |||||||
296 | sub extract_informations { | ||||||
297 | 0 | 0 | 1 | 0 | my $self = shift; | ||
298 | 0 | 0 | my $raw_str = shift ; | ||||
299 | 0 | 0 | my $is_descr=0; | ||||
300 | 0 | 0 | my $have_sd=0; | ||||
301 | 0 | 0 | foreach (split(/\n/,$raw_str) ){ | ||||
302 | 0 | 0 | chomp ; | ||||
303 | 0 | 0 | 0 | if($_ =~ /^\s*PACKAGE NAME\s*:\s*(.*)\.tgz\s*/) | |||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
304 | { | ||||||
305 | 0 | 0 | $self->_setId($1); | ||||
306 | # print "[Slackware::Slackget::Package] (debug) package name: $1\n" if($ENV{SG_DAEMON_DEBUG}); | ||||||
307 | 0 | 0 | $self->fill_object_from_package_name(); | ||||
308 | |||||||
309 | } | ||||||
310 | elsif($_ =~ /^\s*(COMPRESSED PACKAGE SIZE|PACKAGE SIZE \(compressed\))\s*:\s*(.*) K/) | ||||||
311 | { | ||||||
312 | # print "[Slackware::Slackget::Package] (debug) compressed size: $2\n" if($ENV{SG_DAEMON_DEBUG}); | ||||||
313 | 0 | 0 | $self->set_value('compressed-size',$2); | ||||
314 | } | ||||||
315 | elsif($_ =~ /^\s*(UNCOMPRESSED PACKAGE SIZE|PACKAGE SIZE \(uncompressed\))\s*:\s*(.*) K/) | ||||||
316 | { | ||||||
317 | # print "[Slackware::Slackget::Package] (debug) uncompressed size: $2\n" if($ENV{SG_DAEMON_DEBUG}); | ||||||
318 | 0 | 0 | $self->set_value('uncompressed-size',$2); | ||||
319 | } | ||||||
320 | elsif($_ =~ /^\s*PACKAGE LOCATION\s*:\s*(.*)\s*/) | ||||||
321 | { | ||||||
322 | # print "[Slackware::Slackget::Package] (debug) package location: $1\n" if($ENV{SG_DAEMON_DEBUG}); | ||||||
323 | 0 | 0 | $self->set_value('package-location',$1); | ||||
324 | } | ||||||
325 | elsif($_ =~ /^\s*PACKAGE REQUIRED\s*:\s*(.*)\s*/) | ||||||
326 | { | ||||||
327 | # print "[Slackware::Slackget::Package] (debug) required packages: $1\n" if($ENV{SG_DAEMON_DEBUG}); | ||||||
328 | 0 | 0 | my $raw_deps = $1; | ||||
329 | 0 | 0 | my @dep=(); | ||||
330 | 0 | 0 | foreach my $d ( split(/\s*,|;\s*/,$raw_deps) ){ | ||||
331 | 0 | 0 | my $tmp_array = []; | ||||
332 | 0 | 0 | foreach my $i (split(/\s*\|\s*/,$d) ){ | ||||
333 | 0 | 0 | 0 | 0 | if($i=~ /^\s*([^><=\s]+)\s*([><=]+)\s*(.+)\s*$/){ | ||
0 | |||||||
334 | 0 | 0 | my $ref = {pkg_name => $1, comparison_type => $2, required_version => $3}; | ||||
335 | 0 | 0 | 0 | $ref->{required_version} = $1 if($ref->{required_version} =~ /^(.+)-(.+)-(.+)$/); | |||
336 | 0 | 0 | push @{$tmp_array}, $ref; | ||||
0 | 0 | ||||||
337 | }elsif(defined($i) && $i !~ /(,|;|\|)/ ){ | ||||||
338 | 0 | 0 | push @{$tmp_array}, {pkg_name => $i}; | ||||
0 | 0 | ||||||
339 | } | ||||||
340 | # else{ | ||||||
341 | # print STDERR "[Slackware::Slackget::Package] (error) $d is not a valid dependency token for package $self->{ROOT} (",$self->getValue('package-source'),").\n"; | ||||||
342 | # } | ||||||
343 | } | ||||||
344 | 0 | 0 | push @dep, $tmp_array; | ||||
345 | } | ||||||
346 | # print "==> dump for package $self->{ROOT} (",$self->getValue('package-source'),") <==\n",Dumper(@dep); |
||||||
347 | 0 | 0 | $self->set_value('required',[@dep]); | ||||
348 | } | ||||||
349 | elsif($_ =~ /^\s*PACKAGE SUGGESTS\s*:\s*([^\n]*)\s*/) | ||||||
350 | { | ||||||
351 | 0 | 0 | my $raw_deps = $1; | ||||
352 | 0 | 0 | my @dep=(); | ||||
353 | 0 | 0 | foreach my $d ( split(/,|;/,$raw_deps) ){ | ||||
354 | 0 | 0 | my $tmp_array = []; | ||||
355 | 0 | 0 | foreach my $i (split(/\|/,$d) ){ | ||||
356 | 0 | 0 | 0 | 0 | if($i=~ /^\s*([^><=]+)\s*([><=]+)\s*(.+)\s*$/){ | ||
0 | |||||||
357 | 0 | 0 | my $ref = {pkg_name => $1, comparison_type => $2, required_version => $3}; | ||||
358 | 0 | 0 | 0 | $ref->{required_version} = $1 if($ref->{required_version} =~ /^(.+)-(.+)-(.+)$/); | |||
359 | 0 | 0 | 0 | $ref->{comparison_type} = '=<' if($ref->{comparison_type} eq '<='); | |||
360 | 0 | 0 | 0 | $ref->{comparison_type} = '>=' if($ref->{comparison_type} eq '=>'); | |||
361 | 0 | 0 | push @{$tmp_array}, $ref; | ||||
0 | 0 | ||||||
362 | }elsif(defined($i) && $i !~ /(,|;|\|)/ ){ | ||||||
363 | 0 | 0 | push @{$tmp_array}, {pkg_name => $i}; | ||||
0 | 0 | ||||||
364 | } | ||||||
365 | } | ||||||
366 | 0 | 0 | push @dep, $tmp_array; | ||||
367 | } | ||||||
368 | 0 | 0 | $self->set_value('suggested',[@dep]); | ||||
369 | |||||||
370 | } | ||||||
371 | elsif($_ =~ /^\s*PACKAGE CONFLICTS\s*:\s*([^\n]*)\s*/) | ||||||
372 | { | ||||||
373 | 0 | 0 | my $raw_deps = $1; | ||||
374 | 0 | 0 | my @dep=(); | ||||
375 | 0 | 0 | foreach my $d ( split(/,|;/,$raw_deps) ){ | ||||
376 | 0 | 0 | my $tmp_array = []; | ||||
377 | 0 | 0 | foreach my $i (split(/\|/,$d) ){ | ||||
378 | 0 | 0 | 0 | 0 | if($i=~ /^\s*([^><=]+)\s*([><=]+)\s*(.+)\s*$/){ | ||
0 | |||||||
379 | 0 | 0 | my $ref = {pkg_name => $1, comparison_type => $2, required_version => $3}; | ||||
380 | 0 | 0 | 0 | $ref->{required_version} = $1 if($ref->{required_version} =~ /^(.+)-(.+)-(.+)$/); | |||
381 | 0 | 0 | 0 | $ref->{comparison_type} = '=<' if($ref->{comparison_type} eq '<='); | |||
382 | 0 | 0 | 0 | $ref->{comparison_type} = '>=' if($ref->{comparison_type} eq '=>'); | |||
383 | 0 | 0 | push @{$tmp_array}, $ref; | ||||
0 | 0 | ||||||
384 | }elsif(defined($i) && $i !~ /(,|;|\|)/ ){ | ||||||
385 | 0 | 0 | push @{$tmp_array}, {pkg_name => $i}; | ||||
0 | 0 | ||||||
386 | } | ||||||
387 | } | ||||||
388 | 0 | 0 | push @dep, $tmp_array; | ||||
389 | } | ||||||
390 | 0 | 0 | $self->set_value('conflicts',[@dep]); | ||||
391 | |||||||
392 | } | ||||||
393 | elsif($_=~/^\s*PACKAGE DESCRIPTION:\s*\n*(.*)/ms) | ||||||
394 | { | ||||||
395 | # print "descr "; | ||||||
396 | 0 | 0 | $self->set_value('description',$1); | ||||
397 | 0 | 0 | 0 | if(defined($1)){ | |||
398 | 0 | 0 | $self->set_value('shortdescription',$1); | ||||
399 | } | ||||||
400 | 0 | 0 | $is_descr=1; | ||||
401 | |||||||
402 | # print "[DEBUG] Slackware::Slackget::Package -> package ",$self->get_id()," ($self) have $self->{STATS}->{dwc} words in its description.\n"; | ||||||
403 | # print Dumper($self); |
||||||
404 | } | ||||||
405 | elsif($is_descr){ | ||||||
406 | 0 | 0 | 0 | if(/^\s*[^:]+\s*:\s*(.+)$/){ | |||
407 | 0 | 0 | $self->set_value('description', $self->getValue('description')."$1\n" ); | ||||
408 | 0 | 0 | 0 | unless($have_sd){ | |||
409 | 0 | 0 | $self->set_value('shortdescription',$1); | ||||
410 | 0 | 0 | $have_sd=1; | ||||
411 | } | ||||||
412 | } | ||||||
413 | } | ||||||
414 | } | ||||||
415 | 0 | 0 | $self->clean_description ; | ||||
416 | 0 | 0 | my @t = split(/\s/,$self->get_value('description')); | ||||
417 | 0 | 0 | $self->{STATS}->{dwc} = scalar(@t); | ||||
418 | # print "[Slackware::Slackget::Package] (debug) description:\n",$self->getValue('description'),"\n" if($ENV{SG_DAEMON_DEBUG}); | ||||||
419 | } | ||||||
420 | |||||||
421 | =head2 clean_description | ||||||
422 | |||||||
423 | remove the " |
||||||
424 | |||||||
425 | $package->clean_description(); | ||||||
426 | |||||||
427 | =cut | ||||||
428 | |||||||
429 | sub clean_description{ | ||||||
430 | 0 | 0 | 1 | 0 | my $self = shift; | ||
431 | 0 | 0 | 0 | 0 | if($self->{PACK}->{name} && defined($self->{PACK}->{description}) && $self->{PACK}->{description}) | ||
0 | |||||||
432 | { | ||||||
433 | 0 | 0 | $self->{PACK}->{description}=~ s/\s*\Q$self->{PACK}->{name}\E\s*:\s*/ /ig; | ||||
434 | # my @descr = split(/\s*\Q$self->{PACK}->{name}\E\s*:/,$self->{PACK}->{description}); | ||||||
435 | # $self->{PACK}->{description} = join(' ',@descr); | ||||||
436 | 0 | 0 | $self->{PACK}->{description}=~ s/\t{4,}/\t\t\t/g; | ||||
437 | 0 | 0 | $self->{PACK}->{description}=~ s/\n\s+\n/\n/g; | ||||
438 | } | ||||||
439 | 0 | 0 | $self->{PACK}->{description}.="\n\t\t"; | ||||
440 | 0 | 0 | return 1; | ||||
441 | } | ||||||
442 | |||||||
443 | =head2 grab_info_from_description | ||||||
444 | |||||||
445 | Try to find some informations in the description. For example, packages from linuxpackages.net contain a line starting by Packager: ..., this method will extract this information and re-set the package-maintener tag. | ||||||
446 | |||||||
447 | The supported tags are: package-maintener, info-destination-slackware, info-packager-mail, info-homepage, info-packager-tool, info-packager-tool-version | ||||||
448 | |||||||
449 | $package->grab_info_from_description(); | ||||||
450 | |||||||
451 | =cut | ||||||
452 | |||||||
453 | sub grab_info_from_description | ||||||
454 | { | ||||||
455 | 0 | 0 | 1 | 0 | my $self = shift; | ||
456 | 0 | 0 | 0 | return unless( defined($self->{PACK}->{description}) ); | |||
457 | # NOTE: je remplace ici tout les elsif() par des if() histoire de voir si l'extraction d'information est plus interressante. | ||||||
458 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /this\s+version\s+.*\s+was\s+comp(iled|lied)\s+for\s+([^\n]*)\s+(.|\n)*\s+by\s+([^\n\t]*)/i){ | |||
459 | 0 | 0 | $self->set_value('info-destination-slackware',$2); | ||||
460 | 0 | 0 | $self->set_value('package-maintener',$4); | ||||
461 | } | ||||||
462 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /\s*(http:\/\/[^\s]+)/i){ | |||
463 | 0 | 0 | $self->set_value('info-homepage',$1); | ||||
464 | } | ||||||
465 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /\s*([\w\.\-]+\@[^\s]+\.[\w]+)/i){ | |||
466 | 0 | 0 | $self->set_value('info-packager-mail',$1); | ||||
467 | } | ||||||
468 | |||||||
469 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Package\s+created\s+by:\s+(.*)\s+<([^\n\t]*)>/i){ | |||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
0 | |||||||
470 | 0 | 0 | $self->set_value('info-pacdatekager-mail',$2); | ||||
471 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
472 | } | ||||||
473 | elsif($self->{PACK}->{description}=~ /Packager:\s+(.*)\s+<(.*)>/i){ | ||||||
474 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
475 | 0 | 0 | $self->set_value('info-packager-mail',$2); | ||||
476 | } | ||||||
477 | elsif($self->{PACK}->{description}=~ /Package\s+created\s+.*by\s+(.*)\s+\(([^\n\t]*)\)/i){ | ||||||
478 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
479 | 0 | 0 | $self->set_value('info-packager-mail',$2); | ||||
480 | } | ||||||
481 | elsif ( $self->{PACK}->{description}=~ /Packaged by ([^\s]+) ([^\s]+) \((.*)\)/i) | ||||||
482 | { | ||||||
483 | 0 | 0 | $self->set_value('package-maintener',"$1 $2"); | ||||
484 | 0 | 0 | $self->set_value('info-packager-mail',$3); | ||||
485 | } | ||||||
486 | elsif($self->{PACK}->{description}=~ /\s*Package\s+Maintainer:\s+(.*)\s+\(([^\n\t]*)\)/i){ | ||||||
487 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
488 | 0 | 0 | $self->set_value('info-packager-mail',$2); | ||||
489 | } | ||||||
490 | elsif($self->{PACK}->{description}=~ /Packaged\s+by\s+(.*)\s+<([^\n\t]*)>/i){ | ||||||
491 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
492 | 0 | 0 | $self->set_value('info-packager-mail',$2); | ||||
493 | } | ||||||
494 | |||||||
495 | 0 | 0 | 0 | if ( $self->{PACK}->{description}=~ /Package created by ([^\s]+) ([^\s]+)/i) | |||
496 | { | ||||||
497 | 0 | 0 | $self->set_value('package-maintener',"$1 $2"); | ||||
498 | } | ||||||
499 | |||||||
500 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Packaged\s+by:?\s+(.*)(\s+(by|for|to|on))?/i){ | |||
501 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
502 | } | ||||||
503 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Package\s+created\s+by:?\s+([^\n\t]*)/i){ | |||
504 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
505 | } | ||||||
506 | |||||||
507 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Package\s+created\s+by\s+(.*)\s+\[([^\n\t]*)\]/i){ | |||
508 | 0 | 0 | $self->set_value('info-homepage',$2);date | ||||
0 | 0 | ||||||
509 | $self->set_value('package-maintener',$1); | ||||||
510 | } | ||||||
511 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Packager:\s+([^\n\t]*)/i){ | |||
512 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
513 | } | ||||||
514 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Packager\s+([^\n\t]*)/i){ | |||
515 | 0 | 0 | $self->set_value('package-maintener',$1); | ||||
516 | } | ||||||
517 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Home\s{0,1}page: ([^\n\t]*)/i){ | |||
518 | 0 | 0 | $self->set_value('info-homepage',$1); | ||||
519 | } | ||||||
520 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Package URL: ([^\n\t]*)/i){ | |||
521 | 0 | 0 | $self->set_value('info-homepage',$1); | ||||
522 | } | ||||||
523 | |||||||
524 | 0 | 0 | 0 | if($self->{PACK}->{description}=~ /Package creat(ed|e) with ([^\s]*) ([^\s]*)/i){ | |||
525 | 0 | 0 | $self->set_value('info-packager-tool',$2); | ||||
526 | 0 | 0 | $self->set_value('info-packager-tool-version',$3); | ||||
527 | } | ||||||
528 | |||||||
529 | } | ||||||
530 | |||||||
531 | =head2 to_XML (deprecated) | ||||||
532 | |||||||
533 | Same as to_xml(), provided for backward compatibility. | ||||||
534 | |||||||
535 | =cut | ||||||
536 | |||||||
537 | sub to_XML { | ||||||
538 | 1 | 1 | 1 | 6 | return to_xml(@_); | ||
539 | } | ||||||
540 | |||||||
541 | =head2 to_xml | ||||||
542 | |||||||
543 | return the package as an XML encoded string. | ||||||
544 | |||||||
545 | $xml = $package->to_xml(); | ||||||
546 | |||||||
547 | =cut | ||||||
548 | |||||||
549 | sub to_xml | ||||||
550 | { | ||||||
551 | 14 | 14 | 1 | 20 | my $self = shift; | ||
552 | |||||||
553 | 14 | 55 | my $xml = "\t |
||||
554 | 14 | 50 | 33 | 105 | if(defined($self->{STATUS}) && ref($self->{STATUS}) eq 'Slackware::Slackget::Status') | ||
555 | { | ||||||
556 | 0 | 0 | $xml .= "\t\t".$self->{STATUS}->to_xml()."\n"; | ||||
557 | } | ||||||
558 | 14 | 50 | 51 | if($self->{PACK}->{'package-date'}){ | |||
559 | 0 | 0 | $xml .= "\t\t".$self->{PACK}->{'package-date'}->to_xml(); | ||||
560 | 0 | 0 | $self->{TMP}->{'package-date'}=$self->{PACK}->{'package-date'}; | ||||
561 | 0 | 0 | delete($self->{PACK}->{'package-date'}); | ||||
562 | } | ||||||
563 | 14 | 50 | 51 | if($self->{PACK}->{'date'}){ | |||
564 | 0 | 0 | $xml .= "\t\t".$self->{PACK}->{'date'}->to_xml(); | ||||
565 | 0 | 0 | $self->{TMP}->{'date'}=$self->{PACK}->{'date'}; | ||||
566 | 0 | 0 | delete($self->{PACK}->{'date'}); | ||||
567 | } | ||||||
568 | 14 | 50 | 93 | if($self->{STATS}){ | |||
569 | 14 | 100 | 33 | 128 | if($self->{STATS}->{dwc} == 0 && scalar(@{$self->{STATS}->{hw}}) > 0 && defined($self->getValue('description')) ){ | ||
14 | 66 | 102 | |||||
570 | 2 | 17 | my @t = split(/\s/,$self->getValue('description')); | ||||
571 | 2 | 10 | $self->{STATS}->{dwc} = scalar(@t); | ||||
572 | } | ||||||
573 | # print "[Slackware::Slackget::Package->to_xml] $self->{ROOT} ($self) : |
||||||
574 | # print Dumper($self); |
||||||
575 | |||||||
576 | 14 | 128 | $xml .= "\t\t |
||||
14 | 62 | ||||||
577 | } | ||||||
578 | 14 | 50 | 57 | if($self->{PACK}->{'required'}){ | |||
579 | 0 | 0 | $xml .= "\t\t |
||||
580 | 0 | 0 | foreach my $dep ( @{$self->{PACK}->{'required'}} ){ | ||||
0 | 0 | ||||||
581 | 0 | 0 | 0 | next if(ref($dep) ne 'ARRAY'); | |||
582 | 0 | 0 | $xml .= "\t\t\t |
||||
583 | 0 | 0 | foreach my $ad (@{$dep}){ | ||||
0 | 0 | ||||||
584 | 0 | 0 | $xml .= "\t\t\t\t |
||||
585 | 0 | 0 | 0 | $xml .= " required_version=\"$ad->{required_version}\"" if($ad->{required_version}); | |||
586 | 0 | 0 | 0 | $xml .= " comparison_type=\"$ad->{comparison_type}\"" if($ad->{comparison_type}); | |||
587 | 0 | 0 | $xml .= "/>\n"; | ||||
588 | } | ||||||
589 | 0 | 0 | $xml .= "\t\t\t\n"; | ||||
590 | } | ||||||
591 | 0 | 0 | $xml .= "\t\t\n"; | ||||
592 | 0 | 0 | $self->{TMP}->{'required'}=$self->{PACK}->{'required'}; | ||||
593 | 0 | 0 | delete($self->{PACK}->{'required'}); | ||||
594 | } | ||||||
595 | 14 | 50 | 48 | if($self->{PACK}->{'suggested'}){ | |||
596 | 0 | 0 | $xml .= "\t\t |
||||
597 | 0 | 0 | foreach my $dep ( @{$self->{PACK}->{'suggested'}} ){ | ||||
0 | 0 | ||||||
598 | 0 | 0 | 0 | next if(ref($dep) ne 'ARRAY'); | |||
599 | 0 | 0 | $xml .= "\t\t\t |
||||
600 | 0 | 0 | foreach my $ad (@{$dep}){ | ||||
0 | 0 | ||||||
601 | 0 | 0 | $xml .= "\t\t\t\t |
||||
602 | 0 | 0 | 0 | $xml .= " required_version=\"$ad->{required_version}\"" if($ad->{required_version}); | |||
603 | 0 | 0 | 0 | $xml .= " comparison_type=\"$ad->{comparison_type}\"" if($ad->{comparison_type}); | |||
604 | 0 | 0 | $xml .= "/>\n"; | ||||
605 | } | ||||||
606 | 0 | 0 | $xml .= "\t\t\t\n"; | ||||
607 | } | ||||||
608 | 0 | 0 | $xml .= "\t\t\n"; | ||||
609 | 0 | 0 | $self->{TMP}->{'suggested'}=$self->{PACK}->{'suggested'}; | ||||
610 | 0 | 0 | delete($self->{PACK}->{'suggested'}); | ||||
611 | } | ||||||
612 | 14 | 28 | foreach (keys(%{$self->{PACK}})){ | ||||
14 | 65 | ||||||
613 | 68 | 50 | 148 | next if(/^_[A-Z_]+$/); | |||
614 | 68 | 50 | 443 | $xml .= "\t\t<$_>{PACK}->{$_}]]>$_>\n" if(defined($self->{PACK}->{$_})); | |||
615 | } | ||||||
616 | 14 | 57 | $self->{PACK}->{'package-date'}=$self->{TMP}->{'package-date'}; | ||||
617 | 14 | 31 | delete($self->{TMP}); | ||||
618 | 14 | 21 | $xml .= "\t\n"; | ||||
619 | 14 | 72 | return $xml; | ||||
620 | } | ||||||
621 | |||||||
622 | =head2 to_string | ||||||
623 | |||||||
624 | Return a string describing the package using the official Slackware text based semantic. | ||||||
625 | |||||||
626 | my $text = $package->to_string(); | ||||||
627 | |||||||
628 | In this case, $text contains something like that : | ||||||
629 | |||||||
630 | PACKAGE NAME: test_package-1.0-i486-1.tgz | ||||||
631 | PACKAGE LOCATION: ./path/to/test_package/ | ||||||
632 | PACKAGE SIZE (compressed): 677 K | ||||||
633 | PACKAGE SIZE (uncompressed): 1250 K | ||||||
634 | PACKAGE REQUIRED: acl >= 2.2.47_1-i486-1,attr >= 2.4.41_1-i486-1,cxxlibs >= 6.0.9-i486-1 | gcc-g++ >= 4.2.3-i486-1,expat >= 2.0.1-i486-1,fontconfig >= 2.4.2-i486-2,freetype >= 2.3.5-i486-1, | ||||||
635 | PACKAGE CONFLICTS: | ||||||
636 | PACKAGE SUGGESTS: | ||||||
637 | PACKAGE DESCRIPTION: | ||||||
638 | test_package: Test Package | ||||||
639 | test_package: | ||||||
640 | test_package: Test Package is a package for testing | ||||||
641 | test_package: the slack-get API. | ||||||
642 | test_package: | ||||||
643 | |||||||
644 | WARNING: This method behavior have changed compare to previous versions. | ||||||
645 | |||||||
646 | =cut | ||||||
647 | |||||||
648 | sub to_string{ | ||||||
649 | 2 | 2 | 1 | 6 | my $self = shift; | ||
650 | 2 | 5 | my $text = ''; | ||||
651 | 2 | 6 | $text .= "PACKAGE NAME: ".$self->get_id()."\n"; | ||||
652 | 2 | 9 | $text .= "PACKAGE LOCATION: ".$self->location()."\n"; | ||||
653 | 2 | 9 | $text .= "PACKAGE SIZE (compressed): ".$self->compressed_size()." K\n"; | ||||
654 | 2 | 9 | $text .= "PACKAGE SIZE (uncompressed): ".$self->uncompressed_size()." K\n"; | ||||
655 | 2 | 50 | 11 | if($self->{PACK}->{'required'}){ | |||
656 | 0 | 0 | $text .= "PACKAGE REQUIRED: "; | ||||
657 | 0 | 0 | foreach my $dep ( @{$self->{PACK}->{'required'}} ){ | ||||
0 | 0 | ||||||
658 | 0 | 0 | 0 | next if(ref($dep) ne 'ARRAY'); | |||
659 | 0 | 0 | foreach my $ad (@{$dep}){ | ||||
0 | 0 | ||||||
660 | 0 | 0 | $text .= "$ad->{pkg_name}"; | ||||
661 | 0 | 0 | 0 | $text .= " $ad->{comparison_type}" if($ad->{comparison_type}); | |||
662 | 0 | 0 | 0 | $text .= " $ad->{required_version}" if($ad->{required_version}); | |||
663 | 0 | 0 | $text .= "|"; | ||||
664 | } | ||||||
665 | 0 | 0 | chop($text); | ||||
666 | 0 | 0 | $text .= ","; | ||||
667 | } | ||||||
668 | 0 | 0 | chop($text); | ||||
669 | 0 | 0 | $text .= "\n"; | ||||
670 | } | ||||||
671 | 2 | 50 | 17 | if($self->{PACK}->{'suggested'}){ | |||
672 | 0 | 0 | $text .= "PACKAGE SUGGESTS: "; | ||||
673 | 0 | 0 | foreach my $dep ( @{$self->{PACK}->{'suggested'}} ){ | ||||
0 | 0 | ||||||
674 | 0 | 0 | 0 | next if(ref($dep) ne 'ARRAY'); | |||
675 | 0 | 0 | foreach my $ad (@{$dep}){ | ||||
0 | 0 | ||||||
676 | 0 | 0 | $text .= "$ad->{pkg_name}"; | ||||
677 | 0 | 0 | 0 | $text .= " $ad->{comparison_type}" if($ad->{comparison_type}); | |||
678 | 0 | 0 | 0 | $text .= " $ad->{required_version}" if($ad->{required_version}); | |||
679 | 0 | 0 | $text .= "|"; | ||||
680 | } | ||||||
681 | 0 | 0 | chop($text); | ||||
682 | 0 | 0 | $text .= ","; | ||||
683 | } | ||||||
684 | 0 | 0 | chop($text); | ||||
685 | 0 | 0 | $text .= "\n"; | ||||
686 | } | ||||||
687 | 2 | 50 | 14 | if($self->{PACK}->{'conflicts'}){ | |||
688 | 0 | 0 | $text .= "PACKAGE CONFLICTS: "; | ||||
689 | 0 | 0 | foreach my $dep ( @{$self->{PACK}->{'conflicts'}} ){ | ||||
0 | 0 | ||||||
690 | 0 | 0 | 0 | next if(ref($dep) ne 'ARRAY'); | |||
691 | 0 | 0 | foreach my $ad (@{$dep}){ | ||||
0 | 0 | ||||||
692 | 0 | 0 | $text .= "$ad->{pkg_name}"; | ||||
693 | 0 | 0 | 0 | $text .= " $ad->{comparison_type}" if($ad->{comparison_type}); | |||
694 | 0 | 0 | 0 | $text .= " $ad->{required_version}" if($ad->{required_version}); | |||
695 | 0 | 0 | $text .= "|"; | ||||
696 | } | ||||||
697 | 0 | 0 | chop($text); | ||||
698 | 0 | 0 | $text .= ","; | ||||
699 | } | ||||||
700 | 0 | 0 | chop($text); | ||||
701 | 0 | 0 | $text .= "\n"; | ||||
702 | } | ||||||
703 | 2 | 8 | my $short_name = lc( $self->name() ); | ||||
704 | 2 | 9 | $text .= "PACKAGE DESCRIPTION:\n$short_name: ".$self->get_value('shortdescription')."\n$short_name: \n"; | ||||
705 | 2 | 39 | foreach my $l ( split(/\.\s*/,$self->description() )){ | ||||
706 | 2 | 12 | $text .= "$short_name: $l.\n"; | ||||
707 | } | ||||||
708 | 2 | 6 | $text .= "$short_name: \n"; | ||||
709 | 2 | 57 | return $text; | ||||
710 | } | ||||||
711 | |||||||
712 | =head2 to_HTML (deprecated) | ||||||
713 | |||||||
714 | Same as to_html(), provided for backward compatibility. | ||||||
715 | |||||||
716 | =cut | ||||||
717 | |||||||
718 | sub to_HTML { | ||||||
719 | 1 | 1 | 1 | 5 | return to_html(@_); | ||
720 | } | ||||||
721 | |||||||
722 | =head2 to_html | ||||||
723 | |||||||
724 | return the package as an HTML string | ||||||
725 | |||||||
726 | my $html = $package->to_html ; | ||||||
727 | |||||||
728 | Note: I have design this method for 2 reasons. First for an easy integration of the search result in a GUI, second for my website search engine. So this HTML may not satisfy you. In this case just generate new HTML from accessors ;-) | ||||||
729 | |||||||
730 | =cut | ||||||
731 | |||||||
732 | sub to_html | ||||||
733 | { | ||||||
734 | 14 | 14 | 1 | 23 | my $self = shift; | ||
735 | 14 | 44 | my $html = "\t$self->{ROOT}\n"; |
||||
736 | 14 | 50 | 33 | 187 | if(defined($self->{STATUS}) && ref($self->{STATUS}) eq 'Slackware::Slackget::Status') | ||
737 | { | ||||||
738 | 0 | 0 | $html .= "\t\t".$self->{STATUS}->to_html()."\n"; | ||||
739 | } | ||||||
740 | 14 | 50 | 46 | if($self->{PACK}->{'package-date'}){ | |||
741 | 0 | 0 | $html .= "\t\t".$self->{PACK}->{'package-date'}->to_html(); | ||||
742 | 0 | 0 | $self->{TMP}->{'package-date'}=$self->{PACK}->{'package-date'}; | ||||
743 | 0 | 0 | delete($self->{PACK}->{'package-date'}); | ||||
744 | } | ||||||
745 | 14 | 50 | 66 | if($self->{PACK}->{'date'}){ | |||
746 | 0 | 0 | $html .= "\t\t".$self->{PACK}->{'date'}->to_html(); | ||||
747 | 0 | 0 | $self->{TMP}->{'date'}=$self->{PACK}->{'date'}; | ||||
748 | 0 | 0 | delete($self->{PACK}->{'date'}); | ||||
749 | } | ||||||
750 | 14 | 17 | foreach (keys(%{$self->{PACK}})){ | ||||
14 | 53 | ||||||
751 | 82 | 50 | 223 | if($_ eq 'package-source') | |||
752 | { | ||||||
753 | 0 | 0 | 0 | $html .= "$_ : $self->{PACK}->{$_} \n" if(defined($self->{PACK}->{$_})); |
|||
754 | } | ||||||
755 | else | ||||||
756 | { | ||||||
757 | 82 | 100 | 1447 | $html .= "$_ : $self->{PACK}->{$_} \n" if(defined($self->{PACK}->{$_})); |
|||
758 | } | ||||||
759 | } | ||||||
760 | 14 | 52 | $self->{PACK}->{'package-date'}=$self->{TMP}->{'package-date'}; | ||||
761 | 14 | 31 | delete($self->{TMP}); | ||||
762 | 14 | 20 | $html .="\n"; | ||||
763 | 14 | 60 | return $html; | ||||
764 | } | ||||||
765 | |||||||
766 | =head1 PRINTING METHODS | ||||||
767 | |||||||
768 | =head2 print_restricted_info | ||||||
769 | |||||||
770 | Print a part of package information. | ||||||
771 | |||||||
772 | $package->print_restricted_info(); | ||||||
773 | |||||||
774 | =cut | ||||||
775 | |||||||
776 | sub print_restricted_info { | ||||||
777 | 0 | 0 | 1 | 0 | my $self = shift; | ||
778 | 0 | 0 | print "Information on package ".$self->get_id." :\n". | ||||
779 | "\tshort name : ".$self->name()." \n". | ||||||
780 | "\tArchitecture : ".$self->architecture()." \n". | ||||||
781 | "\tDownload size : ".$self->compressed_size()." KB \n". | ||||||
782 | "\tSource : ".$self->getValue('package-source')."\n". | ||||||
783 | "\tPackage version : ".$self->version()." \n"; | ||||||
784 | } | ||||||
785 | |||||||
786 | =head2 print_full_info | ||||||
787 | |||||||
788 | Print all informations found in the package. | ||||||
789 | |||||||
790 | $package->print_full_info(); | ||||||
791 | |||||||
792 | =cut | ||||||
793 | |||||||
794 | sub print_full_info { | ||||||
795 | 0 | 0 | 1 | 0 | my $self = shift; | ||
796 | 0 | 0 | print "Information on package ".$self->get_id." :\n"; | ||||
797 | 0 | 0 | foreach (keys(%{$self->{PACK}})) { | ||||
0 | 0 | ||||||
798 | 0 | 0 | print "\t$_ : $self->{PACK}->{$_}\n"; | ||||
799 | } | ||||||
800 | } | ||||||
801 | |||||||
802 | =head2 fprint_restricted_info | ||||||
803 | |||||||
804 | Same as print_restricted_info, but output in HTML | ||||||
805 | |||||||
806 | $package->fprint_restricted_info(); | ||||||
807 | |||||||
808 | =cut | ||||||
809 | |||||||
810 | sub fprint_restricted_info { | ||||||
811 | 0 | 0 | 1 | 0 | my $self = shift; | ||
812 | 0 | 0 | print " \n". |
||||
813 | " short name : ".$self->name()." \n". |
||||||
814 | " Architecture : ".$self->architecture()." \n". |
||||||
815 | " Download size : ".$self->compressed_size()." KB \n". |
||||||
816 | " Source : ".$self->getValue('package-source')." \n". |
||||||
817 | " Package version : ".$self->version()." \n"; |
||||||
818 | } | ||||||
819 | |||||||
820 | =head2 fprint_full_info | ||||||
821 | |||||||
822 | Same as print_full_info, but output in HTML | ||||||
823 | |||||||
824 | $package->fprint_full_info(); | ||||||
825 | |||||||
826 | =cut | ||||||
827 | |||||||
828 | sub fprint_full_info { | ||||||
829 | 0 | 0 | 1 | 0 | my $self = shift; | ||
830 | 0 | 0 | print " \n"; |
||||
831 | 0 | 0 | foreach (keys(%{$self->{PACK}})){ | ||||
0 | 0 | ||||||
832 | 0 | 0 | print " $_ : $self->{PACK}->{$_} \n"; |
||||
833 | } | ||||||
834 | } | ||||||
835 | |||||||
836 | =head1 ACCESSORS | ||||||
837 | |||||||
838 | =head2 set_value | ||||||
839 | |||||||
840 | Set the value of a named key to the value passed in argument. | ||||||
841 | |||||||
842 | $package->set_value($key,$value); | ||||||
843 | |||||||
844 | Return $value (for integrity check). | ||||||
845 | |||||||
846 | =cut | ||||||
847 | |||||||
848 | sub set_value { | ||||||
849 | 80 | 80 | 1 | 247 | my ($self,$key,$value) = @_ ; | ||
850 | # print "Setting $key=$value for $self\n"; | ||||||
851 | 80 | 374 | $self->{PACK}->{$key} = $value ; | ||||
852 | 80 | 209 | return $self->{PACK}->{$key}; | ||||
853 | } | ||||||
854 | |||||||
855 | =head2 setValue (deprecated) | ||||||
856 | |||||||
857 | Same as set_value(), provided for backward compatibility. | ||||||
858 | |||||||
859 | =cut | ||||||
860 | |||||||
861 | sub setValue { | ||||||
862 | 2 | 2 | 1 | 6 | return set_value(@_); | ||
863 | } | ||||||
864 | |||||||
865 | =head2 getValue (deprecated) | ||||||
866 | |||||||
867 | Same as get_value(), provided for backward compatibility. | ||||||
868 | |||||||
869 | =cut | ||||||
870 | |||||||
871 | sub getValue { | ||||||
872 | 58 | 58 | 1 | 121 | return get_value(@_); | ||
873 | } | ||||||
874 | |||||||
875 | =head2 get_value | ||||||
876 | |||||||
877 | Return the value of a key : | ||||||
878 | |||||||
879 | $string = $package->get_value($key); | ||||||
880 | |||||||
881 | =cut | ||||||
882 | |||||||
883 | sub get_value { | ||||||
884 | 62 | 62 | 1 | 96 | my ($self,$key) = @_ ; | ||
885 | 62 | 551 | return $self->{PACK}->{$key}; | ||||
886 | } | ||||||
887 | |||||||
888 | =head2 status | ||||||
889 | |||||||
890 | Return the current status of the package object as a Slackware::Slackget::Status object. This object is set by other class, and in most case you don't have to set it by yourself. | ||||||
891 | |||||||
892 | print "The current status for ",$package->name," is ",$package->status()->to_string,"\n"; | ||||||
893 | |||||||
894 | You also can set the status, by passing a Slackware::Slackget::Status object, to this method. | ||||||
895 | |||||||
896 | $package->status($status_object); | ||||||
897 | |||||||
898 | This method return 1 if all goes well and undef else. | ||||||
899 | |||||||
900 | =cut | ||||||
901 | |||||||
902 | sub status { | ||||||
903 | 0 | 0 | 1 | 0 | my ($self,$status) = @_ ; | ||
904 | 0 | 0 | 0 | if(defined($status)) | |||
905 | { | ||||||
906 | 0 | 0 | 0 | return undef if(ref($status) ne 'Slackware::Slackget::Status'); | |||
907 | 0 | 0 | $self->{STATUS} = $status ; | ||||
908 | } | ||||||
909 | else | ||||||
910 | { | ||||||
911 | 0 | 0 | return $self->{STATUS} ; | ||||
912 | } | ||||||
913 | |||||||
914 | 0 | 0 | return 1; | ||||
915 | } | ||||||
916 | |||||||
917 | =head2 add_dependency | ||||||
918 | |||||||
919 | Add a dependency to the package. Parameters are : | ||||||
920 | |||||||
921 | * the type of dependency between : required, suggested, conflicts | ||||||
922 | * the dependency as a hashref containing the following keys : pkg_name (mandatory), comparison_type and required_version (optional). | ||||||
923 | |||||||
924 | $package->add_dependency('required',{pkg_name => 'gcc', comparison_type => '>=', required_version => '4.2'}) ; | ||||||
925 | |||||||
926 | If you want to let a choice between 2 or more dependencies (like between cxxlibs and gcc-g++), use an arrayref which contains as mush hashref as needed : | ||||||
927 | |||||||
928 | $package->add_dependency('required',[{pkg_name => 'gcc-g++', comparison_type => '>=', required_version => '4.2.3'},{pkg_name => 'cxxlibs', comparison_type => '>=', required_version => '6.0.9'}]) ; | ||||||
929 | |||||||
930 | =cut | ||||||
931 | |||||||
932 | sub add_dependency { | ||||||
933 | 0 | 0 | 1 | 0 | my ($self,$type,$dep) = @_ ; | ||
934 | 0 | 0 | 0 | 0 | if(defined($type) && ($type eq 'required' || $type eq 'suggested' || $type eq 'conflicts') ){ | ||
0 | |||||||
935 | 0 | 0 | my $deps_array = $self->get_value($type); | ||||
936 | 0 | 0 | 0 | if( ref($dep) eq 'HASH' ){ | |||
0 | |||||||
937 | # print "Slackware::Slackget::Package->add_dependency(): adding a single dependency\n"; | ||||||
938 | 0 | 0 | push @{$deps_array},[$dep]; | ||||
0 | 0 | ||||||
939 | } | ||||||
940 | elsif( ref($dep) eq 'ARRAY' ){ | ||||||
941 | # print "Slackware::Slackget::Package->add_dependency(): adding an array of dependencies\n"; | ||||||
942 | 0 | 0 | push @{$deps_array},$dep; | ||||
0 | 0 | ||||||
943 | } | ||||||
944 | } | ||||||
945 | else{ | ||||||
946 | 0 | 0 | return 0; | ||||
947 | } | ||||||
948 | } | ||||||
949 | |||||||
950 | =head2 _setId [PRIVATE] | ||||||
951 | |||||||
952 | set the package ID (normally the package complete name, like aaa_base-10.0.0-noarch-1). In normal use you don't need to use this method | ||||||
953 | |||||||
954 | $package->_setId('aaa_base-10.0.0-noarch-1'); | ||||||
955 | |||||||
956 | =cut | ||||||
957 | |||||||
958 | sub _setId{ | ||||||
959 | 0 | 0 | 0 | my ($self,$id)=@_; | |||
960 | 0 | 0 | $self->{ROOT} = $id; | ||||
961 | } | ||||||
962 | |||||||
963 | =head2 get_id | ||||||
964 | |||||||
965 | return the package id (full name, like aaa_base-10.0.0-noarch-1). | ||||||
966 | |||||||
967 | $string = $package->get_id(); | ||||||
968 | |||||||
969 | =cut | ||||||
970 | |||||||
971 | sub get_id { | ||||||
972 | 8 | 8 | 1 | 16 | my $self= shift; | ||
973 | 8 | 47 | return $self->{ROOT}; | ||||
974 | } | ||||||
975 | |||||||
976 | =head2 description | ||||||
977 | |||||||
978 | return the description of the package. | ||||||
979 | |||||||
980 | $string = $package->description(); | ||||||
981 | |||||||
982 | =cut | ||||||
983 | |||||||
984 | sub description{ | ||||||
985 | 6 | 6 | 1 | 26 | my $self = shift; | ||
986 | 6 | 41 | return $self->{PACK}->{description}; | ||||
987 | } | ||||||
988 | |||||||
989 | =head2 filelist | ||||||
990 | |||||||
991 | return the list of files in the package. WARNING: by default this list is not included ! | ||||||
992 | |||||||
993 | $string = $package->filelist(); | ||||||
994 | |||||||
995 | =cut | ||||||
996 | |||||||
997 | sub filelist{ | ||||||
998 | 0 | 0 | 1 | 0 | my $self = shift; | ||
999 | 0 | 0 | return $self->{PACK}->{'file-list'}; | ||||
1000 | } | ||||||
1001 | |||||||
1002 | =head2 name | ||||||
1003 | |||||||
1004 | return the name of the package. | ||||||
1005 | Ex: for the package aaa_base-10.0.0-noarch-1 name() will return aaa_base | ||||||
1006 | |||||||
1007 | my $string = $package->name(); | ||||||
1008 | |||||||
1009 | =cut | ||||||
1010 | |||||||
1011 | sub name{ | ||||||
1012 | 4 | 4 | 1 | 8 | my $self = shift; | ||
1013 | 4 | 27 | return $self->{PACK}->{name}; | ||||
1014 | } | ||||||
1015 | |||||||
1016 | =head2 compressed_size | ||||||
1017 | |||||||
1018 | return the compressed size of the package | ||||||
1019 | |||||||
1020 | $number = $package->compressed_size(); | ||||||
1021 | |||||||
1022 | =cut | ||||||
1023 | |||||||
1024 | sub compressed_size{ | ||||||
1025 | 2 | 2 | 1 | 10 | my $self = shift; | ||
1026 | 2 | 9 | return $self->{PACK}->{'compressed-size'}; | ||||
1027 | } | ||||||
1028 | |||||||
1029 | =head2 uncompressed_size | ||||||
1030 | |||||||
1031 | return the uncompressed size of the package | ||||||
1032 | |||||||
1033 | $number = $package->uncompressed_size(); | ||||||
1034 | |||||||
1035 | =cut | ||||||
1036 | |||||||
1037 | sub uncompressed_size{ | ||||||
1038 | 2 | 2 | 1 | 3 | my $self = shift; | ||
1039 | 2 | 9 | return $self->{PACK}->{'uncompressed-size'}; | ||||
1040 | } | ||||||
1041 | |||||||
1042 | =head2 location | ||||||
1043 | |||||||
1044 | return the location of the installed package. | ||||||
1045 | |||||||
1046 | $string = $package->location(); | ||||||
1047 | |||||||
1048 | =cut | ||||||
1049 | |||||||
1050 | sub location{ | ||||||
1051 | 2 | 2 | 1 | 5 | my $self = shift; | ||
1052 | 2 | 50 | 33 | 22 | if(exists($self->{PACK}->{'package-location'}) && defined($self->{PACK}->{'package-location'})) | ||
1053 | { | ||||||
1054 | 2 | 9 | return $self->{PACK}->{'package-location'}; | ||||
1055 | } | ||||||
1056 | else | ||||||
1057 | { | ||||||
1058 | 0 | 0 | return $self->{PACK}->{location}; | ||||
1059 | } | ||||||
1060 | |||||||
1061 | } | ||||||
1062 | |||||||
1063 | =head2 conflicts | ||||||
1064 | |||||||
1065 | return the list of conflicting pakage. | ||||||
1066 | |||||||
1067 | $string = $package->conflicts(); | ||||||
1068 | |||||||
1069 | =cut | ||||||
1070 | |||||||
1071 | sub conflicts{ | ||||||
1072 | 0 | 0 | 1 | 0 | my $self = shift; | ||
1073 | 0 | 0 | return $self->{PACK}->{conflicts}; | ||||
1074 | } | ||||||
1075 | |||||||
1076 | =head2 suggested | ||||||
1077 | |||||||
1078 | return the suggested package related to the current package. | ||||||
1079 | |||||||
1080 | $string = $package->suggested(); | ||||||
1081 | |||||||
1082 | =cut | ||||||
1083 | |||||||
1084 | sub suggested{ | ||||||
1085 | 0 | 0 | 1 | 0 | my $self = shift; | ||
1086 | 0 | 0 | return $self->{PACK}->{suggested}; | ||||
1087 | } | ||||||
1088 | |||||||
1089 | =head2 required | ||||||
1090 | |||||||
1091 | return the required packages for installing the current package | ||||||
1092 | |||||||
1093 | $string = $package->required(); | ||||||
1094 | |||||||
1095 | =cut | ||||||
1096 | |||||||
1097 | sub required{ | ||||||
1098 | 0 | 0 | 1 | 0 | my $self = shift; | ||
1099 | 0 | 0 | return $self->{PACK}->{required}; | ||||
1100 | } | ||||||
1101 | |||||||
1102 | =head2 architecture | ||||||
1103 | |||||||
1104 | return the architecture the package is compiled for. | ||||||
1105 | |||||||
1106 | $string = $package->architecture(); | ||||||
1107 | |||||||
1108 | =cut | ||||||
1109 | |||||||
1110 | sub architecture { | ||||||
1111 | 2 | 2 | 1 | 5 | my $self = shift; | ||
1112 | 2 | 11 | return $self->{PACK}->{architecture}; | ||||
1113 | } | ||||||
1114 | |||||||
1115 | =head2 version | ||||||
1116 | |||||||
1117 | return the package version. | ||||||
1118 | |||||||
1119 | $string = $package->version(); | ||||||
1120 | |||||||
1121 | =cut | ||||||
1122 | |||||||
1123 | sub version { | ||||||
1124 | 100 | 100 | 1 | 119 | my $self = shift; | ||
1125 | 100 | 399 | return $self->{PACK}->{version}; | ||||
1126 | } | ||||||
1127 | |||||||
1128 | =head2 get_fields_list | ||||||
1129 | |||||||
1130 | return a list of all fields of the package. This method is suitable for example in GUI for displaying informations on packages. | ||||||
1131 | |||||||
1132 | foreach my $field ( $package->get_fields_list ) | ||||||
1133 | { | ||||||
1134 | qt_textbrowser->append( "$field : ".$package->getValue( $field )." \n" ) ; |
||||||
1135 | } | ||||||
1136 | |||||||
1137 | =cut | ||||||
1138 | |||||||
1139 | sub get_fields_list | ||||||
1140 | { | ||||||
1141 | 2 | 2 | 1 | 6 | my $self = shift ; | ||
1142 | 2 | 4 | return keys(%{$self->{PACK}}) ; | ||||
2 | 13 | ||||||
1143 | } | ||||||
1144 | |||||||
1145 | # | ||||||
1146 | # =head2 | ||||||
1147 | # | ||||||
1148 | # return the | ||||||
1149 | # | ||||||
1150 | # =cut | ||||||
1151 | # | ||||||
1152 | # sub { | ||||||
1153 | # my $self = shift; | ||||||
1154 | # return $self->{PACK}->{}; | ||||||
1155 | # } | ||||||
1156 | |||||||
1157 | =head1 AUTHOR | ||||||
1158 | |||||||
1159 | DUPUIS Arnaud, C<< |
||||||
1160 | |||||||
1161 | =head1 BUGS | ||||||
1162 | |||||||
1163 | Please report any bugs or feature requests to | ||||||
1164 | C |
||||||
1165 | L |
||||||
1166 | I will be notified, and then you'll automatically be notified of progress on | ||||||
1167 | your bug as I make changes. | ||||||
1168 | |||||||
1169 | =head1 SUPPORT | ||||||
1170 | |||||||
1171 | You can find documentation for this module with the perldoc command. | ||||||
1172 | |||||||
1173 | perldoc Slackware::Slackget::Package | ||||||
1174 | |||||||
1175 | |||||||
1176 | You can also look for information at: | ||||||
1177 | |||||||
1178 | =over 4 | ||||||
1179 | |||||||
1180 | =item * Infinity Perl website | ||||||
1181 | |||||||
1182 | L |
||||||
1183 | |||||||
1184 | =item * slack-get specific website | ||||||
1185 | |||||||
1186 | L |
||||||
1187 | |||||||
1188 | =item * RT: CPAN's request tracker | ||||||
1189 | |||||||
1190 | L |
||||||
1191 | |||||||
1192 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||
1193 | |||||||
1194 | L |
||||||
1195 | |||||||
1196 | =item * CPAN Ratings | ||||||
1197 | |||||||
1198 | L |
||||||
1199 | |||||||
1200 | =item * Search CPAN | ||||||
1201 | |||||||
1202 | L |
||||||
1203 | |||||||
1204 | =back | ||||||
1205 | |||||||
1206 | =head1 ACKNOWLEDGEMENTS | ||||||
1207 | |||||||
1208 | Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation. | ||||||
1209 | |||||||
1210 | =head1 SEE ALSO | ||||||
1211 | |||||||
1212 | =head1 COPYRIGHT & LICENSE | ||||||
1213 | |||||||
1214 | Copyright 2005 DUPUIS Arnaud, All Rights Reserved. | ||||||
1215 | |||||||
1216 | This program is free software; you can redistribute it and/or modify it | ||||||
1217 | under the same terms as Perl itself. | ||||||
1218 | |||||||
1219 | =cut | ||||||
1220 | |||||||
1221 | 1; # End of Slackware::Slackget::Package |