| 1 | # ABSTRACT: Unpack an archive into a temporary directory | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::ArchiveUnpacker; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 59 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 59 | ▶ | use MooseX::StrictConstructor; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 59 | ▶ | use MooseX::Types::Moose qw(Bool); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 59 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 59 | ▶ | use Cwd qw(getcwd); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 59 | ▶ | use Cwd::Guard qw(cwd_guard); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 59 | ▶ | use Path::Class qw(dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 59 | ▶ | use Archive::Extract; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 59 | ▶ | use File::Temp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 59 | ▶ | use Pinto::Types qw(File); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 59 | ▶ | use Pinto::Util qw(debug throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 59 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 59 | has archive => ( | |||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | isa => File, | ||||||||||||||||||||||||||||
| 28 | required => 1, | ||||||||||||||||||||||||||||
| 29 | coerce => 1, | ||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | has temp_dir => ( | ||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | isa => 'File::Temp::Dir', | ||||||||||||||||||||||||||||
| 35 | 59 | ▶ | default => sub { File::Temp->newdir( CLEANUP => $_[0]->cleanup ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 36 | 59 | lazy => 1, | |||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 59 | has cleanup => ( | |||||||||||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||||||||||
| 41 | isa => Bool, | ||||||||||||||||||||||||||||
| 42 | default => 1, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 59 | ▶ | sub unpack { | ||||||||||||||||||||||||||
|
Subroutine
unpack: called CC=6 SCAR=18.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 59 | my ($self) = @_; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 59 | my $archive = $self->archive; | |||||||||||||||||||||||||||
| 51 | 59 | my $temp_dir = $self->temp_dir->dirname; | |||||||||||||||||||||||||||
| 52 | 59 | my $cwd_guard = cwd_guard(getcwd); # Archive::Extract will chdir | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 59 | local $Archive::Extract::PREFER_BIN = 1; | |||||||||||||||||||||||||||
| 55 | 59 | ▶ | local $Archive::Extract::DEBUG = 1 if ( $ENV{PINTO_DEBUG} || 0 ) > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$ENV{'PINTO_DEBUG'} || 0
MC/DC0%0/1
$ENV{'PINTO_DEBUG'} || 0
$ENV{'PINTO_DEBUG'}
Truth table50%1/2
A
A= $ENV{'PINTO_DEBUG'}
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 59 | my $ae = Archive::Extract->new( archive => $archive ); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 59 | debug "Unpacking $archive into $temp_dir"; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 59 | my $ok = $ae->extract( to => $temp_dir ); | |||||||||||||||||||||||||||
| 62 | 59 | ▶ | throw "Failed to unpack $archive: " . $ae->error if not $ok; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 59 | my @children = dir($temp_dir)->children; | |||||||||||||||||||||||||||
| 65 | 59 | ▶ | return @children == 1 && -d $children[0] ? $children[0] : dir($temp_dir); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@children == 1 and -d $children[0]
MC/DC0%0/2
@children == 1 and -d $children[0]
@children == 1
-d $children[0]
Truth table33%1/3
A and B
A= @children == 1B= -d $children[0]
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 59 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | #----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 59 | 1; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | __END__ | ||||||||||||||||||||||||||||