« blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Tgz.pm
↑ Summary
blib/lib/auto/share/dist/Alien-Alien/lib/perl5/Alien/Package/Slp.pm »
| 1 | #!/usr/bin/perl -w | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | Alien::Package - an object that represents a package | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =cut | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | package Alien::Package; | ||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | our $verbose=0; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | This is a perl object class that represents a package in an internal format | ||||||||||||||||||||||||||||
| 17 | usable by alien. The package may be a deb, a rpm, a tgz, or a slp package, | ||||||||||||||||||||||||||||
| 18 | etc. Objects in this class hold various fields of metadata from the actual | ||||||||||||||||||||||||||||
| 19 | packages they represent, as well as some fields pointing to the actual | ||||||||||||||||||||||||||||
| 20 | contents of the package. They can also examine an actual package on disk, | ||||||||||||||||||||||||||||
| 21 | and populate those fields. And they can build the actual package using the | ||||||||||||||||||||||||||||
| 22 | data stored in the fields. | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | A typical use of this object class will be to instantiate an object from | ||||||||||||||||||||||||||||
| 25 | a class derived from this one, such as Alien::Package::Rpm. Feed the object | ||||||||||||||||||||||||||||
| 26 | a rpm file, thus populating all of its fields. Then rebless the object into | ||||||||||||||||||||||||||||
| 27 | the destination class, such as Alien::Package::Deb. Finally, ask the object | ||||||||||||||||||||||||||||
| 28 | to build a package, and the package has been converted. | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 FIELDS | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | These fields are of course really just methods that all act similarly; | ||||||||||||||||||||||||||||
| 33 | allowing a value to be passed in to set them, or simply returning the value | ||||||||||||||||||||||||||||
| 34 | of the field if nothing is passed in. Child classes may override these | ||||||||||||||||||||||||||||
| 35 | fields to process input data, or to format output data. The general rule is | ||||||||||||||||||||||||||||
| 36 | that input data is modified to get things into a package-independant form, | ||||||||||||||||||||||||||||
| 37 | which is how the data is stored in the fields. When the value of a field is | ||||||||||||||||||||||||||||
| 38 | read, it too may be modified before it is returned, to change things into a | ||||||||||||||||||||||||||||
| 39 | form more suitable for the particular type of package. | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =over 4 | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =item name | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | The package's name. | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | =item version | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | The package's upstream version. | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | =item release | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | The package's distribution specific release number. | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =item arch | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | The package's architecture, in the format used by Debian. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =item maintainer | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | The package's maintainer. | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =item depends | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | The package's dependencies. Only dependencies that should exist on all | ||||||||||||||||||||||||||||
| 66 | target distributions can be put in here though (ie: lsb). | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item group | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | The section the package is in. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =item summary | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | A one line description of the package. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =item description | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | A longer description of the package. May contain multiple paragraphs. | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =item copyright | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | A short statement of copyright. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =item origformat | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | What format the package was originally in. | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item distribution | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | What distribution family the package originated from. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =item binary_info | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | Whatever the package's package tool says when told to display info about | ||||||||||||||||||||||||||||
| 95 | the package. | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item conffiles | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | A reference to a list of all the conffiles in the package. | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =item files | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | A reference to a list of all the files in the package. | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =item changelogtext | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | The text of the changelog | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =item postinst | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | The postinst script of the package. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item postrm | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | The postrm script of the package. | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | =item preinst | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | The preinst script of the package. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | =item prerm | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | The prerm script of the package. | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =item usescripts | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | Only use the above scripts fields when generating the package if this is set | ||||||||||||||||||||||||||||
| 128 | to a true value. | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | =item unpacked_tree | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | Points to a directory where the package has been unpacked. | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | =item owninfo | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | If set this will be a reference to a hash, with filename as key, that holds | ||||||||||||||||||||||||||||
| 137 | ownership/group information for files that cannot be represented on the | ||||||||||||||||||||||||||||
| 138 | filesystem. Typically that is because the owners or groups just don't exist | ||||||||||||||||||||||||||||
| 139 | yet. It will be set at unpack time. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | =item modeinfo | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | If set this will be a reference to a hash, with filename as key, that | ||||||||||||||||||||||||||||
| 144 | holds mode information for setuid files that have an entry in owninfo. | ||||||||||||||||||||||||||||
| 145 | It will be set at unpack time. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =back | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | =head1 METHODS | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =over 4 | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =item init | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | This is called by new(). It's a handy place to set fields, etc, without | ||||||||||||||||||||||||||||
| 156 | having to write your own new() method. | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub init {} | ||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =item install | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Simply installs a package file. The filename is passed. | ||||||||||||||||||||||||||||
| 165 | This has to be overridden in child classes. | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub install { | ||||||||||||||||||||||||||
|
Subroutine
install: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 170 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | =item test | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | Test a package file. The filename is passed, should return an array of lines | ||||||||||||||||||||||||||||
| 176 | of test results. Child classses may implement this. | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub test { | ||||||||||||||||||||||||||
|
Subroutine
test: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 181 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | =item filename | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | Set/get the filename of the package the object represents. | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | When it is set, it performs a scan of the file, populating most other | ||||||||||||||||||||||||||||
| 190 | fields with data from it. | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | (This is just a stub; child classes should override it to actually do | ||||||||||||||||||||||||||||
| 193 | something.) | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =cut | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | ▶ | sub filename { | ||||||||||||||||||||||||||
|
Subroutine
filename: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 198 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # set | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 0 | $this->{filename} = shift; | |||||||||||||||||||||||||||
| 203 | 0 | $this->scan; | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | return $this->{filename}; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =item scripts | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | Returns a list of all non-empty maintainer scripts in the package. | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | =cut | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub scripts { | ||||||||||||||||||||||||||
|
Subroutine
scripts: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 216 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | my @ret; | |||||||||||||||||||||||||||
| 219 | 0 | foreach my $s (qw{postinst postrm preinst prerm}) { | |||||||||||||||||||||||||||
| 220 | 0 | my $val=$this->$s; | |||||||||||||||||||||||||||
| 221 | 0 | ▶ | push(@ret, $s) if defined $val && length $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $val and length $val
MC/DC0%0/2
defined $val and length $val
defined $val
length $val
Truth table0%0/3
A and B
A= defined $valB= length $val
| |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 0 | return @ret; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | =item scan | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | This method scans the file associated with an object, and populates as many | ||||||||||||||||||||||||||||
| 229 | other fields as it can with data from it. | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =cut | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | ▶ | sub scan { | ||||||||||||||||||||||||||
|
Subroutine
scan: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 234 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 235 | 0 | my $file=$this->filename; | |||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (! -e $file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | die "$file does not exist; cannot read."; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =item unpack | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | This method unpacks the package into a temporary directory. It sets | ||||||||||||||||||||||||||||
| 245 | unpacked_tree to point to that directory. | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | (This is just a stub method that makes a directory below the current | ||||||||||||||||||||||||||||
| 248 | working directory, and sets unpacked_tree to point to it. It should be | ||||||||||||||||||||||||||||
| 249 | overridden by child classes to actually unpack the package as well.) | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =cut | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | sub unpack { | ||||||||||||||||||||||||||
|
Subroutine
unpack: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 254 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | my $workdir = $this->name."-".$this->version; | |||||||||||||||||||||||||||
| 257 | 0 | ▶ | $this->do("mkdir $workdir") or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | die "unable to mkdir $workdir: $!"; | ||||||||||||||||||||||||||||
| 259 | # If the parent directory is suid/sgid, mkdir will make the root | ||||||||||||||||||||||||||||
| 260 | # directory of the package inherit those bits. That is a bad thing, | ||||||||||||||||||||||||||||
| 261 | # so explicitly force perms to 755. | ||||||||||||||||||||||||||||
| 262 | 0 | $this->do("chmod 755 $workdir"); | |||||||||||||||||||||||||||
| 263 | 0 | $this->unpacked_tree($workdir); | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | =item prep | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | This method causes the object to prepare a build tree to be used in | ||||||||||||||||||||||||||||
| 269 | building the object. It expects that the unpack method has already been | ||||||||||||||||||||||||||||
| 270 | called. It takes the tree generated by that method, and mangles it somehow, | ||||||||||||||||||||||||||||
| 271 | to produce a suitable build tree. | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | (This is just a stub method that all child classes should override.) | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | =cut | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | sub prep {} | ||||||||||||||||||||||||||
|
Subroutine
prep: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | =item cleantree | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | This method should clean the unpacked_tree of any effects the prep and | ||||||||||||||||||||||||||||
| 282 | build methods might have on it. | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | =cut | ||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 0 | ▶ | sub cleantree {} | ||||||||||||||||||||||||||
|
Subroutine
cleantree: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =item revert | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | This method should ensure that the object is in the same state it was in | ||||||||||||||||||||||||||||
| 291 | before the prep method was called. | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | =cut | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub revert {} | ||||||||||||||||||||||||||
|
Subroutine
revert: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | =item build | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | This method takes a prepped build tree, and simply builds a package from | ||||||||||||||||||||||||||||
| 300 | it. It should put the package in the current directory, and should return | ||||||||||||||||||||||||||||
| 301 | the filename of the generated package. | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | (This is just a stub method that all child classes should override.) | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | =cut | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | ▶ | sub build {} | ||||||||||||||||||||||||||
|
Subroutine
build: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | =item incrementrelease | ||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||
| 311 | This method should increment the release field of the package by | ||||||||||||||||||||||||||||
| 312 | the specified number. | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =cut | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | ▶ | sub incrementrelease { | ||||||||||||||||||||||||||
|
Subroutine
incrementrelease: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 317 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 318 | 0 | my $number=shift; | |||||||||||||||||||||||||||
| 319 | 0 | $^W=0; # Shut of possible "is not numeric" warning. | |||||||||||||||||||||||||||
| 320 | 0 | $this->release($this->release + $number); | |||||||||||||||||||||||||||
| 321 | 0 | $^W=1; # Re-enable warnings. | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | =item DESTROY | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | When an object is destroyed, it cleans some stuff up. In particular, if the | ||||||||||||||||||||||||||||
| 327 | package was unpacked, it is time now to wipe out the temporary directory. | ||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | =cut | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 332 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | my $exitcode=$?; | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | ▶ | return if (! defined $this->unpacked_tree || $this->unpacked_tree eq ''); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $this->unpacked_tree or $this->unpacked_tree eq ""
MC/DC0%0/2
not defined $this->unpacked_tree or $this->unpacked_tree eq ""
not defined $this->unpacked_tree
$this->unpacked_tree eq ""
Truth table0%0/3
not(A) or B
A= not defined $this->unpacked_treeB= $this->unpacked_tree eq ""
| |||||||||||||||||||||||||||||
| 337 | # This should never happen, but it pays to check. | ||||||||||||||||||||||||||||
| 338 | 0 | ▶ | if ($this->unpacked_tree eq '/') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | die "alien internal error: unpacked_tree is set to '/'. Please file a bug report!"; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if (-d $this->unpacked_tree) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 343 | # Just in case some dir perms are too screwed up for | ||||||||||||||||||||||||||||
| 344 | # rm to work and we're not running as root. NB: can't | ||||||||||||||||||||||||||||
| 345 | # use xargs | ||||||||||||||||||||||||||||
| 346 | 0 | $this->do('find', $this->unpacked_tree, '-type', 'd', | |||||||||||||||||||||||||||
| 347 | '-exec', 'chmod', '755', '{}', ';'); | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | $this->do('rm', '-rf', $this->unpacked_tree) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | or die "unable to delete temporary directory '".$this->unpacked_tree."': $!"; | ||||||||||||||||||||||||||||
| 351 | 0 | $this->unpacked_tree(''); | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | $?=$exitcode; | |||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =item AUTOLOAD | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | Handles all fields, by creating accessor methods for them the first time | ||||||||||||||||||||||||||||
| 360 | they are accessed. | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | =cut | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||
| 365 | 0 | my $field; | |||||||||||||||||||||||||||
| 366 | 0 | ($field = $AUTOLOAD) =~ s/.*://; | |||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 369 | 0 | ▶ | *$AUTOLOAD = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 370 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | ▶ | return $this->{$field} unless @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | 0 | return $this->{$field}=shift; | |||||||||||||||||||||||||||
| 374 | 0 | }; | |||||||||||||||||||||||||||
| 375 | 0 | goto &$AUTOLOAD; | |||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | =back | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | =head1 CLASS DATA | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =over 4 | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | =item $Alien::Package::verbose | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | If set to a nonzero value, the shell commands that are run should be output. | ||||||||||||||||||||||||||||
| 387 | If set to a value greater than 1, any output of the commands should also be | ||||||||||||||||||||||||||||
| 388 | output. | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | =back | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | These methods can be called on either an object or on the class itself. | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | =cut | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =over 4 | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =item new | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | Returns a new object of this class. Optionally, you can pass in named | ||||||||||||||||||||||||||||
| 403 | parameters that specify the values of any fields in the class. | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | =cut | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 408 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 409 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 410 | 0 | my $this=bless ({}, $class); | |||||||||||||||||||||||||||
| 411 | 0 | $this->init; | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | $this->$_(shift) while $_=shift; # run named parameters as methods | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | return $this; | |||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | =item checkfile | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | Pass it a filename, and it will return true if it looks like the file is | ||||||||||||||||||||||||||||
| 419 | a package of the type handled by the class. | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =cut | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 0 | ▶ | sub checkfile { | ||||||||||||||||||||||||||
|
Subroutine
checkfile: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 424 | 0 | my $this=shift; | |||||||||||||||||||||||||||
| 425 | 0 | my $file=shift; | |||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 0 | return ''; # children override this. | |||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | =item do | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | Runs a shell command. Is verbose or not depending on the value of | ||||||||||||||||||||||||||||
| 433 | $Alien::Package::verbose. Returns true if the command succeeds, | ||||||||||||||||||||||||||||
| 434 | false on failure. | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =cut | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 0 | ▶ | sub do { | ||||||||||||||||||||||||||
|
Subroutine
do: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 439 | 0 | my $whatever=shift; | |||||||||||||||||||||||||||
| 440 | 0 | my @command=@_; | |||||||||||||||||||||||||||
| 441 | 0 | ▶ | if ($Alien::Package::verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 442 | 0 | print "\t@command\n"; | |||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||
| 444 | 0 | my $pid=fork; | |||||||||||||||||||||||||||
| 445 | 0 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 446 | # child | ||||||||||||||||||||||||||||
| 447 | 0 | ▶ | if ($Alien::Package::verbose < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 448 | # just closing it won't do | ||||||||||||||||||||||||||||
| 449 | 0 | open(STDOUT, ">/dev/null"); | |||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | 0 | exec(@command); | |||||||||||||||||||||||||||
| 452 | 0 | exit 1; | |||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||
| 454 | else { | ||||||||||||||||||||||||||||
| 455 | # parent | ||||||||||||||||||||||||||||
| 456 | 0 | my $ret=(waitpid($pid, 0) > 0); | |||||||||||||||||||||||||||
| 457 | 0 | ▶ | return ! $ret || ! $?; | ||||||||||||||||||||||||||
|
Condition0%0/3
$ret && $?
MC/DC0%0/2
$ret && $?
$ret
$?
Truth table0%0/3
A && B
A= $retB= $?
| |||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||
| 461 | =item runpipe | ||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | This is similar to backticks, but honors $Alien::Package::verbose, logging | ||||||||||||||||||||||||||||
| 464 | the command run if asked to. The output of the command is returned. | ||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | The first parameter controls what to do on error. If it's true then any | ||||||||||||||||||||||||||||
| 467 | errors from the command will be ignored (and $? will be set). If it's | ||||||||||||||||||||||||||||
| 468 | false, errors will abort alien. | ||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | =cut | ||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 0 | ▶ | sub runpipe { | ||||||||||||||||||||||||||
|
Subroutine
runpipe: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 473 | 0 | my $whatever=shift; | |||||||||||||||||||||||||||
| 474 | 0 | my $ignoreerror=shift; | |||||||||||||||||||||||||||
| 475 | 0 | my @command=@_; | |||||||||||||||||||||||||||
| 476 | 0 | ▶ | if ($Alien::Package::verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 477 | 0 | print "\t@command\n"; | |||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||
| 479 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 480 | 0 | my @ret=`@command`; | |||||||||||||||||||||||||||
| 481 | 0 | ▶ | die "Error executing \"@command\": $!" if ! $ignoreerror && $? ne 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ignoreerror and $? ne 0
MC/DC0%0/2
not $ignoreerror and $? ne 0
not $ignoreerror
$? ne 0
Truth table0%0/3
not(A) and B
A= not $ignoreerrorB= $? ne 0
| |||||||||||||||||||||||||||||
| 482 | 0 | ▶ | if ($Alien::Package::verbose >= 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 483 | 0 | print @ret; | |||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||
| 485 | 0 | return @ret; | |||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||
| 487 | else { | ||||||||||||||||||||||||||||
| 488 | 0 | my $ret=`@command`; | |||||||||||||||||||||||||||
| 489 | 0 | ▶ | die "Error executing \"@command\": $!" if ! $ignoreerror && $? ne 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $ignoreerror and $? ne 0
MC/DC0%0/2
not $ignoreerror and $? ne 0
not $ignoreerror
$? ne 0
Truth table0%0/3
not(A) and B
A= not $ignoreerrorB= $? ne 0
| |||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if ($Alien::Package::verbose >= 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 491 | 0 | print $ret."\n"; | |||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||
| 493 | 0 | return $ret; | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||
| 497 | =back | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||
| 501 | Joey Hess <joey@kitenet.net> | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | =cut | ||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||
| 505 | 1 | 1 | |||||||||||||||||||||||||||