File Coverage

blib/lib/Filename/Type/Perl/Release.pm
Criterion Covered Total %
statement 20 20 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 30 30 100.0


line stmt bran cond sub pod time code
1             package Filename::Type::Perl::Release;
2              
3 2     2   513627 use 5.010001;
  2         8  
4 2     2   11 use strict;
  2         26  
  2         53  
5 2     2   19 use warnings;
  2         13  
  2         197  
6              
7 2     2   12 use Exporter 'import';
  2         7  
  2         1072  
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2024-12-21'; # DATE
11             our $DIST = 'Filename-Type-Perl-Release'; # DIST
12             our $VERSION = '0.002'; # VERSION
13              
14             our @EXPORT_OK = qw(check_perl_release_filename);
15              
16             our %SPEC;
17              
18             $SPEC{check_perl_release_filename} = {
19             v => 1.1,
20             summary => 'Check whether filename looks like a perl module release archive, e.g. a CPAN release tarball',
21             description => <<'MARKDOWN',
22              
23              
24             MARKDOWN
25             args => {
26             filename => {
27             schema => 'str*',
28             req => 1,
29             pos => 0,
30             },
31             },
32             result_naked => 1,
33             result => {
34             schema => ['any*', of=>['bool*', 'hash*']],
35             description => <<'MARKDOWN',
36              
37             Return false if not detected like a perl module release archive. Otherwise
38             return a hash of information, which contains these keys: `distribution`,
39             `module`, `version`.
40              
41             MARKDOWN
42             },
43             };
44             sub check_perl_release_filename {
45 3     3 1 343135 require Filename::Archive;
46              
47 3         1102 my %args = @_;
48              
49 3         8 my $filename = $args{filename};
50              
51 3         8 my $cares = Filename::Archive::check_archive_filename(filename=>$filename, ci=>1);
52 3 100       1975 return 0 unless $cares;
53              
54             $cares->{filename_without_suffix} =~
55 2 100       18 /\A
56             (\w+(?:-\w+)*)
57             -v?(\d+(?:\.\d+){0,}(_\d+|-TRIAL)?)
58             \z/ix
59             or return 0;
60 1         3 my ($dist, $ver) = ($1, $2);
61 1         5 (my $mod = $dist) =~ s/-/::/g;
62 1         11 {distribution => $dist, module=>$mod, version=>$ver, archive_suffix=>$cares->{archive_suffix}};
63             }
64              
65             1;
66             # ABSTRACT: Check whether filename looks like a perl module release archive, e.g. a CPAN release tarball
67              
68             __END__