« blib/lib/Alien/Build/Plugin/PkgConfig/Negotiate.pm
↑ Summary
blib/lib/Alien/Build/CommandSequence.pm »
| 1 | package Alien::Build::Plugin::Extract::ArchiveTar; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 10 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Alien::Build::Plugin; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use File::chdir; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 9 | 10 | ▶ | use Path::Tiny (); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | # ABSTRACT: Plugin to extract a tarball using Archive::Tar | ||||||||||||||||||||||||||||||||||||
| 12 | 10 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||
| 15 | 10 | has '+format' => 'tar'; | |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | sub handles | ||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
handles: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 20 | 0 | my(undef, $ext) = @_; | |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | return 1 if $ext =~ /^(tar|tar\.gz|tar\.bz2|tar\.xz|tbz|taz|txz)$/; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | 0 | return 0; | |||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | sub available | ||||||||||||||||||||||||||||||||||||
| 29 | 18 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
available: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 30 | 18 | my(undef, $ext) = @_; | |||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 18 | ▶ | if($ext eq 'tar.gz') | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||
| 34 | 8 | return !! eval { require Archive::Tar; Archive::Tar->has_zlib_support }; | |||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||
| 36 | elsif($ext eq 'tar.bz2') | ||||||||||||||||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||||||||||||||||
| 38 | 3 | ▶ | return !! eval { require Archive::Tar; Archive::Tar->has_bzip2_support && __PACKAGE__->_can_bz2 }; | ||||||||||||||||||||||||||||||||||
|
Condition66%2/3
'Archive::Tar'->has_bzip2_support && __PACKAGE__->_can_bz2
MC/DC50%1/2
'Archive::Tar'->has_bzip2_support && __PACKAGE__->_can_bz2
'Archive::Tar'->has_bzip2_support
__PACKAGE__->_can_bz2
Truth table66%2/3
A && B
A= 'Archive::Tar'->has_bzip2_supportB= __PACKAGE__->_can_bz2
| |||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||
| 40 | elsif($ext eq 'tar.xz') | ||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||
| 42 | 2 | return !! eval { require Archive::Tar; Archive::Tar->has_xz_support }; | |||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||
| 44 | else | ||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||
| 46 | 5 | return $ext eq 'tar'; | |||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||
| 50 | sub init | ||||||||||||||||||||||||||||||||||||
| 51 | 32 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=7 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 52 | 32 | my($self, $meta) = @_; | |||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||
| 54 | 32 | $meta->add_requires('share' => 'Archive::Tar' => 0); | |||||||||||||||||||||||||||||||||||
| 55 | 32 | ▶ | if($self->format eq 'tar.gz' || $self->format eq 'tgz') | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$self->format eq "tar.gz" or $self->format eq "tgz"
MC/DC50%1/2
$self->format eq "tar.gz" or $self->format eq "tgz"
$self->format eq "tar.gz"
$self->format eq "tgz"
Truth table66%2/3
A or B
A= $self->format eq "tar.gz"B= $self->format eq "tgz"
| |||||||||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||||||||
| 57 | 5 | $meta->add_requires('share' => 'IO::Zlib' => 0); | |||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||
| 59 | ▶ | elsif($self->format eq 'tar.bz2' || $self->format eq 'tbz') | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->format eq "tar.bz2" or $self->format eq "tbz"
MC/DC0%0/2
$self->format eq "tar.bz2" or $self->format eq "tbz"
$self->format eq "tar.bz2"
$self->format eq "tbz"
Truth table33%1/3
A or B
A= $self->format eq "tar.bz2"B= $self->format eq "tbz"
| |||||||||||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||||||||||
| 61 | 0 | $meta->add_requires('share' => 'IO::Uncompress::Bunzip2' => 0); | |||||||||||||||||||||||||||||||||||
| 62 | 0 | $meta->add_requires('share' => 'IO::Compress::Bzip2' => 0); | |||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||
| 64 | ▶ | elsif($self->format eq 'tar.xz' || $self->format eq 'txz') | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->format eq "tar.xz" or $self->format eq "txz"
MC/DC0%0/2
$self->format eq "tar.xz" or $self->format eq "txz"
$self->format eq "tar.xz"
$self->format eq "txz"
Truth table33%1/3
A or B
A= $self->format eq "tar.xz"B= $self->format eq "txz"
| |||||||||||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||||||||||
| 66 | 0 | $meta->add_requires('share' => 'Archive::Tar' => 2.34); | |||||||||||||||||||||||||||||||||||
| 67 | 0 | $meta->add_requires('share' => 'IO::Uncompress::UnXz' => 0); | |||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | $meta->register_hook( | ||||||||||||||||||||||||||||||||||||
| 71 | 21 | ▶ | extract => sub { | ||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 72 | 21 | my($build, $src) = @_; | |||||||||||||||||||||||||||||||||||
| 73 | 21 | my $tar = Archive::Tar->new; | |||||||||||||||||||||||||||||||||||
| 74 | 21 | $tar->read($src); | |||||||||||||||||||||||||||||||||||
| 75 | 21 | $tar->extract; | |||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||
| 77 | 32 | ); | |||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||
| 80 | sub _can_bz2 | ||||||||||||||||||||||||||||||||||||
| 81 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_can_bz2: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||
| 82 | # even when Archive::Tar reports that it supports bz2, I can sometimes get this error: | ||||||||||||||||||||||||||||||||||||
| 83 | # 'Cannot read enough bytes from the tar file', so lets just probe for actual support! | ||||||||||||||||||||||||||||||||||||
| 84 | 3 | my $dir = Path::Tiny->new(File::Temp::tempdir( CLEANUP => 1 )); | |||||||||||||||||||||||||||||||||||
| 85 | 3 | eval { | |||||||||||||||||||||||||||||||||||
| 86 | 3 | local $CWD = $dir; | |||||||||||||||||||||||||||||||||||
| 87 | 3 | my $tarball = unpack "u", q{M0EIH.3%!62936=+(]$0``$A[D-$0`8!``7^``!!AI)Y`!```""``=!JGIH-(MT#0]0/2!**---&F@;4#0&:D;X?(6@JH(2<%'N$%3VHC-9E>S/N@"6&I*1@GNJNHCC2>$I5(<0BKR.=XBZ""HVZ;T,CV\LJ!K&*?9`#\7<D4X4)#2R/1$`}; | |||||||||||||||||||||||||||||||||||
| 88 | 3 | Path::Tiny->new('xx.tar.bz2')->spew_raw($tarball); | |||||||||||||||||||||||||||||||||||
| 89 | 3 | require Archive::Tar; | |||||||||||||||||||||||||||||||||||
| 90 | 3 | my $tar = Archive::Tar->new; | |||||||||||||||||||||||||||||||||||
| 91 | 3 | $tar->read('xx.tar.bz2'); | |||||||||||||||||||||||||||||||||||
| 92 | 3 | $tar->extract; | |||||||||||||||||||||||||||||||||||
| 93 | 3 | my $content = Path::Tiny->new('xx.txt')->slurp; | |||||||||||||||||||||||||||||||||||
| 94 | 3 | ▶ | die unless $content && $content eq "xx\n"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$content and $content eq "xx\n"
MC/DC0%0/2
$content and $content eq "xx\n"
$content
$content eq "xx\n"
Truth table33%1/3
A and B
A= $contentB= $content eq "xx\n"
| |||||||||||||||||||||||||||||||||||||
| 95 | }; | ||||||||||||||||||||||||||||||||||||
| 96 | 3 | my $error = $@; | |||||||||||||||||||||||||||||||||||
| 97 | 3 | $dir->remove_tree; | |||||||||||||||||||||||||||||||||||
| 98 | 3 | !$error; | |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | 10 | 1; | |||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||
| 103 | __END__ | ||||||||||||||||||||||||||||||||||||