| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Alien::Build::Plugin::Extract::ArchiveTar; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 7 |  |  | 7 |  | 1404 | use strict; | 
|  | 7 |  |  |  |  | 17 |  | 
|  | 7 |  |  |  |  | 184 |  | 
| 4 | 7 |  |  | 7 |  | 34 | use warnings; | 
|  | 7 |  |  |  |  | 13 |  | 
|  | 7 |  |  |  |  | 144 |  | 
| 5 | 7 |  |  | 7 |  | 115 | use 5.008004; | 
|  | 7 |  |  |  |  | 22 |  | 
| 6 | 7 |  |  | 7 |  | 384 | use Alien::Build::Plugin; | 
|  | 7 |  |  |  |  | 13 |  | 
|  | 7 |  |  |  |  | 51 |  | 
| 7 | 7 |  |  | 7 |  | 773 | use File::chdir; | 
|  | 7 |  |  |  |  | 5264 |  | 
|  | 7 |  |  |  |  | 743 |  | 
| 8 | 7 |  |  | 7 |  | 59 | use File::Temp (); | 
|  | 7 |  |  |  |  | 23 |  | 
|  | 7 |  |  |  |  | 104 |  | 
| 9 | 7 |  |  | 7 |  | 39 | use Path::Tiny (); | 
|  | 7 |  |  |  |  | 13 |  | 
|  | 7 |  |  |  |  | 3472 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # ABSTRACT: Plugin to extract a tarball using Archive::Tar | 
| 12 |  |  |  |  |  |  | our $VERSION = '2.47'; # VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has '+format' => 'tar'; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | sub handles | 
| 19 |  |  |  |  |  |  | { | 
| 20 | 0 |  |  | 0 | 1 | 0 | my(undef, $ext) = @_; | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 0 | 0 |  |  |  | 0 | return 1 if $ext =~ /^(tar|tar.gz|tar.bz2|tbz|taz)$/; | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 0 |  |  |  |  | 0 | return 0; | 
| 25 |  |  |  |  |  |  | } | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub available | 
| 29 |  |  |  |  |  |  | { | 
| 30 | 16 |  |  | 16 | 1 | 91450 | my(undef, $ext) = @_; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 16 | 100 |  |  |  | 59 | if($ext eq 'tar.gz') | 
|  |  | 100 |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | { | 
| 34 | 8 |  |  |  |  | 16 | return !! eval { require Archive::Tar; Archive::Tar->has_zlib_support }; | 
|  | 8 |  |  |  |  | 647 |  | 
|  | 8 |  |  |  |  | 74627 |  | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  | elsif($ext eq 'tar.bz2') | 
| 37 |  |  |  |  |  |  | { | 
| 38 | 3 | 100 |  |  |  | 10 | return !! eval { require Archive::Tar; Archive::Tar->has_bzip2_support && __PACKAGE__->_can_bz2 }; | 
|  | 3 |  |  |  |  | 21 |  | 
|  | 3 |  |  |  |  | 28 |  | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | else | 
| 41 |  |  |  |  |  |  | { | 
| 42 | 5 |  |  |  |  | 20 | return $ext eq 'tar'; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub init | 
| 47 |  |  |  |  |  |  | { | 
| 48 | 14 |  |  | 14 | 1 | 74 | my($self, $meta) = @_; | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 14 |  |  |  |  | 55 | $meta->add_requires('share' => 'Archive::Tar' => 0); | 
| 51 | 14 | 100 | 66 |  |  | 69 | if($self->format eq 'tar.gz' || $self->format eq 'tgz') | 
|  |  | 50 | 33 |  |  |  |  | 
| 52 |  |  |  |  |  |  | { | 
| 53 | 5 |  |  |  |  | 12 | $meta->add_requires('share' => 'IO::Zlib' => 0); | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  | elsif($self->format eq 'tar.bz2' || $self->format eq 'tbz') | 
| 56 |  |  |  |  |  |  | { | 
| 57 | 0 |  |  |  |  | 0 | $meta->add_requires('share' => 'IO::Uncompress::Bunzip2' => 0); | 
| 58 | 0 |  |  |  |  | 0 | $meta->add_requires('share' => 'IO::Compress::Bzip2' => 0); | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | $meta->register_hook( | 
| 62 |  |  |  |  |  |  | extract => sub { | 
| 63 | 11 |  |  | 11 |  | 36 | my($build, $src) = @_; | 
| 64 | 11 |  |  |  |  | 112 | my $tar = Archive::Tar->new; | 
| 65 | 11 |  |  |  |  | 180 | $tar->read($src); | 
| 66 | 11 |  |  |  |  | 49326 | $tar->extract; | 
| 67 |  |  |  |  |  |  | } | 
| 68 | 14 |  |  |  |  | 135 | ); | 
| 69 |  |  |  |  |  |  | } | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | sub _can_bz2 | 
| 72 |  |  |  |  |  |  | { | 
| 73 |  |  |  |  |  |  | # even when Archive::Tar reports that it supports bz2, I can sometimes get this error: | 
| 74 |  |  |  |  |  |  | # 'Cannot read enough bytes from the tarfile', so lets just probe for actual support! | 
| 75 | 3 |  |  | 3 |  | 435 | my $dir = Path::Tiny->new(File::Temp::tempdir( CLEANUP => 1 )); | 
| 76 | 3 |  |  |  |  | 1461 | eval { | 
| 77 | 3 |  |  |  |  | 39 | local $CWD = $dir; | 
| 78 | 3 |  |  |  |  | 221 | 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 | 
| 79 | 3 |  |  |  |  | 16 | Path::Tiny->new('xx.tar.bz2')->spew_raw($tarball); | 
| 80 | 3 |  |  |  |  | 1485 | require Archive::Tar; | 
| 81 | 3 |  |  |  |  | 30 | my $tar = Archive::Tar->new; | 
| 82 | 3 |  |  |  |  | 40 | $tar->read('xx.tar.bz2'); | 
| 83 | 3 |  |  |  |  | 7376 | $tar->extract; | 
| 84 | 3 |  |  |  |  | 20397 | my $content = Path::Tiny->new('xx.txt')->slurp; | 
| 85 | 3 | 50 | 33 |  |  | 1303 | die unless $content && $content eq "xx\n"; | 
| 86 |  |  |  |  |  |  | }; | 
| 87 | 3 |  |  |  |  | 206 | my $error = $@; | 
| 88 | 3 |  |  |  |  | 49 | $dir->remove_tree; | 
| 89 | 3 |  |  |  |  | 1940 | !$error; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | 1; | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | __END__ |