line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Unpack an archive into a temporary directory |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Pinto::ArchiveUnpacker; |
4
|
|
|
|
|
|
|
|
5
|
51
|
|
|
51
|
|
312
|
use Moose; |
|
51
|
|
|
|
|
113
|
|
|
51
|
|
|
|
|
379
|
|
6
|
51
|
|
|
51
|
|
317631
|
use MooseX::StrictConstructor; |
|
51
|
|
|
|
|
116
|
|
|
51
|
|
|
|
|
436
|
|
7
|
51
|
|
|
51
|
|
152339
|
use MooseX::Types::Moose qw(Bool); |
|
51
|
|
|
|
|
126
|
|
|
51
|
|
|
|
|
450
|
|
8
|
51
|
|
|
51
|
|
222991
|
use MooseX::MarkAsMethods ( autoclean => 1 ); |
|
51
|
|
|
|
|
122
|
|
|
51
|
|
|
|
|
406
|
|
9
|
|
|
|
|
|
|
|
10
|
51
|
|
|
51
|
|
180175
|
use Cwd qw(getcwd); |
|
51
|
|
|
|
|
122
|
|
|
51
|
|
|
|
|
3075
|
|
11
|
51
|
|
|
51
|
|
17774
|
use Cwd::Guard qw(cwd_guard); |
|
51
|
|
|
|
|
26313
|
|
|
51
|
|
|
|
|
2681
|
|
12
|
51
|
|
|
51
|
|
379
|
use Path::Class qw(dir); |
|
51
|
|
|
|
|
130
|
|
|
51
|
|
|
|
|
2123
|
|
13
|
51
|
|
|
51
|
|
19786
|
use Archive::Extract; |
|
51
|
|
|
|
|
6024813
|
|
|
51
|
|
|
|
|
2128
|
|
14
|
51
|
|
|
51
|
|
444
|
use File::Temp; |
|
51
|
|
|
|
|
106
|
|
|
51
|
|
|
|
|
4273
|
|
15
|
|
|
|
|
|
|
|
16
|
51
|
|
|
51
|
|
316
|
use Pinto::Types qw(File); |
|
51
|
|
|
|
|
113
|
|
|
51
|
|
|
|
|
506
|
|
17
|
51
|
|
|
51
|
|
300110
|
use Pinto::Util qw(debug throw); |
|
51
|
|
|
|
|
122
|
|
|
51
|
|
|
|
|
17848
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.13'; # VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
default => sub { File::Temp->newdir( CLEANUP => $_[0]->cleanup ) }, |
36
|
|
|
|
|
|
|
lazy => 1, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has cleanup => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
isa => Bool, |
42
|
|
|
|
|
|
|
default => 1, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub unpack { |
48
|
161
|
|
|
161
|
0
|
789
|
my ($self) = @_; |
49
|
|
|
|
|
|
|
|
50
|
161
|
|
|
|
|
4648
|
my $archive = $self->archive; |
51
|
161
|
|
|
|
|
4414
|
my $temp_dir = $self->temp_dir->dirname; |
52
|
161
|
|
|
|
|
3700
|
my $cwd_guard = cwd_guard(getcwd); # Archive::Extract will chdir |
53
|
|
|
|
|
|
|
|
54
|
161
|
|
|
|
|
11715
|
local $Archive::Extract::PREFER_BIN = 1; |
55
|
161
|
50
|
50
|
|
|
1863
|
local $Archive::Extract::DEBUG = 1 if ( $ENV{PINTO_DEBUG} || 0 ) > 1; |
56
|
|
|
|
|
|
|
|
57
|
161
|
|
|
|
|
1805
|
my $ae = Archive::Extract->new( archive => $archive ); |
58
|
|
|
|
|
|
|
|
59
|
161
|
|
|
|
|
57835
|
debug "Unpacking $archive into $temp_dir"; |
60
|
|
|
|
|
|
|
|
61
|
161
|
|
|
|
|
1011
|
my $ok = $ae->extract( to => $temp_dir ); |
62
|
161
|
50
|
|
|
|
7058964
|
throw "Failed to unpack $archive: " . $ae->error if not $ok; |
63
|
|
|
|
|
|
|
|
64
|
161
|
|
|
|
|
2819
|
my @children = dir($temp_dir)->children; |
65
|
161
|
50
|
33
|
|
|
122488
|
return @children == 1 && -d $children[0] ? $children[0] : dir($temp_dir); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#----------------------------------------------------------------------------- |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=encoding UTF-8 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=for :stopwords Jeffrey Ryan Thalhammer |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 NAME |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Pinto::ArchiveUnpacker - Unpack an archive into a temporary directory |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 VERSION |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
version 0.13 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 AUTHOR |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Jeffrey Ryan Thalhammer <jeff@stratopan.com> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
101
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |