Info/FromRepoName.pm

filter: Statementstmt 60.9% 25 / 41 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 100% 1 / 1 totaltotal 55.5% 30 / 54 CC 4 SCAR 22.6
CC
4
Cov
53%
extract_cpan_info_from_repo_name
20.0
_normalize_mod
2.0
BEGIN
1.0
CRAP 9.6
↑ Summary Module/FromRepoName.pm »
1 package CPAN::Info::FromRepoName;
2  
3 5 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 5 our $DATE = '2020-10-02'; # DATE
5 5 our $DIST = 'CPAN-Info-FromRepoName'; # DIST
6 5 our $VERSION = '0.001'; # VERSION
7  
8 5 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 our @EXPORT_OK = qw(extract_cpan_info_from_repo_name);
14  
15 5 our %SPEC;
16  
17 5 our $re_proto_http = qr!(?:https?://)!i;
18 5 our $re_author = qr/(?:\w+)/;
19 5 our $re_dist = qr/(?:\w+(?:-\w+)*)/;
20 5 our $re_mod = qr/(?:\w+(?:::\w+)*)/;
21 5 our $re_version = qr/(?:v?[0-9]+(?:\.[0-9]+)*(?:_[0-9]+|-TRIAL)?)/;
22 5 our $re_end_or_q = qr/(?:[?&#]|\z)/;
23  
24 0 ▶sub _normalize_mod {
Subroutine _normalize_mod: not called CC=1 SCAR=6.9
25 0 my $mod = shift;
26 0 $mod =~ s/'/::/g;
27 0 $mod;
28 }
29  
30 $SPEC{extract_cpan_info_from_repo_name} = {
31 5 v => 1.1,
32 summary => 'Extract/guess information from a repo name',
33 description => <<'_',
34  
35 Guess information from a repo name and return a hash (or undef if nothing can be
36 guessed). Possible keys include `dist` (Perl distribution name).
37  
38 _
39 args => {
40 repo_name => {
41 schema => 'str*',
42 req => 1,
43 pos => 0,
44 },
45 },
46 args_as => 'array',
47 result => {
48 schema => 'hash',
49 },
50 result_naked => 1,
51 examples => [
52 {
53 name => "perl-<dist>",
54 args => {repo_name=>'perl-Foo-Bar'},
55 result => {dist=>"Foo-Bar"},
56 },
57 {
58 name => "p5-<dist>",
59 args => {repo_name=>'perl-Foo-Bar'},
60 result => {dist=>"Foo-Bar"},
61 },
62 {
63 name => "cpan-<dist>",
64 args => {repo_name=>'cpan-Foo-Bar'},
65 result => {dist=>"Foo-Bar"},
66 },
67 {
68 name => "<dist>-perl",
69 args => {repo_name=>'Foo-Bar-perl'},
70 result => {dist=>"Foo-Bar"},
71 },
72 {
73 name => "<dist>-p5",
74 args => {repo_name=>'Foo-Bar-p5'},
75 result => {dist=>"Foo-Bar"},
76 },
77 {
78 name => "<dist>-cpan",
79 args => {repo_name=>'Foo-Bar-cpan'},
80 result => {dist=>"Foo-Bar"},
81 },
82 {
83 name => "<dist>",
84 args => {repo_name=>'CPAN-Foo-Bar'},
85 result => {dist=>"CPAN-Foo-Bar"},
86 },
87 {
88 name => "unknown",
89 args => {repo_name=>'@foo'},
90 result => undef,
91 },
92 ],
93 };
94 0 ▶sub extract_cpan_info_from_repo_name {
Subroutine extract_cpan_info_from_repo_name: not called CC=4 SCAR=30.0
Pod documented
95 0 state $re_modname;
96 0 state $re_distname = do {
97 0 require Regexp::Pattern::Perl::Module;
98 0 $re_modname = $Regexp::Pattern::Perl::Module::RE{perl_modname}{pat};
99  
100 0 require Regexp::Pattern::Perl::Dist;
101 0 $Regexp::Pattern::Perl::Dist::RE{perl_distname}{pat};
102 };
103  
104 0 my $repo_name = shift;
105  
106 0 my $res;
107  
108 0 ▶ if ($repo_name =~ /\A(?:perl|p5|cpan)-($re_distname)\z/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($repo_name =~ /\A(?:perl|p5|cpan)-($re_distname)\z/) { } 0 0 0
elsif ($repo_name =~ /\A($re_distname)-(?:perl|p5|cpan)\z/) { } 0 0 0
elsif ($repo_name =~ /\A($re_distname)\z/) { } 0 0 0
109 0 $res->{dist} = $1;
110 } elsif ($repo_name =~ /\A($re_distname)-(?:perl|p5|cpan)\z/) {
111 0 $res->{dist} = $1;
112 } elsif ($repo_name =~ /\A($re_distname)\z/) {
113 0 $res->{dist} = $1;
114 }
115 0 $res;
116 }
117  
118 5 1;
119 # ABSTRACT: Extract/guess information from a repo name
120  
121 __END__
↑ Summary Module/FromRepoName.pm »