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

filter: Statementstmt 6.4% 10 / 154 Branchbran 0.0% 0 / 72 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 27.2% 3 / 11 Podpod 100% 8 / 8 totaltotal 8.0% 21 / 261 CC 45 SCAR 51.3
CC
45
Cov
4%
scan
380.0
prep
132.0
unpack
56.0
CRAP 168.5
« blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Rpm.pm ↑ Summary blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Deb.pm »
1 #!/usr/bin/perl -w
2  
3 =head1 NAME
4  
5 Alien::Package::Pkg - an object that represents a Solaris pkg package
6  
7 =cut
8  
9 package Alien::Package::Pkg;
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 pkg package, as used in Solaris.
16 It is derived from Alien::Package.
17  
18 =head1 CLASS DATA
19  
20 =over 4
21  
22 =item scripttrans
23  
24 Translation table between canoical script names and the names used in
25 pkg's.
26  
27 =cut
28  
29 1 ▶use constant scripttrans => {
Subroutine BEGIN: called CC=1 SCAR=0.0
30 postinst => 'postinstall',
31 preinst => 'preinstall',
32 1 };
33  
34 =back
35  
36 =head1 METHODS
37  
38 =over 4
39  
40 =item init
41  
42 This class needs the Solaris pkginfo and kgtrans tools to work.
43  
44 =cut
45  
46 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
47 0 foreach (qw(/usr/bin/pkginfo /usr/bin/pkgtrans)) {
48 0 ▶ -x || die "$_ is needed to use ".__PACKAGE__."\n";
Branch: 1 branch
BranchTrueFalseTotal
-x $_ or die "$_ is needed to use " . 'Alien::Package::Pkg' . "\n" 0 0 0
49 }
50 }
51  
52 =item converted_name
53  
54 Convert name from something debian-like to something that the
55 Solaris constraints will handle (i.e. 9 chars max).
56  
57 =cut
58  
59 0 ▶sub converted_name {
Subroutine converted_name: not called CC=2 SCAR=17.9
Pod documented
60 0 my $this = shift;
61 0 my $prefix = "ALN";
62 0 my $name = $this->name;
63  
64 0 for ($name) { # A Short list to start us off.
65 # Still, this is risky since we need
66 # unique names.
67 0 s/^lib/l/;
68 0 s/-perl$/p/;
69 0 s/^perl-/pl/;
70 }
71
72 0 $name = substr($name, 0, 9);
73  
74 0 return $prefix.$name;
75 }
76  
77 =item checkfile
78  
79 Detect pkg files by their contents.
80  
81 =cut
82  
83 0 ▶sub checkfile {
Subroutine checkfile: not called CC=4 SCAR=30.0
Pod documented
84 0 my $this=shift;
85 0 my $file=shift;
86  
87 0 ▶ open(F, $file) || die "Couldn't open $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open F, $file or die "Couldn't open ${file}: $!\n" 0 0 0
88 0 my $line = <F>;
89 0 close F;
90  
91 0 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
92
93 0 ▶ if($line =~ "# PaCkAgE DaTaStReAm") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /# PaCkAgE DaTaStReAm/) 0 0 0
94 0 return 1;
95 }
96 }
97  
98 =item install
99  
100 Install a pkg with pkgadd. Pass in the filename of the pkg to install.
101  
102 =cut
103  
104 0 ▶sub install {
Subroutine install: not called CC=3 SCAR=24.8
Pod documented
105 0 my $this=shift;
106 0 my $pkg=shift;
107  
108 0 ▶ if (-x "/usr/sbin/pkgadd") {
Branch: 1 branch
BranchTrueFalseTotal
if (-x '/usr/sbin/pkgadd') { } 0 0 0
109 0 my $v=$Alien::Package::verbose;
110 0 $Alien::Package::verbose=2;
111 0 ▶ $this->do("/usr/sbin/pkgadd", "-d .", "$pkg")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("/usr/sbin/pkgadd", "-d .", "$pkg") or die "Unable to install" 0 0 0
112 or die "Unable to install";
113 0 $Alien::Package::verbose=$v;
114 }
115 else {
116 0 die "Sorry, I cannot install the generated .pkg file because /usr/sbin/pkgadd is not present.\n";
117 }
118 }
119  
120 =item scan
121  
122 Scan a pkg file for fields.
123  
124 =cut
125  
126 0 ▶sub scan {
Subroutine scan: not called CC=19 SCAR=59.4
Pod documented
127 0 my $this=shift;
128 0 $this->SUPER::scan(@_);
129 0 my $file=$this->filename;
130 0 my $tdir="pkg-scan-tmp.$$";
131  
132 0 ▶ $this->do("mkdir", $tdir) || die "Error making $tdir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$this->do("mkdir", $tdir) or die "Error making ${tdir}: $!\n" 0 0 0
133  
134 0 my $pkgname;
135 0 ▶ if (-x "/usr/bin/pkginfo" && -x "/usr/bin/pkgtrans") {
Branch: 1 branch
BranchTrueFalseTotal
if (-x "/usr/bin/pkginfo" and -x "/usr/bin/pkgtrans") 0 0 0
Condition0%0/3
-x "/usr/bin/pkginfo" and -x "/usr/bin/pkgtrans"
!ll&&!rl&&r
000
MC/DC0%0/2
-x "/usr/bin/pkginfo" and -x "/usr/bin/pkgtrans"
-x "/usr/bin/pkginfo" -x "/usr/bin/pkgtrans"
Truth table0%0/3
A and B
A= -x "/usr/bin/pkginfo"B= -x "/usr/bin/pkgtrans"
ABresult
0X0
100
111
136 0 my $pkginfo;
137  
138 0 ▶ open(INFO, "/usr/bin/pkginfo -d $file|")
Branch: 1 branch
BranchTrueFalseTotal
open INFO, "/usr/bin/pkginfo -d $file|" or die "Couldn't open pkginfo: $!\n" 0 0 0
139 || die "Couldn't open pkginfo: $!\n";
140 0 $_ = <INFO>;
141 0 ($pkgname) = /\S+\s+(\S+)/;
142 0 close INFO;
143  
144 # Extract the files
145 0 ▶ $this->do("/usr/bin/pkgtrans -i $file $tdir $pkgname")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("/usr/bin/pkgtrans -i $file $tdir $pkgname") or die "Error running pkgtrans: $!\n" 0 0 0
146 || die "Error running pkgtrans: $!\n";
147  
148 0 ▶ open(INFO, "$tdir/$pkgname/pkginfo")
Branch: 1 branch
BranchTrueFalseTotal
open INFO, "$tdir/$pkgname/pkginfo" or die "Couldn't open pkgparam: $!\n" 0 0 0
149 || die "Couldn't open pkgparam: $!\n";
150 0 my ($key, $value);
151 0 ▶ while (<INFO>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline INFO)) 0 0 0
152 0 ▶ if (/^([^=]+)=(.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^([^=]+)=(.*)$/) { } 0 0 0
153 0 $key = $1;
154 0 $value = $2;
155 }
156 else {
157 0 $value = $_;
158 }
159 0 push @{$pkginfo->{$key}}, $value
160 }
161 0 close INFO;
162 0 $file =~ m,([^/]+)-[^-]+(?:.pkg)$,;
163 0 $this->name($1);
164 0 $this->arch($pkginfo->{ARCH}->[0]);
165 0 $this->summary("Converted Solaris pkg package");
166 0 ▶ $this->description(join("", @{[$pkginfo->{DESC} || "."]}));
Condition0%0/2
$pkginfo->{'DESC'} || '.'
l!l
00
MC/DC0%0/1
$pkginfo->{'DESC'} || '.'
$pkginfo->{'DESC'}
Truth table0%0/2
A
A= $pkginfo->{'DESC'}
Aresult
11
00
167 0 $this->version($pkginfo->{VERSION}->[0]);
168 0 $this->distribution("Solaris");
169 0 $this->group("unknown"); # *** FIXME
170 0 $this->origformat('pkg');
171 0 $this->changelogtext('');
172 0 $this->binary_info('unknown'); # *** FIXME
173
174 0 ▶ if (-f "$tdir/$pkgname/copyright") {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$tdir/$pkgname/copyright") { } 0 0 0
175 0 ▶ open (COPYRIGHT, "$file/install/copyright")
Branch: 1 branch
BranchTrueFalseTotal
open COPYRIGHT, "$file/install/copyright" or die "Couldn't open copyright: $!\n" 0 0 0
176 || die "Couldn't open copyright: $!\n";
177 0 $this->copyright(join("\n",<COPYRIGHT>));
178 0 close(COPYRIGHT);
179 }
180 else {
181 0 $this->copyright("unknown");
182 }
183 }
184  
185 # Now figure out the conffiles. Assume anything in etc/ is a
186 # conffile.
187 0 my @conffiles;
188 my @filelist;
189 0 my @scripts;
190 0 ▶ open (FILELIST,"$tdir/$pkgname/pkgmap") ||
Branch: 1 branch
BranchTrueFalseTotal
open FILELIST, "$tdir/$pkgname/pkgmap" or die "getting filelist ($file/pkgmap): $!" 0 0 0
191 die "getting filelist ($file/pkgmap): $!";
192 0 ▶ while (<FILELIST>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline FILELIST)) 0 0 0
193 0 ▶ if (m,^1 f \S+ etc/([^\s=]+),) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^1 f \S+ etc/([^\s=]+)]) 0 0 0
194 0 push @conffiles, "/etc/$1";
195 }
196 0 ▶ if (m,^1 [fd] \S+ ([^\s=]+),) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^1 [fd] \S+ ([^\s=]+)/) 0 0 0
197 0 push @filelist, $1;
198 }
199 0 ▶ if (m,^1 i (\S+),) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^1 i (\S+)/) 0 0 0
200 0 push @scripts, $1;
201 }
202 }
203  
204 0 $this->filelist(\@filelist);
205 0 $this->conffiles(\@conffiles);
206  
207 # Now get the scripts.
208 0 foreach my $script (keys %{scripttrans()}) {
209 $this->$script(scripttrans()->{$script})
210 0 ▶ if -e "$file/".scripttrans()->{$script};
Branch: 1 branch
BranchTrueFalseTotal
if -e "$file/" . {"postinst" => "postinstall","preinst" => "preinstall"}->{$script} 0 0 0
211 }
212  
213 0 $this->do("rm -rf $tdir");
214  
215 0 return 1;
216 }
217  
218 =item unpack
219  
220 Unpack pkg.
221  
222 =cut
223  
224 0 ▶sub unpack {
Subroutine unpack: not called CC=7 SCAR=40.3
Pod documented
225 0 my $this=shift;
226 0 $this->SUPER::unpack(@_);
227 0 my $file=$this->filename;
228  
229 0 my $pkgname;
230 0 ▶ open(INFO, "/usr/bin/pkginfo -d $file|")
Branch: 1 branch
BranchTrueFalseTotal
open INFO, "/usr/bin/pkginfo -d $file|" or die "Couldn't open pkginfo: $!\n" 0 0 0
231 || die "Couldn't open pkginfo: $!\n";
232 0 $_ = <INFO>;
233 0 ($pkgname) = /\S+\s+(\S+)/;
234 0 close INFO;
235  
236 0 ▶ if (-x "/usr/bin/pkgtrans") {
Branch: 1 branch
BranchTrueFalseTotal
if (-x "/usr/bin/pkgtrans") 0 0 0
237 0 my $workdir = $this->name."-".$this->version;;
238 0 ▶ $this->do("mkdir", $workdir) || die "unable to mkdir $workdir: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
$this->do("mkdir", $workdir) or die "unable to mkdir ${workdir}: $!\n" 0 0 0
239 0 ▶ $this->do("/usr/bin/pkgtrans $file $workdir $pkgname")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("/usr/bin/pkgtrans $file $workdir $pkgname") or die "unable to extract ${file}: $!\n" 0 0 0
240 || die "unable to extract $file: $!\n";
241 0 ▶ rename("$workdir/$pkgname", "$ {workdir}_1")
Branch: 1 branch
BranchTrueFalseTotal
rename "$workdir/$pkgname", "${workdir}_1" or die "unable rename $workdir/${pkgname}: $!\n" 0 0 0
242 || die "unable rename $workdir/$pkgname: $!\n";
243 0 rmdir $workdir;
244 0 ▶ rename("$ {workdir}_1", $workdir)
Branch: 1 branch
BranchTrueFalseTotal
rename "${workdir}_1", $workdir or die "unable to rename ${workdir}_1: $!\n" 0 0 0
245 || die "unable to rename $ {workdir}_1: $!\n";
246 0 $this->unpacked_tree($workdir);
247 }
248 }
249  
250 =item prep
251  
252 Adds a populated install directory to the build tree.
253  
254 =cut
255  
256 0 ▶sub prep {
Subroutine prep: not called CC=11 SCAR=48.8
Pod documented
257 0 my $this=shift;
258 0 ▶ my $dir=$this->unpacked_tree || die "The package must be unpacked first!";
Condition0%0/2
$this->unpacked_tree || die('The package must be unpacked first!')
l!l
00
MC/DC0%0/1
$this->unpacked_tree || die('The package must be unpacked first!')
$this->unpacked_tree
Truth table0%0/2
A
A= $this->unpacked_tree
Aresult
11
00
259  
260 # opendir(DIR, $this->unpacked_tree);
261 # my @sub = map {$this->unpacked_tree . "$_"}
262 # grep {/^\./} readdir DIR;
263 # closedir DIR;
264  
265 0 ▶ $this->do("cd $dir; find . -print | sed -e '/.\\/prototype\$/d' | pkgproto > ./prototype")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("cd $dir; find . -print | sed -e '/.\\/prototype\$/d' | pkgproto > ./prototype") or die "error during pkgproto: $!\n" 0 0 0
266 || die "error during pkgproto: $!\n";
267  
268 0 ▶ open(PKGPROTO, ">>$dir/prototype")
Branch: 1 branch
BranchTrueFalseTotal
open PKGPROTO, ">>$dir/prototype" or die "error appending to prototype: $!\n" 0 0 0
269 || die "error appending to prototype: $!\n";
270  
271 0 ▶ open(PKGINFO, ">$dir/pkginfo")
Branch: 1 branch
BranchTrueFalseTotal
open PKGINFO, ">$dir/pkginfo" or die "error creating pkginfo: $!\n" 0 0 0
272 || die "error creating pkginfo: $!\n";
273 0 print PKGINFO qq{PKG="}.$this->converted_name.qq{"\n};
274 0 print PKGINFO qq{NAME="}.$this->name.qq{"\n};
275 0 print PKGINFO qq{ARCH="}.$this->arch.qq{"\n};
276 0 print PKGINFO qq{VERSION="}.$this->version.qq{"\n};
277 0 print PKGINFO qq{CATEGORY="application"\n};
278 0 print PKGINFO qq{VENDOR="Alien-converted package"\n};
279 0 print PKGINFO qq{EMAIL=\n};
280 0 print PKGINFO qq{PSTAMP=alien\n};
281 0 print PKGINFO qq{MAXINST=1000\n};
282 0 print PKGINFO qq{BASEDIR="/"\n};
283 0 print PKGINFO qq{CLASSES="none"\n};
284 0 print PKGINFO qq{DESC="}.$this->description.qq{"\n};
285 0 close PKGINFO;
286 0 print PKGPROTO "i pkginfo=./pkginfo\n";
287  
288 0 ▶ $this->do("mkdir", "$dir/install") || die "unable to mkdir $dir/install: $!";
Branch: 1 branch
BranchTrueFalseTotal
$this->do("mkdir", "$dir/install") or die "unable to mkdir $dir/install: $!" 0 0 0
289 0 ▶ open(COPYRIGHT, ">$dir/install/copyright")
Branch: 1 branch
BranchTrueFalseTotal
open COPYRIGHT, ">$dir/install/copyright" or die "error creating copyright: $!\n" 0 0 0
290 || die "error creating copyright: $!\n";
291 0 print COPYRIGHT $this->copyright;
292 0 close COPYRIGHT;
293 0 print PKGPROTO "i copyright=./install/copyright\n";
294  
295 0 foreach my $script (keys %{scripttrans()}) {
296 0 my $data=$this->$script();
297 0 my $out=$this->unpacked_tree."/install/".${scripttrans()}{$script};
298 0 ▶ next if ! defined $data || $data =~ m/^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $data or $data =~ /^\s*$/ 0 0 0
Condition0%0/3
not defined $data or $data =~ /^\s*$/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $data or $data =~ /^\s*$/
not defined $data $data =~ /^\s*$/
Truth table0%0/3
not(A) or B
A= not defined $dataB= $data =~ /^\s*$/
ABresult
1X1
011
000
299  
300 0 ▶ open (OUT, ">$out") || die "$out: $!";
Branch: 1 branch
BranchTrueFalseTotal
open OUT, ">$out" or die "${out}: $!" 0 0 0
301 0 print OUT $data;
302 0 close OUT;
303 0 $this->do("chmod", 755, $out);
304 0 print PKGPROTO "i $script=$out\n";
305 }
306 0 close PKGPROTO;
307 }
308  
309 =item build
310  
311 Build a pkg.
312  
313 =cut
314  
315 0 ▶sub build {
Subroutine build: not called CC=3 SCAR=24.8
Pod documented
316 0 my $this = shift;
317 0 my $dir = $this->unpacked_tree;
318  
319 0 ▶ $this->do("cd $dir; pkgmk -r / -d .")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("cd $dir; pkgmk -r / -d .") or die "Error during pkgmk: $!\n" 0 0 0
320 || die "Error during pkgmk: $!\n";
321  
322 0 my $pkgname = $this->converted_name;
323 0 my $name = $this->name."-".$this->version.".pkg";
324 0 ▶ $this->do("pkgtrans $dir $name $pkgname")
Branch: 1 branch
BranchTrueFalseTotal
$this->do("pkgtrans $dir $name $pkgname") or die "Error during pkgtrans: $!\n" 0 0 0
325 || die "Error during pkgtrans: $!\n";
326 0 $this->do("mv", "$dir/$name", $name);
327 0 return $name;
328 }
329  
330 =back
331  
332 =head1 AUTHOR
333  
334 Mark Hershberger <mah@everybody.org>
335  
336 =cut
337  
338 1 1
« blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Rpm.pm ↑ Summary blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Deb.pm »