line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Path::Tiny::Archive::Tar; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Tar/untar add-on for file path utility |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
173775
|
use strict; |
|
2
|
|
|
|
|
25
|
|
|
2
|
|
|
|
|
67
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
73
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1548
|
use Archive::Tar qw( COMPRESS_GZIP COMPRESS_BZIP ); |
|
2
|
|
|
|
|
201288
|
|
|
2
|
|
|
|
|
178
|
|
9
|
2
|
|
|
2
|
|
23
|
use Compress::Raw::Zlib (); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
43
|
|
10
|
2
|
|
|
2
|
|
11
|
use Path::Tiny qw( path ); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
86
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
1202
|
use namespace::clean; |
|
2
|
|
|
|
|
34709
|
|
|
2
|
|
|
|
|
14
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
556
|
use Exporter qw( import ); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
185
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( const =>[qw( |
20
|
|
|
|
|
|
|
COMPRESSION_NONE |
21
|
|
|
|
|
|
|
COMPRESSION_GZIP |
22
|
|
|
|
|
|
|
COMPRESSION_GZIP_DEFAULT |
23
|
|
|
|
|
|
|
COMPRESSION_GZIP_NONE |
24
|
|
|
|
|
|
|
COMPRESSION_GZIP_FASTEST |
25
|
|
|
|
|
|
|
COMPRESSION_GZIP_BEST |
26
|
|
|
|
|
|
|
COMPRESSION_BZIP2 |
27
|
|
|
|
|
|
|
)] ); |
28
|
|
|
|
|
|
|
our @EXPORT_OK = @{ $EXPORT_TAGS{const} }; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
BEGIN { |
32
|
2
|
|
|
2
|
|
229
|
push(@Path::Tiny::ISA, __PACKAGE__); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use constant { |
36
|
2
|
|
|
|
|
21
|
COMPRESSION_NONE => undef, |
37
|
|
|
|
|
|
|
# Hack for Archive::Tar: true so don't use default compression and pass |
38
|
|
|
|
|
|
|
# this level to IO::Zlib. And hack for Compress::Zlib: not digit so use |
39
|
|
|
|
|
|
|
# default compression (letters may specify other compression modes). |
40
|
|
|
|
|
|
|
COMPRESSION_GZIP => '-', |
41
|
|
|
|
|
|
|
COMPRESSION_GZIP_DEFAULT => '-', |
42
|
|
|
|
|
|
|
# Hack for Archive::Tar: zero but true so pass 0 level to IO::Zlib. |
43
|
|
|
|
|
|
|
COMPRESSION_GZIP_NONE => '00', |
44
|
|
|
|
|
|
|
COMPRESSION_GZIP_FASTEST => Compress::Raw::Zlib::Z_BEST_SPEED, |
45
|
|
|
|
|
|
|
COMPRESSION_GZIP_BEST => Compress::Raw::Zlib::Z_BEST_COMPRESSION, |
46
|
|
|
|
|
|
|
COMPRESSION_BZIP2 => COMPRESS_BZIP, |
47
|
2
|
|
|
2
|
|
16
|
}; |
|
2
|
|
|
|
|
4
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub tar { |
51
|
4
|
|
|
4
|
1
|
25108
|
my ($self, $dest, $level) = @_; |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
19
|
$dest = path($dest); |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
78
|
my $tar = Archive::Tar->new; |
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
55
|
if ($self->is_file) { |
|
|
50
|
|
|
|
|
|
58
|
3
|
|
|
|
|
79
|
my $file = Archive::Tar::File->new(file => $self->stringify()); |
59
|
|
|
|
|
|
|
|
60
|
3
|
50
|
|
|
|
1476
|
return unless $file; |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
|
|
15
|
$file->name($self->basename); |
63
|
3
|
|
|
|
|
122
|
$file->prefix(''); |
64
|
|
|
|
|
|
|
|
65
|
3
|
50
|
|
|
|
37
|
$tar->add_files($file) or return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ($self->is_dir) { |
68
|
1
|
|
|
|
|
44
|
my $paths = $self->iterator({ recurse => 1 }); |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
36
|
while (my $path = $paths->()) { |
71
|
2
|
|
|
|
|
299
|
my $file = Archive::Tar::File->new(file => $path->stringify()); |
72
|
|
|
|
|
|
|
|
73
|
2
|
50
|
|
|
|
650
|
return unless $file; |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
9
|
$file->rename($path->relative($self)); |
76
|
|
|
|
|
|
|
|
77
|
2
|
50
|
|
|
|
664
|
$tar->add_files($file) or return; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
else { |
81
|
0
|
|
|
|
|
0
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
4
|
100
|
|
|
|
356
|
$tar->write($dest->stringify(), defined $level ? $level : ()) or return; |
|
|
50
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
4
|
|
|
|
|
6185
|
return $dest; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub untar { |
91
|
2
|
|
|
2
|
1
|
13391
|
my ($self, $dest) = @_; |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
8
|
$dest = path($dest); |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
77
|
my $files = Archive::Tar->iter($self->stringify()); |
96
|
|
|
|
|
|
|
|
97
|
2
|
50
|
|
|
|
3477
|
return unless $files; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
8
|
while (my $file = $files->()) { |
100
|
3
|
50
|
|
|
|
3711
|
$file->extract($dest->child($file->full_path)->stringify()) or return; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
2358
|
return $dest; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |