File Coverage

blib/lib/Filename/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::Perl::Release;
2              
3 2     2   476887 use 5.010001;
  2         8  
4 2     2   12 use strict;
  2         3  
  2         60  
5 2     2   10 use warnings;
  2         4  
  2         134  
6              
7 2     2   11 use Exporter 'import';
  2         4  
  2         1058  
8              
9             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
10             our $DATE = '2023-12-16'; # DATE
11             our $DIST = 'Filename-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             examples => [
44             {
45             args => {filename=>'foo.bar'},
46             },
47             {
48             args => {filename=>'qux-quux-0.123.tar.gz'},
49             },
50             ],
51             };
52             sub check_perl_release_filename {
53 3     3 1 441847 require Filename::Archive;
54              
55 3         772 my %args = @_;
56              
57 3         4 my $filename = $args{filename};
58              
59 3         8 my $cares = Filename::Archive::check_archive_filename(filename=>$filename, ci=>1);
60 3 100       1374 return 0 unless $cares;
61              
62             $cares->{filename_without_suffix} =~
63 2 100       15 /\A
64             (\w+(?:-\w+)*)
65             -v?(\d+(?:\.\d+){0,}(_\d+|-TRIAL)?)
66             \z/ix
67             or return 0;
68 1         3 my ($dist, $ver) = ($1, $2);
69 1         4 (my $mod = $dist) =~ s/-/::/g;
70 1         10 {distribution => $dist, module=>$mod, version=>$ver, archive_suffix=>$cares->{archive_suffix}};
71             }
72              
73             1;
74             # ABSTRACT: Check whether filename looks like a perl module release archive, e.g. a CPAN release tarball
75              
76             __END__