| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Filename::Compressed; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-01-01'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
444
|
use 5.010001; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
31
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
21
|
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
0
|
|
|
|
1
|
|
|
|
|
411
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(check_compressed_filename); |
|
13
|
|
|
|
|
|
|
#list_compressor_suffixes |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SUFFIXES = ( |
|
16
|
|
|
|
|
|
|
'.Z' => {name=>'NCompress'}, |
|
17
|
|
|
|
|
|
|
'.gz' => {name=>'Gzip'}, |
|
18
|
|
|
|
|
|
|
'.bz2' => {name=>'Bzip2'}, |
|
19
|
|
|
|
|
|
|
'.xz' => {name=>'XZ'}, |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our %COMPRESSORS = ( |
|
23
|
|
|
|
|
|
|
NCompress => { |
|
24
|
|
|
|
|
|
|
# all programs mentioned here must accept filename(s) as arguments. |
|
25
|
|
|
|
|
|
|
# preferably CLI. |
|
26
|
|
|
|
|
|
|
compressor_programs => [ |
|
27
|
|
|
|
|
|
|
{name => 'compress', opts => ''}, |
|
28
|
|
|
|
|
|
|
], |
|
29
|
|
|
|
|
|
|
decompressor_programs => [ |
|
30
|
|
|
|
|
|
|
{name => 'uncompress', opts => ''}, |
|
31
|
|
|
|
|
|
|
], |
|
32
|
|
|
|
|
|
|
}, |
|
33
|
|
|
|
|
|
|
Gzip => { |
|
34
|
|
|
|
|
|
|
compressor_programs => [ |
|
35
|
|
|
|
|
|
|
{name => 'gzip', opts => ''}, |
|
36
|
|
|
|
|
|
|
], |
|
37
|
|
|
|
|
|
|
decompressor_programs => [ |
|
38
|
|
|
|
|
|
|
{name => 'gzip', opts => '-d'}, |
|
39
|
|
|
|
|
|
|
{name => 'gunzip', opts => ''}, |
|
40
|
|
|
|
|
|
|
], |
|
41
|
|
|
|
|
|
|
}, |
|
42
|
|
|
|
|
|
|
Bzip2 => { |
|
43
|
|
|
|
|
|
|
compressor_programs => [ |
|
44
|
|
|
|
|
|
|
{name => 'bzip2', opts => ''}, |
|
45
|
|
|
|
|
|
|
], |
|
46
|
|
|
|
|
|
|
decompressor_programs => [ |
|
47
|
|
|
|
|
|
|
{name => 'bzip2', opts => '-d'}, |
|
48
|
|
|
|
|
|
|
{name => 'bunzip2', opts => ''}, |
|
49
|
|
|
|
|
|
|
], |
|
50
|
|
|
|
|
|
|
}, |
|
51
|
|
|
|
|
|
|
XZ => { |
|
52
|
|
|
|
|
|
|
compressor_programs => [ |
|
53
|
|
|
|
|
|
|
{name => 'xz', opts => ''}, |
|
54
|
|
|
|
|
|
|
], |
|
55
|
|
|
|
|
|
|
decompressor_programs => [ |
|
56
|
|
|
|
|
|
|
{name => 'xz', opts => '-d'}, |
|
57
|
|
|
|
|
|
|
{name => 'unxz', opts => ''}, |
|
58
|
|
|
|
|
|
|
], |
|
59
|
|
|
|
|
|
|
}, |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
); |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
our %SPEC; |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$SPEC{check_compressed_filename} = { |
|
66
|
|
|
|
|
|
|
v => 1.1, |
|
67
|
|
|
|
|
|
|
summary => 'Check whether filename indicates being compressed', |
|
68
|
|
|
|
|
|
|
description => <<'_', |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
_ |
|
72
|
|
|
|
|
|
|
args => { |
|
73
|
|
|
|
|
|
|
filename => { |
|
74
|
|
|
|
|
|
|
schema => 'str*', |
|
75
|
|
|
|
|
|
|
req => 1, |
|
76
|
|
|
|
|
|
|
pos => 0, |
|
77
|
|
|
|
|
|
|
}, |
|
78
|
|
|
|
|
|
|
# recurse? |
|
79
|
|
|
|
|
|
|
ci => { |
|
80
|
|
|
|
|
|
|
summary => 'Whether to match case-insensitively', |
|
81
|
|
|
|
|
|
|
schema => 'bool', |
|
82
|
|
|
|
|
|
|
default => 1, |
|
83
|
|
|
|
|
|
|
}, |
|
84
|
|
|
|
|
|
|
}, |
|
85
|
|
|
|
|
|
|
result_naked => 1, |
|
86
|
|
|
|
|
|
|
result => { |
|
87
|
|
|
|
|
|
|
schema => ['any*', of=>['bool*', 'hash*']], |
|
88
|
|
|
|
|
|
|
description => <<'_', |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Return false if no compressor suffixes detected. Otherwise return a hash of |
|
91
|
|
|
|
|
|
|
information, which contains these keys: `compressor_name`, `compressor_suffix`, |
|
92
|
|
|
|
|
|
|
`uncompressed_filename`. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
_ |
|
95
|
|
|
|
|
|
|
}, |
|
96
|
|
|
|
|
|
|
}; |
|
97
|
|
|
|
|
|
|
sub check_compressed_filename { |
|
98
|
6
|
|
|
6
|
1
|
26
|
my %args = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
6
|
|
|
|
|
8
|
my $filename = $args{filename}; |
|
101
|
6
|
50
|
|
|
|
39
|
$filename =~ /(\.\w+)\z/ or return 0; |
|
102
|
6
|
|
100
|
|
|
21
|
my $ci = $args{ci} // 1; |
|
103
|
|
|
|
|
|
|
|
|
104
|
6
|
|
|
|
|
14
|
my $suffix = $1; |
|
105
|
|
|
|
|
|
|
|
|
106
|
6
|
|
|
|
|
4
|
my $spec; |
|
107
|
6
|
100
|
|
|
|
11
|
if ($ci) { |
|
108
|
5
|
|
|
|
|
7
|
my $suffix_lc = lc($suffix); |
|
109
|
5
|
|
|
|
|
16
|
for (keys %SUFFIXES) { |
|
110
|
14
|
100
|
|
|
|
29
|
if (lc($_) eq $suffix_lc) { |
|
111
|
4
|
|
|
|
|
6
|
$spec = $SUFFIXES{$_}; |
|
112
|
4
|
|
|
|
|
8
|
last; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} else { |
|
116
|
1
|
|
|
|
|
2
|
$spec = $SUFFIXES{$suffix}; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
6
|
100
|
|
|
|
24
|
return 0 unless $spec; |
|
119
|
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
16
|
(my $ufilename = $filename) =~ s/\.\w+\z//; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
return { |
|
123
|
4
|
|
|
|
|
38
|
compressor_name => $spec->{name}, |
|
124
|
|
|
|
|
|
|
compressor_suffix => $suffix, |
|
125
|
|
|
|
|
|
|
uncompressed_filename => $ufilename, |
|
126
|
|
|
|
|
|
|
}; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
|
130
|
|
|
|
|
|
|
# ABSTRACT: Check whether filename indicates being compressed |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |