blib/lib/Alien/Build/Plugin/Extract/CommandLine.pm

filter: Statementstmt 76.1% 112 / 147 Branchbran 56.9% 66 / 116 Conditioncond 41.2% 26 / 63 MC/DCmcdc 12.2% 5 / 41 Subroutinesub 85.7% 24 / 28 Podpod 100% 8 / 8 totaltotal 59.8% 241 / 403 CC 81 SCAR 30.2
CC
81
Cov
63%
handles
41.1
_dcon
29.7
init
27.1
CRAP 20.5
« blib/lib/Alien/Build/Plugin/Digest/SHAPP.pm ↑ Summary blib/lib/Test/Alien/Diag.pm »
1 package Alien::Build::Plugin::Extract::CommandLine;
2  
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use 5.008004;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 8 ▶use File::Which ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use File::Temp qw( tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use Capture::Tiny qw( capture_merged );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 # ABSTRACT: Plugin to extract an archive using command line tools
14 8 our $VERSION = '2.88'; # VERSION
15  
16  
17 8 has '+format' => 'tar';
18  
19  
20 sub gzip_cmd
21 3 ▶{
Subroutine gzip_cmd: called CC=2 SCAR=7.6
Pod documented
22 3 ▶ _which('gzip') ? 'gzip' : undef;
Branch: 1 branch
BranchTrueFalseTotal
_which('gzip') ? : 3 0 3
23 }
24  
25  
26 50 ▶sub _which { scalar File::Which::which(@_) }
Subroutine _which: called CC=1 SCAR=0.0
27  
28 sub bzip2_cmd
29 2 ▶{
Subroutine bzip2_cmd: called CC=2 SCAR=7.6
Pod documented
30 2 ▶ _which('bzip2') ? 'bzip2' : undef;
Branch: 1 branch
BranchTrueFalseTotal
_which('bzip2') ? : 2 0 2
31 }
32  
33  
34 sub xz_cmd
35 2 ▶{
Subroutine xz_cmd: called CC=2 SCAR=7.6
Pod documented
36 2 ▶ _which('xz') ? 'xz' : undef;
Branch: 1 branch
BranchTrueFalseTotal
_which('xz') ? : 2 0 2
37 }
38  
39  
40 {
41 8 my $bsd_tar;
42  
43 # Note: GNU tar can be iffy to very bad on windows, where absolute
44 # paths get confused with remote tars. We used to assume that 'tar.exe'
45 # is borked on Windows, but recent versions of Windows 10 come bundled
46 # with bsdtar (libarchive) named 'tar.exe', and we should definitely
47 # prefer that to ptar.
48 sub _windows_tar_is_bsdtar
49 20 ▶ {
Subroutine _windows_tar_is_bsdtar: called CC=4 SCAR=25.5
50 20 ▶ return 1 if $^O ne 'MSWin32';
Branch: 1 branch
BranchTrueFalseTotal
if $^O ne "MSWin32" 20 0 20
51 0 ▶ return $bsd_tar if defined $bsd_tar;
Branch: 1 branch
BranchTrueFalseTotal
if defined $bsd_tar 0 0 0
52 0 ▶ my($out) = capture_merged {
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 system 'tar', '--version';
54 0 };
55 0 ▶ return $bsd_tar = $out =~ /bsdtar/ ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$out =~ /bsdtar/ ? : 0 0 0
56 }
57 }
58  
59 sub tar_cmd
60 8 ▶{
Subroutine tar_cmd: called CC=7 SCAR=27.5
Pod documented
61 20 ▶ _which('bsdtar')
Branch: 4 branches
BranchTrueFalseTotal
_which('bsdtar') ? : 0 20 20
$^O eq 'solaris' && _which('gtar') ? : 0 20 20
_which('tar') && _windows_tar_is_bsdtar() ? : 20 0 20
_which('ptar') ? : 0 0 0
Condition33%2/6
$^O eq "solaris" and _which("gtar")
!ll&&!rl&&r
2000
_which("tar") and _windows_tar_is_bsdtar()
!ll&&!rl&&r
0020
MC/DC0%0/2
$^O eq "solaris" and _which("gtar")
$^O eq "solaris" _which("gtar")
MC/DC0%0/2
_which("tar") and _windows_tar_is_bsdtar()
_which("tar") _windows_tar_is_bsdtar()
Truth table33%1/3
A and B
A= $^O eq "solaris"B= _which("gtar")
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= _which("tar")B= _windows_tar_is_bsdtar()
ABresult
0X0
100
111
62 ? 'bsdtar'
63 # Slowlaris /usr/bin/tar doesn't seem to like pax global header
64 # but seems to have gtar in the path by default, which is okay with it
65 : $^O eq 'solaris' && _which('gtar')
66 ? 'gtar'
67 # See note above for Windows logic.
68 : _which('tar') && _windows_tar_is_bsdtar()
69 ? 'tar'
70 : _which('ptar')
71 ? 'ptar'
72 : undef;
73 };
74  
75  
76 sub unzip_cmd
77 3 ▶{
Subroutine unzip_cmd: called CC=5 SCAR=21.9
Pod documented
78 3 ▶ if($^O eq 'MSWin32' && _which('tar') && _windows_tar_is_bsdtar())
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32' and _which('tar') and _windows_tar_is_bsdtar()) { } 0 3 3
Condition33%2/6
$^O eq "MSWin32" and _which("tar") and _windows_tar_is_bsdtar()
!ll&&!rl&&r
300
$^O eq "MSWin32" and _which("tar")
!ll&&!rl&&r
300
MC/DC0%0/3
$^O eq "MSWin32" and _which("tar") and _windows_tar_is_bsdtar()
$^O eq "MSWin32" _which("tar") _windows_tar_is_bsdtar()
Truth table25%1/4
A and B and C
A= $^O eq "MSWin32"B= _which("tar")C= _windows_tar_is_bsdtar()
ABCresult
0XX0
10X0
1100
1111
79 {
80 0 (_which('tar'), 'xf');
81 }
82 else
83 {
84 3 ▶ _which('unzip') ? 'unzip' : undef;
Branch: 1 branch
BranchTrueFalseTotal
_which('unzip') ? : 3 0 3
85 }
86 }
87  
88 sub _run
89 7 ▶{
Subroutine _run: called CC=2 SCAR=7.0
90 7 my(undef, $build, @cmd) = @_;
91 7 $build->log("+ @cmd");
92 7 system @cmd;
93 7 ▶ die "execute failed" if $?;
Branch: 1 branch
BranchTrueFalseTotal
if $? 0 7 7
94 }
95  
96 sub _cp
97 0 ▶{
Subroutine _cp: not called CC=2 SCAR=17.9
98 0 my(undef, $build, $from, $to) = @_;
99 0 require File::Copy;
100 0 $build->log("copy $from => $to");
101 0 ▶ File::Copy::cp($from, $to) || die "unable to copy: $!";
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::cp($from, $to) or die "unable to copy: $!" 0 0 0
102 }
103  
104 sub _mv
105 0 ▶{
Subroutine _mv: not called CC=2 SCAR=17.9
106 0 my(undef, $build, $from, $to) = @_;
107 0 $build->log("move $from => $to");
108 0 ▶ rename($from, $to) || die "unable to rename: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $from, $to or die "unable to rename: $!" 0 0 0
109 }
110  
111 sub _dcon
112 7 ▶{
Subroutine _dcon: called CC=17 SCAR=33.9
113 7 my($self, $src) = @_;
114  
115 7 my $name;
116 my $cmd;
117  
118 7 ▶ if($src =~ /\.(gz|tgz|Z|taz)$/)
Branch: 3 branches
BranchTrueFalseTotal
if ($src =~ /\.(gz|tgz|Z|taz)$/) { } 2 5 7
elsif ($src =~ /\.(bz2|tbz)$/) { } 1 4 5
elsif ($src =~ /\.(xz|txz)$/) { } 1 3 4
119 {
120 2 ▶ $self->gzip_cmd(_which('gzip')) unless defined $self->gzip_cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->gzip_cmd 0 2 2
121 2 ▶ if($src =~ /\.(gz|tgz)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($src =~ /\.(gz|tgz)$/) { } 1 1 2
elsif ($src =~ /\.(Z|taz)$/) { } 1 0 1
122 {
123 1 ▶ $cmd = $self->gzip_cmd unless $self->_tar_can('tar.gz');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_tar_can("tar.gz") 0 1 1
124 }
125 elsif($src =~ /\.(Z|taz)$/)
126 {
127 1 ▶ $cmd = $self->gzip_cmd unless $self->_tar_can('tar.Z');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_tar_can("tar.Z") 0 1 1
128 }
129 }
130 elsif($src =~ /\.(bz2|tbz)$/)
131 {
132 1 ▶ $self->bzip2_cmd(_which('bzip2')) unless defined $self->bzip2_cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->bzip2_cmd 0 1 1
133 1 ▶ $cmd = $self->bzip2_cmd unless $self->_tar_can('tar.bz2');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_tar_can("tar.bz2") 0 1 1
134 }
135 elsif($src =~ /\.(xz|txz)$/)
136 {
137 1 ▶ $self->xz_cmd(_which('xz')) unless defined $self->xz_cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->xz_cmd 0 1 1
138 1 ▶ $cmd = $self->xz_cmd unless $self->_tar_can('tar.xz');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_tar_can("tar.xz") 0 1 1
139 }
140  
141 7 ▶ if($cmd && $src =~ /\.(gz|bz2|xz|Z)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($cmd and $src =~ /\.(gz|bz2|xz|Z)$/) { } 0 7 7
elsif ($cmd and $src =~ /\.(tgz|tbz|txz|taz)$/) { } 0 14 14
Condition33%1/3
$cmd and $src =~ /\.(gz|bz2|xz|Z)$/
!ll&&!rl&&r
700
MC/DC0%0/2
$cmd and $src =~ /\.(gz|bz2|xz|Z)$/
$cmd $src =~ /\.(gz|bz2|xz|Z)$/
Truth table33%1/3
A and B
A= $cmdB= $src =~ /\.(gz|bz2|xz|Z)$/
ABresult
0X0
100
111
142 {
143 0 $name = $src;
144 0 $name =~ s/\.(gz|bz2|xz|Z)$//g;
145 }
146 ▶ elsif($cmd && $src =~ /\.(tgz|tbz|txz|taz)$/)
Condition33%1/3
$cmd and $src =~ /\.(tgz|tbz|txz|taz)$/
!ll&&!rl&&r
700
MC/DC0%0/2
$cmd and $src =~ /\.(tgz|tbz|txz|taz)$/
$cmd $src =~ /\.(tgz|tbz|txz|taz)$/
Truth table33%1/3
A and B
A= $cmdB= $src =~ /\.(tgz|tbz|txz|taz)$/
ABresult
0X0
100
111
147 {
148 0 $name = $src;
149 0 $name =~ s/\.(tgz|tbz|txz|taz)$/.tar/;
150 }
151  
152 7 ($name,$cmd);
153 }
154  
155  
156 sub handles
157 8 ▶{
Subroutine handles: called CC=24 SCAR=37.2
Pod documented
158 8 my($class, $ext) = @_;
159  
160 8 ▶ my $self = ref $class
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 7 1 8
161 ? $class
162 : __PACKAGE__->new;
163  
164 8 ▶ $ext = 'tar.Z' if $ext eq 'taz';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "taz" 0 8 8
165 8 ▶ $ext = 'tar.gz' if $ext eq 'tgz';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tgz" 0 8 8
166 8 ▶ $ext = 'tar.bz2' if $ext eq 'tbz';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tbz" 0 8 8
167 8 ▶ $ext = 'tar.xz' if $ext eq 'txz';
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "txz" 0 8 8
168  
169 8 ▶ return 1 if $ext eq 'tar.gz' && $self->_tar_can('tar.gz');
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tar.gz" and $self->_tar_can("tar.gz") 1 7 8
Condition66%2/3
$ext eq "tar.gz" and $self->_tar_can("tar.gz")
!ll&&!rl&&r
701
MC/DC50%1/2
$ext eq "tar.gz" and $self->_tar_can("tar.gz")
$ext eq "tar.gz" $self->_tar_can("tar.gz")
Truth table66%2/3
A and B
A= $ext eq "tar.gz"B= $self->_tar_can("tar.gz")
ABresult
0X0
100
111
170 7 ▶ return 1 if $ext eq 'tar.Z' && $self->_tar_can('tar.Z');
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tar.Z" and $self->_tar_can("tar.Z") 1 6 7
Condition66%2/3
$ext eq "tar.Z" and $self->_tar_can("tar.Z")
!ll&&!rl&&r
601
MC/DC50%1/2
$ext eq "tar.Z" and $self->_tar_can("tar.Z")
$ext eq "tar.Z" $self->_tar_can("tar.Z")
Truth table66%2/3
A and B
A= $ext eq "tar.Z"B= $self->_tar_can("tar.Z")
ABresult
0X0
100
111
171 6 ▶ return 1 if $ext eq 'tar.bz2' && $self->_tar_can('tar.bz2');
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tar.bz2" and $self->_tar_can("tar.bz2") 1 5 6
Condition66%2/3
$ext eq "tar.bz2" and $self->_tar_can("tar.bz2")
!ll&&!rl&&r
501
MC/DC50%1/2
$ext eq "tar.bz2" and $self->_tar_can("tar.bz2")
$ext eq "tar.bz2" $self->_tar_can("tar.bz2")
Truth table66%2/3
A and B
A= $ext eq "tar.bz2"B= $self->_tar_can("tar.bz2")
ABresult
0X0
100
111
172 5 ▶ return 1 if $ext eq 'tar.xz' && $self->_tar_can('tar.xz');
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tar.xz" and $self->_tar_can("tar.xz") 1 4 5
Condition66%2/3
$ext eq "tar.xz" and $self->_tar_can("tar.xz")
!ll&&!rl&&r
401
MC/DC50%1/2
$ext eq "tar.xz" and $self->_tar_can("tar.xz")
$ext eq "tar.xz" $self->_tar_can("tar.xz")
Truth table66%2/3
A and B
A= $ext eq "tar.xz"B= $self->_tar_can("tar.xz")
ABresult
0X0
100
111
173  
174 4 ▶ return 0 if $ext =~ s/\.(gz|Z)$// && (!$self->gzip_cmd);
Branch: 1 branch
BranchTrueFalseTotal
if $ext =~ s/\.(gz|Z)$// and not $self->gzip_cmd 0 4 4
Condition33%1/3
$ext =~ s/\.(gz|Z)$// and not $self->gzip_cmd
!ll&&!rl&&r
400
MC/DC0%0/2
$ext =~ s/\.(gz|Z)$// and not $self->gzip_cmd
$ext =~ s/\.(gz|Z)$// not $self->gzip_cmd
Truth table33%1/3
A and not(B)
A= $ext =~ s/\.(gz|Z)$//B= not $self->gzip_cmd
ABresult
0X0
100
111
175 4 ▶ return 0 if $ext =~ s/\.bz2$// && (!$self->bzip2_cmd);
Branch: 1 branch
BranchTrueFalseTotal
if $ext =~ s/\.bz2$// and not $self->bzip2_cmd 0 4 4
Condition33%1/3
$ext =~ s/\.bz2$// and not $self->bzip2_cmd
!ll&&!rl&&r
400
MC/DC0%0/2
$ext =~ s/\.bz2$// and not $self->bzip2_cmd
$ext =~ s/\.bz2$// not $self->bzip2_cmd
Truth table33%1/3
A and not(B)
A= $ext =~ s/\.bz2$//B= not $self->bzip2_cmd
ABresult
0X0
100
111
176 4 ▶ return 0 if $ext =~ s/\.xz$// && (!$self->xz_cmd);
Branch: 1 branch
BranchTrueFalseTotal
if $ext =~ s/\.xz$// and not $self->xz_cmd 0 4 4
Condition33%1/3
$ext =~ s/\.xz$// and not $self->xz_cmd
!ll&&!rl&&r
400
MC/DC0%0/2
$ext =~ s/\.xz$// and not $self->xz_cmd
$ext =~ s/\.xz$// not $self->xz_cmd
Truth table33%1/3
A and not(B)
A= $ext =~ s/\.xz$//B= not $self->xz_cmd
ABresult
0X0
100
111
177  
178 4 ▶ return 1 if $ext eq 'tar' && $self->_tar_can('tar');
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "tar" and $self->_tar_can("tar") 3 1 4
Condition66%2/3
$ext eq "tar" and $self->_tar_can("tar")
!ll&&!rl&&r
103
MC/DC50%1/2
$ext eq "tar" and $self->_tar_can("tar")
$ext eq "tar" $self->_tar_can("tar")
Truth table66%2/3
A and B
A= $ext eq "tar"B= $self->_tar_can("tar")
ABresult
0X0
100
111
179 1 ▶ return 1 if $ext eq 'zip' && $self->_tar_can('zip');
Branch: 1 branch
BranchTrueFalseTotal
if $ext eq "zip" and $self->_tar_can("zip") 1 0 1
Condition33%1/3
$ext eq "zip" and $self->_tar_can("zip")
!ll&&!rl&&r
001
MC/DC0%0/2
$ext eq "zip" and $self->_tar_can("zip")
$ext eq "zip" $self->_tar_can("zip")
Truth table33%1/3
A and B
A= $ext eq "zip"B= $self->_tar_can("zip")
ABresult
0X0
100
111
180  
181 0 return 0;
182 }
183  
184  
185 sub available
186 0 ▶{
Subroutine available: not called CC=1 SCAR=6.9
Pod documented
187 0 my(undef, $ext) = @_;
188  
189 # this is actually the same as handles
190 0 __PACKAGE__->handles($ext);
191 }
192  
193 sub init
194 2 ▶{
Subroutine init: called CC=9 SCAR=33.0
Pod documented
195 2 my($self, $meta) = @_;
196  
197 2 ▶ if($self->format eq 'tar.xz' && !$self->handles('tar.xz'))
Branch: 4 branches
BranchTrueFalseTotal
if ($self->format eq 'tar.xz' and not $self->handles('tar.xz')) { } 0 2 2
elsif ($self->format eq 'tar.bz2' and not $self->handles('tar.bz2')) { } 0 2 2
elsif ($self->format =~ /^tar\.(gz|Z)$/ and not $self->handles($self->format)) { } 0 2 2
elsif ($self->format eq 'zip' and not $self->handles('zip')) { } 0 4 4
Condition33%1/3
$self->format eq "tar.xz" and not $self->handles("tar.xz")
!ll&&!rl&&r
200
MC/DC0%0/2
$self->format eq "tar.xz" and not $self->handles("tar.xz")
$self->format eq "tar.xz" not $self->handles("tar.xz")
Truth table33%1/3
A and not(B)
A= $self->format eq "tar.xz"B= not $self->handles("tar.xz")
ABresult
0X0
100
111
198 {
199 0 $meta->add_requires('share' => 'Alien::xz' => '0.06');
200 }
201 ▶ elsif($self->format eq 'tar.bz2' && !$self->handles('tar.bz2'))
Condition33%1/3
$self->format eq "tar.bz2" and not $self->handles("tar.bz2")
!ll&&!rl&&r
200
MC/DC0%0/2
$self->format eq "tar.bz2" and not $self->handles("tar.bz2")
$self->format eq "tar.bz2" not $self->handles("tar.bz2")
Truth table33%1/3
A and not(B)
A= $self->format eq "tar.bz2"B= not $self->handles("tar.bz2")
ABresult
0X0
100
111
202 {
203 0 $meta->add_requires('share' => 'Alien::Libbz2' => '0.22');
204 }
205 ▶ elsif($self->format =~ /^tar\.(gz|Z)$/ && !$self->handles($self->format))
Condition33%1/3
$self->format =~ /^tar\.(gz|Z)$/ and not $self->handles($self->format)
!ll&&!rl&&r
200
MC/DC0%0/2
$self->format =~ /^tar\.(gz|Z)$/ and not $self->handles($self->format)
$self->format =~ /^tar\.(gz|Z)$/ not $self->handles($self->format)
Truth table33%1/3
A and not(B)
A= $self->format =~ /^tar\.(gz|Z)$/B= not $self->handles($self->format)
ABresult
0X0
100
111
206 {
207 0 $meta->add_requires('share' => 'Alien::gzip' => '0.03');
208 }
209 ▶ elsif($self->format eq 'zip' && !$self->handles('zip'))
Condition33%1/3
$self->format eq "zip" and not $self->handles("zip")
!ll&&!rl&&r
200
MC/DC0%0/2
$self->format eq "zip" and not $self->handles("zip")
$self->format eq "zip" not $self->handles("zip")
Truth table33%1/3
A and not(B)
A= $self->format eq "zip"B= not $self->handles("zip")
ABresult
0X0
100
111
210 {
211 0 $meta->add_requires('share' => 'Alien::unzip' => '0');
212 }
213  
214 $meta->register_hook(
215 7 ▶ extract => sub {
Subroutine __ANON__: called CC=7 SCAR=29.3
216 7 my($build, $src) = @_;
217  
218 7 my($dcon_name, $dcon_cmd) = _dcon($self, $src);
219  
220 7 ▶ if($dcon_name)
Branch: 1 branch
BranchTrueFalseTotal
if ($dcon_name) 0 7 7
221 {
222 0 ▶ unless($dcon_cmd)
Branch: 1 branch
BranchTrueFalseTotal
unless ($dcon_cmd) 0 0 0
223 {
224 0 die "unable to decompress $src";
225 }
226 # if we have already decompressed, then keep it.
227 0 ▶ unless(-f $dcon_name)
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $dcon_name) 0 0 0
228 {
229 # we don't use pipes, because that may not work on Windows.
230 # keep the original archive, in case another extract
231 # plugin needs it. keep the decompressed archive
232 # in case WE need it again.
233 0 my $src_tmp = Path::Tiny::path($src)
234 ->parent
235 ->child('x'.Path::Tiny::path($src)->basename);
236 0 my $dcon_tmp = Path::Tiny::path($dcon_name)
237 ->parent
238 ->child('x'.Path::Tiny::path($dcon_name)->basename);
239 0 $self->_cp($build, $src, $src_tmp);
240 0 $self->_run($build, $dcon_cmd, "-d", $src_tmp);
241 0 $self->_mv($build, $dcon_tmp, $dcon_name);
242 }
243 0 $src = $dcon_name;
244 }
245  
246 7 ▶ if($src =~ /\.zip$/i)
Branch: 2 branches
BranchTrueFalseTotal
if ($src =~ /\.zip$/i) { } 1 6 7
elsif ($src =~ /\.tar/ or $src =~ /(\.tgz|\.tbz|\.txz|\.taz)$/i) { } 6 0 6
247 {
248 1 $self->_run($build, $self->unzip_cmd, $src);
249 }
250 ▶ elsif($src =~ /\.tar/ || $src =~ /(\.tgz|\.tbz|\.txz|\.taz)$/i)
Condition33%1/3
$src =~ /\.tar/ or $src =~ /(\.tgz|\.tbz|\.txz|\.taz)$/i
l!l&&r!l&&!r
600
MC/DC0%0/2
$src =~ /\.tar/ or $src =~ /(\.tgz|\.tbz|\.txz|\.taz)$/i
$src =~ /\.tar/ $src =~ /(\.tgz|\.tbz|\.txz|\.taz)$/i
Truth table33%1/3
A or B
A= $src =~ /\.tar/B= $src =~ /(\.tgz|\.tbz|\.txz|\.taz)$/i
ABresult
1X1
011
000
251 {
252 6 $self->_run($build, $self->tar_cmd, '-xf', $src);
253 }
254 else
255 {
256 0 die "not sure of archive type from extension";
257 }
258 }
259 2 );
260 }
261  
262 8 my %tars;
263  
264 sub _tar_can
265 12 ▶{
Subroutine _tar_can: called CC=9 SCAR=22.1
266 12 my($self, $ext) = @_;
267  
268 12 ▶ unless(%tars)
Branch: 1 branch
BranchTrueFalseTotal
unless (%tars) 2 10 12
269 {
270 2 my $name = '';
271 2 local $_; # to avoid dynamically scoped read-only $_ from upper scopes
272 2 ▶ while(my $line = <DATA>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline DATA)) 166 2 168
273 {
274 166 ▶ if($line =~ /^\[ (.*) \]$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\[ (.*) \]$/) { } 12 154 166
275 {
276 12 $name = $1;
277 }
278 else
279 {
280 154 $tars{$name} .= $line;
281 }
282 }
283  
284 2 foreach my $key (keys %tars)
285 {
286 14 $tars{$key} = unpack "u", $tars{$key};
287 }
288 }
289  
290 12 my $name = "xx.$ext";
291  
292 12 ▶ return 0 unless $tars{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $tars{$name} 0 12 12
293  
294 12 local $CWD = tempdir( CLEANUP => 1 );
295  
296 12 ▶ my $cleanup = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
297 12 my $save = $CWD;
298 12 unlink $name;
299 12 unlink 'xx.txt';
300 12 $CWD = '..';
301 12 rmdir $save;
302 12 };
303  
304 12 Path::Tiny->new($name)->spew_raw($tars{$name});
305  
306 12 my @cmd = ($self->tar_cmd, 'xf', $name);
307 12 ▶ if($ext eq 'zip')
Branch: 1 branch
BranchTrueFalseTotal
if ($ext eq "zip") 1 11 12
308 {
309 1 @cmd = ($self->unzip_cmd, $name);
310 }
311  
312 12 ▶ my(undef, $exit) = capture_merged {
Subroutine __ANON__: called CC=1 SCAR=0.0
313 12 system(@cmd);
314 12 $?;
315 12 };
316  
317 12 ▶ if($exit)
Branch: 1 branch
BranchTrueFalseTotal
if ($exit) 0 12 12
318 {
319 0 $cleanup->();
320 0 return 0;
321 }
322  
323 12 my $content = eval { Path::Tiny->new('xx.txt')->slurp };
324 12 $cleanup->();
325  
326 12 ▶ return defined $content && $content eq "xx\n";
Condition33%1/3
defined $content && $content eq "xx\n"
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $content && $content eq "xx\n"
defined $content $content eq "xx\n"
Truth table33%1/3
A && B
A= defined $contentB= $content eq "xx\n"
ABresult
0X0
100
111
327 }
328  
329 8 1;
330  
331 =pod
332  
333 =encoding UTF-8
334  
335 =head1 NAME
336  
337 Alien::Build::Plugin::Extract::CommandLine - Plugin to extract an archive using command line tools
338  
339 =head1 VERSION
340  
341 version 2.88
342  
343 =head1 SYNOPSIS
344  
345 use alienfile;
346 plugin 'Extract::CommandLine' => (
347 format => 'tar.gz',
348 );
349  
350 =head1 DESCRIPTION
351  
352 Note: in most case you will want to use L<Alien::Build::Plugin::Extract::Negotiate>
353 instead. It picks the appropriate Extract plugin based on your platform and environment.
354 In some cases you may need to use this plugin directly instead.
355  
356 This plugin extracts from an archive in various formats using command line tools.
357  
358 =head1 PROPERTIES
359  
360 =head2 format
361  
362 Gives a hint as to the expected format.
363  
364 =head2 gzip_cmd
365  
366 The C<gzip> command, if available. C<undef> if not available.
367  
368 =head2 bzip2_cmd
369  
370 The C<bzip2> command, if available. C<undef> if not available.
371  
372 =head2 xz_cmd
373  
374 The C<xz> command, if available. C<undef> if not available.
375  
376 =head2 tar_cmd
377  
378 The C<tar> command, if available. C<undef> if not available.
379  
380 =head2 unzip_cmd
381  
382 The C<unzip> command, if available. C<undef> if not available.
383  
384 =head1 METHODS
385  
386 =head2 handles
387  
388 Alien::Build::Plugin::Extract::CommandLine->handles($ext);
389 $plugin->handles($ext);
390  
391 Returns true if the plugin is able to handle the archive of the
392 given format.
393  
394 =head2 available
395  
396 Alien::Build::Plugin::Extract::CommandLine->available($ext);
397  
398 Returns true if the plugin is available to extract without
399 installing anything new.
400  
401 =head1 SEE ALSO
402  
403 L<Alien::Build::Plugin::Extract::Negotiate>, L<Alien::Build>, L<alienfile>, L<Alien::Build::MM>, L<Alien>
404  
405 =head1 AUTHOR
406  
407 Author: Graham Ollis E<lt>plicease@cpan.orgE<gt>
408  
409 Contributors:
410  
411 Diab Jerius (DJERIUS)
412  
413 Roy Storey (KIWIROY)
414  
415 Ilya Pavlov
416  
417 David Mertens (run4flat)
418  
419 Mark Nunberg (mordy, mnunberg)
420  
421 Christian Walde (Mithaldu)
422  
423 Brian Wightman (MidLifeXis)
424  
425 Zaki Mughal (zmughal)
426  
427 mohawk (mohawk2, ETJ)
428  
429 Vikas N Kumar (vikasnkumar)
430  
431 Flavio Poletti (polettix)
432  
433 Salvador Fandiño (salva)
434  
435 Gianni Ceccarelli (dakkar)
436  
437 Pavel Shaydo (zwon, trinitum)
438  
439 Kang-min Liu (劉康民, gugod)
440  
441 Nicholas Shipp (nshp)
442  
443 Juan Julián Merelo Guervós (JJ)
444  
445 Joel Berger (JBERGER)
446  
447 Petr Písař (ppisar)
448  
449 Lance Wicks (LANCEW)
450  
451 Ahmad Fatoum (a3f, ATHREEF)
452  
453 José Joaquín Atria (JJATRIA)
454  
455 Duke Leto (LETO)
456  
457 Shoichi Kaji (SKAJI)
458  
459 Shawn Laffan (SLAFFAN)
460  
461 Paul Evans (leonerd, PEVANS)
462  
463 Håkon Hægland (hakonhagland, HAKONH)
464  
465 nick nauwelaerts (INPHOBIA)
466  
467 Florian Weimer
468  
469 Marcel Telka (mtelka)
470  
471 =head1 COPYRIGHT AND LICENSE
472  
473 This software is copyright (c) 2011-2022 by Graham Ollis.
474  
475 This is free software; you can redistribute it and/or modify it under
476 the same terms as the Perl 5 programming language system itself.
477  
478 =cut
479  
480 __DATA__
« blib/lib/Alien/Build/Plugin/Digest/SHAPP.pm ↑ Summary blib/lib/Test/Alien/Diag.pm »