blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Slp.pm

filter: Statementstmt 22.7% 25 / 110 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 44.4% 8 / 18 Podpod 100% 10 / 10 totaltotal 23.3% 43 / 184 CC 24 SCAR 28.8
CC
24
Cov
16%
scan
42.0
copyright
30.0
arch
30.0
CRAP 17.8
« blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package.pm ↑ Summary blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Lsb.pm »
1 #!/usr/bin/perl -w
2  
3 =head1 NAME
4  
5 Alien::Package::Slp - an object that represents a slp package
6  
7 =cut
8  
9 package Alien::Package::Slp;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use base qw(Alien::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 DESCRIPTION
14  
15 This is an object class that represents a slp package. It is derived from
16 Alien::Package.
17  
18 =head1 CLASS DATA
19  
20 The following data is global to the class, and is used to describe the slp
21 package format, which this class processes directly.
22  
23 =over 4
24  
25 =item footer_size
26  
27 Complete sizeof(slpformat) from slp.h in the stampede package manager
28 source.
29  
30 =item footer_packstring
31  
32 This is the pack format string for the footer. (A=space terminated
33 character, I=unsigned integer.)
34  
35 =item footer_version
36  
37 What package format are we up to now? (Lowest one this is still
38 compatible with.)
39  
40 =item archtrans
41  
42 This is a translation table between architectures and the number
43 that represents them in a slp package.
44  
45 =item fieldlist
46  
47 This is a list of all the fields in the order they appear in the footer.
48  
49 =cut
50  
51 1 ▶use constant footer_size => 3784;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 1 ▶use constant footer_packstring => "A756IIIIA128A128A80A1536A512A512A30A30IA20A20III";
Subroutine BEGIN: called CC=1 SCAR=0.0
53 1 ▶use constant footer_version => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 1 ▶use constant archtrans => {
Subroutine BEGIN: called CC=1 SCAR=0.0
55 0 => 'all',
56 1 => 'i386',
57 2 => 'sparc',
58 3 => 'alpha',
59 4 => 'powerpc',
60 5 => 'm68k',
61 1 };
62 1 ▶use constant copyrighttrans => {
Subroutine BEGIN: called CC=1 SCAR=0.0
63 0 => 'GPL',
64 1 => 'BSD',
65 2 => 'LGPL',
66 3 => 'unknown',
67 254 => 'unknown',
68 1 };
69 1 ▶use constant fieldlist => [qw{conffiles priority compresstype release copyright
Subroutine BEGIN: called CC=1 SCAR=0.0
70 conflicts setupscript summary description depends
71 provides maintainer date compiler version name
72 1 arch group slpkgversion}];
73  
74 =back
75  
76 =head1 FIELDS
77  
78 =over 4
79  
80 =item compresstype
81  
82 Holds the compression type used in the slp file.
83  
84 =item slpkgversion
85  
86 Holds the slp package format version of the slp file.
87  
88 =back
89  
90 =head1 METHODS
91  
92 =over 4
93  
94 =item checkfile
95  
96 Detect slp files by their extension.
97  
98 =cut
99  
100 0 ▶sub checkfile {
Subroutine checkfile: not called CC=1 SCAR=6.9
Pod documented
101 0 my $this=shift;
102 0 my $file=shift;
103  
104 0 return $file =~ m/.*\.slp$/;
105 }
106  
107 =item install
108  
109 Install a slp. Pass in the filename of the slp to install.
110  
111 =cut
112  
113 0 ▶sub install {
Subroutine install: not called CC=2 SCAR=17.9
Pod documented
114 0 my $this=shift;
115 0 my $slp=shift;
116  
117 0 my $v=$Alien::Package::verbose;
118 0 $Alien::Package::verbose=2;
119 0 ▶ $this->do("slpi", $slp)
Branch: 1 branch
BranchTrueFalseTotal
$this->do("slpi", $slp) or die "Unable to install" 0 0 0
120 or die "Unable to install";
121 0 $Alien::Package::verbose=$v;
122 }
123  
124 =item getfooter
125  
126 Pulls the footer out of the slp file and returns it.
127  
128 =cut
129  
130 0 ▶sub getfooter {
Subroutine getfooter: not called CC=2 SCAR=17.9
Pod documented
131 0 my $this=shift;
132 0 my $file=$this->filename;
133  
134 0 ▶ open (SLP,"<$file") || die "$file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open SLP, "<$file" or die "${file}: $!" 0 0 0
135 # position at beginning of footer (2 = seek from EOF)
136 0 seek SLP,(- footer_size),2;
137 0 read SLP,$_,footer_size;
138 0 close SLP;
139 0 return $_;
140 }
141  
142 =item scan
143  
144 Implement the scan method to read a slp file.
145  
146 =cut
147  
148 0 ▶sub scan {
Subroutine scan: not called CC=6 SCAR=37.4
Pod documented
149 0 my $this=shift;
150 0 $this->SUPER::scan(@_);
151 0 my $file=$this->filename;
152  
153 # Decode the footer.
154 0 my @values=unpack(footer_packstring(),$this->getfooter);
155 # Populate fields.
156 0 foreach my $field (@{fieldlist()}) {
157 0 $_=shift @values;
158 0 $this->$field($_);
159 }
160  
161 # A simple sanity check.
162 0 ▶ if (! defined $this->slpkgversion || $this->slpkgversion < footer_version()) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $this->slpkgversion or $this->slpkgversion < 5) 0 0 0
Condition0%0/3
not defined $this->slpkgversion or $this->slpkgversion < 5
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $this->slpkgversion or $this->slpkgversion < 5
not defined $this->slpkgversion $this->slpkgversion < 5
Truth table0%0/3
not(A) or B
A= not defined $this->slpkgversionB= $this->slpkgversion < 5
ABresult
1X1
011
000
163 0 die "unsupported stampede package version";
164 }
165  
166 # Read in the file list.
167 0 my @filelist;
168 # FIXME: support gzip files too!
169 0 foreach ($this->runpipe(0, "bzip2 -d < '$file' | tar -tf -")) {
170 0 chomp;
171 0 s:^\./:/:;
172 0 ▶ $_="/$_" unless m:^/:;
Branch: 1 branch
BranchTrueFalseTotal
unless m[^/] 0 0 0
173 0 push @filelist, $_;
174 }
175 0 $this->filelist(\@filelist);
176  
177 # TODO: read in postinst script.
178  
179 0 $this->distribution('Stampede');
180 0 $this->origformat('slp');
181 0 $this->changelogtext('');
182 0 $this->binary_info($this->runpipe(0, "ls -l '$file'"));
183
184 0 return 1;
185 }
186  
187 =item unpack
188  
189 Unpack a slp file. They can be compressed in various ways, depending on
190 what is in the compresstype field.
191  
192 =cut
193  
194 0 ▶sub unpack {
Subroutine unpack: not called CC=3 SCAR=24.8
Pod documented
195 0 my $this=shift;
196 0 $this->SUPER::unpack(@_);
197 0 my $file=$this->filename;
198 0 my $compresstype=$this->compresstype;
199  
200 0 ▶ if ($compresstype == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($compresstype == 0) { } 0 0 0
elsif ($compresstype == 1) { } 0 0 0
201 0 $this->do("bzip2 -d < $file | (cd ".$this->unpacked_tree."; tar xpf -)")
202 }
203 elsif ($compresstype == 1) {
204 0 $this->do("gzip -dc $file | (cd ".$this->unpacked_tree."; tar xpf -)")
205 }
206 else {
207 0 die "package uses an unknown compression type, $compresstype (please file a bug report)";
208 }
209  
210 0 return 1;
211 }
212  
213 =item build
214  
215 Build a slp.
216  
217 =cut
218  
219 0 ▶sub build {
Subroutine build: not called CC=3 SCAR=24.8
Pod documented
220 0 my $this=shift;
221 0 my $slp=$this->name."-".$this->version.".slp";
222
223 # Now generate the footer.
224 # We cannot use the actual $slp::footer_packstring, becuase it uses
225 # space terminated strings (A) instead of null terminated strings
226 # (a). That is good for decoding, but not for encoding.
227 0 my $fmt=footer_packstring();
228 0 $fmt=~tr/A/a/;
229 0 my $footer=pack($fmt,
230 $this->conffiles,
231 2, # Use priority optional for alien packages.
232 0, # Always use bzip2 as the compression type.
233 $this->release,
234 254, # Don't try to guess copyright, just use unknown.
235 '', # Conflicts.
236 '', # Set up script. TODO
237 $this->summary,
238 $this->description,
239 '', # $this->depends would go here, but slp uses some weird format
240 '', # Provides.
241 $this->maintainer,
242 scalar localtime, # Use current date.
243 252, # Unknown compiler.
244 $this->version,
245 $this->name,
246 $this->arch,
247 252, # Unknown group.
248 footer_version(),
249 );
250  
251 # Generate .tar.bz2 file.
252 # Note that it's important I use "./*" instead of just "." or
253 # something like that, becuase it results in a tar file where all
254 # the files in it start with "./", which is consitent with how
255 # normal stampede files look.
256 0 ▶ $this->do("(cd ".$this->unpacked_tree."; tar cf - ./*) | bzip2 - > $slp")
Branch: 1 branch
BranchTrueFalseTotal
$this->do('(cd ' . $this->unpacked_tree . "; tar cf - ./*) | bzip2 - > $slp") or die "package build failed: $!" 0 0 0
257 or die "package build failed: $!";
258  
259 # Now append the footer.
260 0 ▶ open (OUT,">>$slp") || die "$slp: $!";
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">>$slp" or die "${slp}: $!" 0 0 0
261 0 print OUT $footer;
262 0 close OUT;
263  
264 0 return $slp;
265 }
266  
267 =item conffiles
268  
269 Set/get conffiles.
270  
271 When the conffiles are set, the format used by slp (a colon-delimited list)
272 is turned into the real list that is used internally. The list is changed
273 back into slp's internal format when it is retrieved.
274  
275 =cut
276  
277 0 ▶sub conffiles {
Subroutine conffiles: not called CC=3 SCAR=24.8
Pod documented
278 0 my $this=shift;
279  
280 # set
281 0 ▶ $this->{conffiles}=[split /:/, shift] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
282  
283 # get
284 0 ▶ return unless defined wantarray; # optimization
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
285 0 return join(':',@{$this->{conffiles}});
286 }
287  
288 =item copyright
289  
290 Set/get copyright.
291  
292 When the copyright is set, the number used by slp is changed into a textual
293 description. This is changed back into a number when the value is
294 retrieved.
295  
296 =cut
297  
298 0 ▶sub copyright {
Subroutine copyright: not called CC=5 SCAR=34.0
Pod documented
299 0 my $this=shift;
300  
301 # set
302 0 ▶ $this->{copyright}=(${copyrighttrans()}{shift} || 'unknown') if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
Condition0%0/2
do { {0 => 'GPL', 1 => 'BSD', 2 => 'LGPL', 254 => 'unknown', 3 => 'unknown'} }->{'shift'} || 'unknown'
l!l
00
MC/DC0%0/1
do { {0 => 'GPL', 1 => 'BSD', 2 => 'LGPL', 254 => 'unknown', 3 => 'unknown'} }->{'shift'} || 'unknown'
do { {0 => 'GPL', 1 => 'BSD', 2 => 'LGPL', 254 => 'unknown', 3 => 'unknown'} }->{'shift'}
Truth table0%0/2
A
A= do { {0 => 'GPL', 1 => 'BSD', 2 => 'LGPL', 254 => 'unknown', 3 => 'unknown'} }->{'shift'}
Aresult
11
00
303
304 # get
305 0 ▶ return unless defined wantarray; # optimization
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
306 0 my %transcopyright=reverse %{copyrighttrans()};
307 return $transcopyright{$this->{copyright}}
308 0 ▶ if (exists $transcopyright{$this->{copyright}});
Branch: 1 branch
BranchTrueFalseTotal
if exists $transcopyright{$this->{"copyright"}} 0 0 0
309 0 return 254; # unknown
310 }
311  
312 =item arch
313  
314 Set/get arch.
315  
316 When the arch is set, the number used by slp is changed into a textual
317 description. This is changed back into a number when the value is
318 retrieved.
319  
320 =cut
321  
322 0 ▶sub arch {
Subroutine arch: not called CC=5 SCAR=34.0
Pod documented
323 0 my $this=shift;
324  
325 # set
326 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
327 0 my $arch=shift;
328 0 $this->{arch}=${archtrans()}{$arch};
329 0 ▶ die "unknown architecture $arch" unless defined $this->{arch};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"arch"} 0 0 0
330 }
331  
332 # get
333 0 ▶ return unless defined wantarray; # optimization
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
334 0 my %transarch=reverse %{archtrans()};
335 return $transarch{$this->{arch}}
336 0 ▶ if (exists $transarch{$this->{arch}});
Branch: 1 branch
BranchTrueFalseTotal
if exists $transarch{$this->{"arch"}} 0 0 0
337 0 die "Stampede does not support architecture ".$this->{arch}." packages";
338 }
339  
340 =item release
341  
342 Set/get release version.
343  
344 When the release version is retrieved, it is converted to an unsigned
345 integer, as is required by the slp package format.
346  
347 =cut
348  
349 0 ▶sub release {
Subroutine release: not called CC=3 SCAR=24.8
Pod documented
350 0 my $this=shift;
351  
352 # set
353 0 ▶ $this->{release}=shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
354  
355 # get
356 0 ▶ return unless defined wantarray; # optimization
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 0 0
357 0 return int($this->{release});
358 }
359  
360  
361 =back
362  
363 =head1 AUTHOR
364  
365 Joey Hess <joey@kitenet.net>
366  
367 =cut
368  
369 1 1
« blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package.pm ↑ Summary blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Lsb.pm »