| 1 | package App::CheckArchiveFilename; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||
| 8 | 1 | our $DATE = '2023-12-15'; # DATE | |||||||||
| 9 | 1 | our $DIST = 'App-CheckArchiveFilename'; # DIST | |||||||||
| 10 | 1 | our $VERSION = '0.008'; # VERSION | |||||||||
| 11 | |||||||||||
| 12 | 1 | our %SPEC; | |||||||||
| 13 | |||||||||||
| 14 | $SPEC{check_archive_filename} = { | ||||||||||
| 15 | 1 | v => 1.1, | |||||||||
| 16 | summary => 'Return information about archive & compressor types from filenames', | ||||||||||
| 17 | args => { | ||||||||||
| 18 | filenames => { | ||||||||||
| 19 | schema => ['array*', of=>'filename*', min_len=>1], | ||||||||||
| 20 | 'x.name.is_plural' => 1, | ||||||||||
| 21 | req => 1, | ||||||||||
| 22 | pos => 0, | ||||||||||
| 23 | greedy => 1, | ||||||||||
| 24 | }, | ||||||||||
| 25 | }, | ||||||||||
| 26 | examples => [ | ||||||||||
| 27 | { | ||||||||||
| 28 | argv => [qw/foo.bar qux.Zip quux.tar.xz/], | ||||||||||
| 29 | }, | ||||||||||
| 30 | ], | ||||||||||
| 31 | }; | ||||||||||
| 32 | 0 | ▶ | sub check_archive_filename { | ||||||||
|
Subroutine
check_archive_filename: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 33 | 0 | require Filename::Archive; | |||||||||
| 34 | 0 | require Filename::Compressed; | |||||||||
| 35 | |||||||||||
| 36 | 0 | my %args = @_; | |||||||||
| 37 | 0 | my $filenames = $args{filenames}; | |||||||||
| 38 | |||||||||||
| 39 | 0 | my @res; | |||||||||
| 40 | 0 | for my $filename (@$filenames) { | |||||||||
| 41 | 0 | my $rec = {filename => $filename}; | |||||||||
| 42 | 0 | my $ares = Filename::Archive::check_archive_filename( | |||||||||
| 43 | filename => $filename); | ||||||||||
| 44 | 0 | ▶ | if ($ares) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | $rec->{is_archive} = 1; | |||||||||
| 46 | 0 | $rec->{archive_name} = $ares->{archive_name}; | |||||||||
| 47 | 0 | $rec->{archive_suffix} = $ares->{archive_suffix}; | |||||||||
| 48 | 0 | $rec->{filename_without_suffix} = $ares->{filename_without_suffix}; | |||||||||
| 49 | 0 | ▶ | if ($ares->{compressor_info}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | $rec->{is_compressed} = 1; | |||||||||
| 51 | # we'll just display the outermost compressor (e.g. compressor | ||||||||||
| 52 | # for file.tar.gz.bz2 is bzip2). this is rare though. | ||||||||||
| 53 | 0 | $rec->{compressor_name} = $ares->{compressor_info}[0]{compressor_name}; | |||||||||
| 54 | 0 | $rec->{compressor_suffix} = $ares->{compressor_info}[0]{compressor_suffix}; | |||||||||
| 55 | } | ||||||||||
| 56 | } else { | ||||||||||
| 57 | 0 | $rec->{is_archive} = 0; | |||||||||
| 58 | 0 | my $cres = Filename::Compressed::check_compressed_filename( | |||||||||
| 59 | filename => $filename); | ||||||||||
| 60 | 0 | ▶ | if ($cres) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $rec->{is_compressed} = 1; | |||||||||
| 62 | 0 | $rec->{compressor_name} = $cres->{compressor_name}; | |||||||||
| 63 | 0 | $rec->{compressor_suffix} = $cres->{compressor_suffix}; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | 0 | push @res, $rec; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 0 | [200, "OK", \@res, { | |||||||||
| 70 | 'table.fields' => [qw/filename is_archive is_compressed | ||||||||||
| 71 | archive_name compressor_name compressor_suffix/], | ||||||||||
| 72 | }]; | ||||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | 1 | 1; | |||||||||
| 76 | # ABSTRACT: Return information about archive & compressor types from filenames | ||||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||