| 1 | package CPAN::Info::FromURL; | ||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||||||||||||||
| 4 | 5 | our $DATE = '2020-10-02'; # DATE | |||||||||||||||||||||||||||||||||||||||
| 5 | 5 | our $DIST = 'CPAN-Info-FromURL'; # DIST | |||||||||||||||||||||||||||||||||||||||
| 6 | 5 | our $VERSION = '0.092'; # 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_url); | |||||||||||||||||||||||||||||||||||||||
| 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_url} = { | ||||||||||||||||||||||||||||||||||||||||
| 31 | 5 | v => 1.1, | |||||||||||||||||||||||||||||||||||||||
| 32 | summary => 'Extract/guess information from a URL', | ||||||||||||||||||||||||||||||||||||||||
| 33 | description => <<'_', | ||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||
| 35 | Return a hash of information from a CPAN-related URL. Possible keys include: | ||||||||||||||||||||||||||||||||||||||||
| 36 | `site` (site nickname, include: `mcpan` [metacpan.org, api.metacpan.org, | ||||||||||||||||||||||||||||||||||||||||
| 37 | fastapi.metacpan.org], `sco` [search.cpan.org], `cpanratings` | ||||||||||||||||||||||||||||||||||||||||
| 38 | [cpanratings.perl.org], `rt` ([rt.cpan.org]), `cpan` [any normal CPAN mirror]), | ||||||||||||||||||||||||||||||||||||||||
| 39 | `author` (CPAN author ID), `module` (module name), `dist` (distribution name), | ||||||||||||||||||||||||||||||||||||||||
| 40 | `version` (distribution version). Some keys might not exist, depending on what | ||||||||||||||||||||||||||||||||||||||||
| 41 | information the URL provides. Return undef if URL is not detected to be of some | ||||||||||||||||||||||||||||||||||||||||
| 42 | CPAN-related URL. | ||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||
| 44 | _ | ||||||||||||||||||||||||||||||||||||||||
| 45 | args => { | ||||||||||||||||||||||||||||||||||||||||
| 46 | url => { | ||||||||||||||||||||||||||||||||||||||||
| 47 | schema => 'str*', | ||||||||||||||||||||||||||||||||||||||||
| 48 | req => 1, | ||||||||||||||||||||||||||||||||||||||||
| 49 | pos => 0, | ||||||||||||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||||||||||||
| 51 | }, | ||||||||||||||||||||||||||||||||||||||||
| 52 | args_as => 'array', | ||||||||||||||||||||||||||||||||||||||||
| 53 | result => { | ||||||||||||||||||||||||||||||||||||||||
| 54 | schema => 'hash', | ||||||||||||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||||||||||||
| 56 | result_naked => 1, | ||||||||||||||||||||||||||||||||||||||||
| 57 | examples => [ | ||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||||||||||||||
| 60 | name => "mcpan/pod/MOD", | ||||||||||||||||||||||||||||||||||||||||
| 61 | args => {url=>'https://metacpan.org/pod/Foo::Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 62 | result => {site=>'mcpan', module=>'Foo::Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||
| 65 | name => "mcpan/module/MOD", | ||||||||||||||||||||||||||||||||||||||||
| 66 | args => {url=>'metacpan.org/module/Foo?'}, | ||||||||||||||||||||||||||||||||||||||||
| 67 | result => {site=>'mcpan', module=>'Foo'}, | ||||||||||||||||||||||||||||||||||||||||
| 68 | }, | ||||||||||||||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||||||||||||||
| 70 | name => "mcpan/pod/release/AUTHOR/DIST-VERSION/lib/MOD.pm", | ||||||||||||||||||||||||||||||||||||||||
| 71 | args => {url=>'http://metacpan.org/pod/release/SRI/Mojolicious-6.46/lib/Mojo.pm'}, | ||||||||||||||||||||||||||||||||||||||||
| 72 | result => {site=>'mcpan', author=>'SRI', dist=>'Mojolicious', version=>'6.46', module=>'Mojo'}, | ||||||||||||||||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||||
| 75 | name => "mcpan/pod/release/AUTHOR/DIST-VERSION/bin/SCRIPT", | ||||||||||||||||||||||||||||||||||||||||
| 76 | args => {url=>'http://metacpan.org/pod/release/PERLANCAR/App-PMUtils-1.23/bin/pmpath'}, | ||||||||||||||||||||||||||||||||||||||||
| 77 | result => {site=>'mcpan', author=>'PERLANCAR', dist=>'App-PMUtils', version=>'1.23', script=>'pmpath'}, | ||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||
| 80 | name => "mcpan/source/AUTHOR/DIST-VERSION/lib/MOD.pm", | ||||||||||||||||||||||||||||||||||||||||
| 81 | args => {url=>'http://metacpan.org/source/SRI/Mojolicious-6.46/lib/Mojo.pm?'}, | ||||||||||||||||||||||||||||||||||||||||
| 82 | result => {site=>'mcpan', author=>'SRI', dist=>'Mojolicious', version=>'6.46', module=>'Mojo'}, | ||||||||||||||||||||||||||||||||||||||||
| 83 | }, | ||||||||||||||||||||||||||||||||||||||||
| 84 | { | ||||||||||||||||||||||||||||||||||||||||
| 85 | name => "api.mcpan/source/AUTHOR/DIST-VERSION", | ||||||||||||||||||||||||||||||||||||||||
| 86 | args => {url=>'http://api.metacpan.org/source/SRI/Mojolicious-6.46?'}, | ||||||||||||||||||||||||||||||||||||||||
| 87 | result => {site=>'mcpan', author=>'SRI', dist=>'Mojolicious', version=>'6.46'}, | ||||||||||||||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||||||||||||||
| 89 | { | ||||||||||||||||||||||||||||||||||||||||
| 90 | name => "fastapi.mcpan/v1/module/MODULE", | ||||||||||||||||||||||||||||||||||||||||
| 91 | args => {url=>'http://fastapi.metacpan.org/v1/module/Moose'}, | ||||||||||||||||||||||||||||||||||||||||
| 92 | result => {site=>'mcpan', module=>'Moose'}, | ||||||||||||||||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||
| 95 | name => 'mcpan/release/DIST', | ||||||||||||||||||||||||||||||||||||||||
| 96 | args => {url=>'https://metacpan.org/release/Foo-Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 97 | result => {site=>'mcpan', dist=>'Foo-Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 98 | }, | ||||||||||||||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||||||||||||||
| 100 | name => 'mcpan/release/AUTHOR/DIST-VERSION', | ||||||||||||||||||||||||||||||||||||||||
| 101 | args => {url=>'https://metacpan.org/release/FOO/Bar-1.23'}, | ||||||||||||||||||||||||||||||||||||||||
| 102 | result => {site=>'mcpan', author=>'FOO', dist=>'Bar', version=>'1.23'}, | ||||||||||||||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||||||||||||||
| 105 | name => 'mcpan/author/AUTHOR', | ||||||||||||||||||||||||||||||||||||||||
| 106 | args => {url=>'https://metacpan.org/author/FOO'}, | ||||||||||||||||||||||||||||||||||||||||
| 107 | result => {site=>'mcpan', author=>'FOO'}, | ||||||||||||||||||||||||||||||||||||||||
| 108 | }, | ||||||||||||||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||||||||||||||
| 110 | name => 'mcpan/changes/distribution/DIST', | ||||||||||||||||||||||||||||||||||||||||
| 111 | args => {url=>'https://metacpan.org/changes/distribution/Module-XSOrPP'}, | ||||||||||||||||||||||||||||||||||||||||
| 112 | result => {site=>'mcpan', dist=>'Module-XSOrPP'}, | ||||||||||||||||||||||||||||||||||||||||
| 113 | }, | ||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||
| 115 | name => 'mcpan/requires/distribution/DIST', | ||||||||||||||||||||||||||||||||||||||||
| 116 | args => {url=>'https://metacpan.org/requires/distribution/Module-XSOrPP?sort=[[2,1]]'}, | ||||||||||||||||||||||||||||||||||||||||
| 117 | result => {site=>'mcpan', dist=>'Module-XSOrPP'}, | ||||||||||||||||||||||||||||||||||||||||
| 118 | }, | ||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||
| 121 | name => 'sco/dist/DIST', | ||||||||||||||||||||||||||||||||||||||||
| 122 | args => {url=>'http://search.cpan.org/dist/Foo-Bar/'}, | ||||||||||||||||||||||||||||||||||||||||
| 123 | result => {site=>'sco', dist=>'Foo-Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 124 | }, | ||||||||||||||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||||||||||||||
| 126 | name => 'sco/perldoc?MOD', | ||||||||||||||||||||||||||||||||||||||||
| 127 | args => {url=>'http://search.cpan.org/perldoc?Foo::Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 128 | result => {site=>'sco', module=>'Foo::Bar'}, | ||||||||||||||||||||||||||||||||||||||||
| 129 | }, | ||||||||||||||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||||||||||||||
| 131 | name => 'sco/search?mode=module&query=MOD', | ||||||||||||||||||||||||||||||||||||||||
| 132 | args => {url=>'http://search.cpan.org/search?mode=module&query=DBIx%3A%3AClass'}, | ||||||||||||||||||||||||||||||||||||||||
| 133 | result => {site=>'sco', module=>'DBIx::Class'}, | ||||||||||||||||||||||||||||||||||||||||
| 134 | }, | ||||||||||||||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||||||||||||||
| 136 | name => 'sco/search?module=MOD', | ||||||||||||||||||||||||||||||||||||||||
| 137 | args => {url=>'http://search.cpan.org/search?module=ToolSet'}, | ||||||||||||||||||||||||||||||||||||||||
| 138 | result => {site=>'sco', module=>'ToolSet'}, | ||||||||||||||||||||||||||||||||||||||||
| 139 | }, | ||||||||||||||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||||||||||||
| 141 | name => 'sco/search?module=MOD (#2)', | ||||||||||||||||||||||||||||||||||||||||
| 142 | args => {url=>'http://search.cpan.org/search?module=Acme::Don\'t'}, | ||||||||||||||||||||||||||||||||||||||||
| 143 | result => {site=>'sco', module=>'Acme::Don::t'}, | ||||||||||||||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||
| 146 | name => 'sco/~AUTHOR', | ||||||||||||||||||||||||||||||||||||||||
| 147 | args => {url=>'http://search.cpan.org/~unera?'}, | ||||||||||||||||||||||||||||||||||||||||
| 148 | result => {site=>'sco', author=>'unera'}, | ||||||||||||||||||||||||||||||||||||||||
| 149 | }, | ||||||||||||||||||||||||||||||||||||||||
| 150 | { | ||||||||||||||||||||||||||||||||||||||||
| 151 | name => 'sco/~AUTHOR/DIST-REL/lib/MOD.pm', | ||||||||||||||||||||||||||||||||||||||||
| 152 | args => {url=>'http://search.cpan.org/~unera/DR-SunDown-0.02/lib/DR/SunDown.pm'}, | ||||||||||||||||||||||||||||||||||||||||
| 153 | result => {site=>'sco', author=>'unera', dist=>'DR-SunDown', version=>'0.02', module=>'DR::SunDown'}, | ||||||||||||||||||||||||||||||||||||||||
| 154 | }, | ||||||||||||||||||||||||||||||||||||||||
| 155 | { | ||||||||||||||||||||||||||||||||||||||||
| 156 | name => 'sco/~AUTHOR/DIST-REL/bin/SCRIPT.pm', | ||||||||||||||||||||||||||||||||||||||||
| 157 | args => {url=>'http://search.cpan.org/~perlancar/App-PMUtils-1.23/bin/pmpath'}, | ||||||||||||||||||||||||||||||||||||||||
| 158 | result => {site=>'sco', author=>'perlancar', dist=>'App-PMUtils', version=>'1.23', script=>'pmpath'}, | ||||||||||||||||||||||||||||||||||||||||
| 159 | }, | ||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||
| 161 | { | ||||||||||||||||||||||||||||||||||||||||
| 162 | name => 'cpan/authors/id/A/AU/AUTHOR', | ||||||||||||||||||||||||||||||||||||||||
| 163 | args => {url=>'file:/cpan/authors/id/A/AU/AUTHOR?'}, | ||||||||||||||||||||||||||||||||||||||||
| 164 | result => {site=>'cpan', author=>'AUTHOR'}, | ||||||||||||||||||||||||||||||||||||||||
| 165 | }, | ||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||
| 167 | name => 'cpan/authors/id/A/AU/AUTHOR/DIST-VERSION.tar.gz', | ||||||||||||||||||||||||||||||||||||||||
| 168 | args => {url=>'file:/cpan/authors/id/A/AU/AUTHOR/Foo-Bar-1.0.tar.gz'}, | ||||||||||||||||||||||||||||||||||||||||
| 169 | result => {site=>'cpan', author=>'AUTHOR', release=>'Foo-Bar-1.0.tar.gz', dist=>'Foo-Bar', version=>'1.0'}, | ||||||||||||||||||||||||||||||||||||||||
| 170 | }, | ||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||||||||||||||
| 173 | name => 'cpanratings/dist/DIST', | ||||||||||||||||||||||||||||||||||||||||
| 174 | args => {url=>'http://cpanratings.perl.org/dist/Submodules'}, | ||||||||||||||||||||||||||||||||||||||||
| 175 | result => {site=>'cpanratings', dist=>'Submodules'}, | ||||||||||||||||||||||||||||||||||||||||
| 176 | }, | ||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||
| 179 | name => 'perldoc.perl.org/MOD/SUBMOD.html', | ||||||||||||||||||||||||||||||||||||||||
| 180 | args => {url=>'http://perldoc.perl.org/Module/CoreList.html'}, | ||||||||||||||||||||||||||||||||||||||||
| 181 | result => {site=>'perldoc.perl.org', module=>'Module::CoreList'}, | ||||||||||||||||||||||||||||||||||||||||
| 182 | }, | ||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||
| 185 | name => 'rt/(Public/)Dist/Display.html?Queue=DIST', | ||||||||||||||||||||||||||||||||||||||||
| 186 | args => {url=>'https://rt.cpan.org/Dist/Display.html?Queue=Perinci-Sub-Gen-AccessTable-DBI'}, | ||||||||||||||||||||||||||||||||||||||||
| 187 | result => {site=>'rt', dist=>'Perinci-Sub-Gen-AccessTable-DBI'}, | ||||||||||||||||||||||||||||||||||||||||
| 188 | }, | ||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||
| 190 | { | ||||||||||||||||||||||||||||||||||||||||
| 191 | name => "mojo", | ||||||||||||||||||||||||||||||||||||||||
| 192 | args => {url=>'https://mojolicious.org/perldoc/Mojo/DOM/CSS'}, | ||||||||||||||||||||||||||||||||||||||||
| 193 | result => {site=>'mojo', module=>'Mojo::DOM::CSS'}, | ||||||||||||||||||||||||||||||||||||||||
| 194 | }, | ||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||||||||
| 197 | name => "anchor in url", | ||||||||||||||||||||||||||||||||||||||||
| 198 | args => {url=>'https://mojolicious.org/perldoc/Mojo/DOM/CSS#Foo'}, | ||||||||||||||||||||||||||||||||||||||||
| 199 | result => {site=>'mojo', module=>'Mojo::DOM::CSS'}, | ||||||||||||||||||||||||||||||||||||||||
| 200 | }, | ||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||
| 202 | { | ||||||||||||||||||||||||||||||||||||||||
| 203 | name => "github (https, .git)", | ||||||||||||||||||||||||||||||||||||||||
| 204 | args => {url=>'https://github.com/perlancar/perl-CPAN-Info-FromURL.git'}, | ||||||||||||||||||||||||||||||||||||||||
| 205 | result => {site=>'github', github_user=>"perlancar", github_repo=>"perl-CPAN-Info-FromURL", dist=>'CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 206 | }, | ||||||||||||||||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||||||||||||||
| 208 | name => "github (https, no .git)", | ||||||||||||||||||||||||||||||||||||||||
| 209 | args => {url=>'https://github.com/perlancar/perl-CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 210 | result => {site=>'github', github_user=>"perlancar", github_repo=>"perl-CPAN-Info-FromURL", dist=>'CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 211 | }, | ||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||
| 213 | name => "github (git)", | ||||||||||||||||||||||||||||||||||||||||
| 214 | args => {url=>'git@github.com:perlancar/perl-CPAN-Info-FromURL.git'}, | ||||||||||||||||||||||||||||||||||||||||
| 215 | result => {site=>'github', github_user=>"perlancar", github_repo=>"perl-CPAN-Info-FromURL", dist=>'CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 216 | }, | ||||||||||||||||||||||||||||||||||||||||
| 217 | { | ||||||||||||||||||||||||||||||||||||||||
| 218 | name => "github (git)", | ||||||||||||||||||||||||||||||||||||||||
| 219 | args => {url=>'git://github.com/perlancar/perl-CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 220 | result => {site=>'github', github_user=>"perlancar", github_repo=>"perl-CPAN-Info-FromURL", dist=>'CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 221 | }, | ||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||
| 224 | name => "gitlab (https, .git)", | ||||||||||||||||||||||||||||||||||||||||
| 225 | args => {url=>'https://gitlab.com/perlancar/perl-CPAN-Info-FromURL.git'}, | ||||||||||||||||||||||||||||||||||||||||
| 226 | result => {site=>'gitlab', github_user=>"perlancar", github_repo=>"perl-CPAN-Info-FromURL", dist=>'CPAN-Info-FromURL'}, | ||||||||||||||||||||||||||||||||||||||||
| 227 | }, | ||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||
| 230 | name => 'unknown', | ||||||||||||||||||||||||||||||||||||||||
| 231 | args => {url=>'https://www.google.com/'}, | ||||||||||||||||||||||||||||||||||||||||
| 232 | result => undef, | ||||||||||||||||||||||||||||||||||||||||
| 233 | }, | ||||||||||||||||||||||||||||||||||||||||
| 234 | ], | ||||||||||||||||||||||||||||||||||||||||
| 235 | }; | ||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | sub extract_cpan_info_from_url { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_cpan_info_from_url: not called CC=39 SCAR=73.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $url = shift; | |||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||
| 241 | # metacpan | ||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | if ($url =~ s!\A$re_proto_http?(?:fastapi\.|api\.)?metacpan\.org/?(?:v\d/)?!!i) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $res->{site} = 'mcpan'; | |||||||||||||||||||||||||||||||||||||||
| 245 | # note: /module is the old URL. /pod might misreport a script as a | ||||||||||||||||||||||||||||||||||||||||
| 246 | # module, e.g. metacpan.org/pod/cpanm. | ||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ($url =~ m!\A(?:pod|module)/ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||
| 248 | ($re_mod)(?:[?&#]|\z)!x) { | ||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | $res->{module} = $1; | |||||||||||||||||||||||||||||||||||||||
| 250 | } elsif ($url =~ s!\A(?:pod/release/|source/) | ||||||||||||||||||||||||||||||||||||||||
| 251 | ($re_author)/($re_dist)-($re_version)/?!!x) { | ||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $res->{author} = $1; | |||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $res->{dist} = $2; | |||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $res->{version} = $3; | |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | if ($url =~ m!\Alib/((?:[^/]+/)*\w+)\.(?:pm|pod)!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $res->{module} = $1; $res->{module} =~ s!/!::!g; | |||||||||||||||||||||||||||||||||||||||
| 257 | } elsif ($url =~ m!\A(?:bin|scripts?)/ | ||||||||||||||||||||||||||||||||||||||||
| 258 | (?:[^/]+/)* | ||||||||||||||||||||||||||||||||||||||||
| 259 | (.+?) | ||||||||||||||||||||||||||||||||||||||||
| 260 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $res->{script} = $1; | |||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||
| 263 | } elsif ($url =~ m!\A(?:pod/release/|source/) | ||||||||||||||||||||||||||||||||||||||||
| 264 | ($re_author)/($re_dist)-($re_version)/? | ||||||||||||||||||||||||||||||||||||||||
| 265 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $res->{author} = $1; | |||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $res->{dist} = $2; | |||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $res->{version} = $3; | |||||||||||||||||||||||||||||||||||||||
| 269 | } elsif ($url =~ m!\Arelease/ | ||||||||||||||||||||||||||||||||||||||||
| 270 | ($re_dist)/? | ||||||||||||||||||||||||||||||||||||||||
| 271 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $res->{dist} = $1; | |||||||||||||||||||||||||||||||||||||||
| 273 | } elsif ($url =~ m!\Arelease/ | ||||||||||||||||||||||||||||||||||||||||
| 274 | ($re_author)/($re_dist)-($re_version)/? | ||||||||||||||||||||||||||||||||||||||||
| 275 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $res->{author} = $1; | |||||||||||||||||||||||||||||||||||||||
| 277 | 0 | $res->{dist} = $2; | |||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $res->{version} = $3; | |||||||||||||||||||||||||||||||||||||||
| 279 | } elsif ($url =~ m!\A(?:changes|requires)/distribution/ | ||||||||||||||||||||||||||||||||||||||||
| 280 | ($re_dist)/? | ||||||||||||||||||||||||||||||||||||||||
| 281 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $res->{dist} = $1; | |||||||||||||||||||||||||||||||||||||||
| 283 | } elsif ($url =~ m!\Aauthor/ | ||||||||||||||||||||||||||||||||||||||||
| 284 | ($re_author)/? | ||||||||||||||||||||||||||||||||||||||||
| 285 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $res->{author} = $1; | |||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||
| 289 | } elsif ($url =~ s!\A$re_proto_http?search\.cpan\.org/?!!i) { | ||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $res->{site} = 'sco'; | |||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ($url =~ m!\Adist/ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||
| 293 | ($re_dist)/? | ||||||||||||||||||||||||||||||||||||||||
| 294 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $res->{dist} = $1; | |||||||||||||||||||||||||||||||||||||||
| 296 | } elsif ($url =~ m!\Aperldoc\? | ||||||||||||||||||||||||||||||||||||||||
| 297 | (.+?) | ||||||||||||||||||||||||||||||||||||||||
| 298 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $res->{module} = URI::Escape::uri_unescape($1); | |||||||||||||||||||||||||||||||||||||||
| 301 | } elsif ($url =~ m!\Asearch\?!) { | ||||||||||||||||||||||||||||||||||||||||
| 302 | # used by perlmonks.org | ||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | ▶ | if ($url =~ m![?&#]mode=module(?:&|\z)! && $ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$url =~ /[?&#]mode=module(?:&|\z)/ and $url =~ /[?&#]query=(.+?)(?:&|\z)/
MC/DC0%0/2
$url =~ /[?&#]mode=module(?:&|\z)/ and $url =~ /[?&#]query=(.+?)(?:&|\z)/
$url =~ /[?&#]mode=module(?:&|\z)/
$url =~ /[?&#]query=(.+?)(?:&|\z)/
Truth table0%0/3
A and B
A= $url =~ /[?&#]mode=module(?:&|\z)/B= $url =~ /[?&#]query=(.+?)(?:&|\z)/
| |||||||||||||||||||||||||||||||||||||||||
| 304 | url =~ m![?&#]query=(.+?)(?:&|\z)!) { | ||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $res->{module} = _normalize_mod(URI::Escape::uri_unescape($1)); | |||||||||||||||||||||||||||||||||||||||
| 307 | ▶ | } elsif ($url =~ m![?&#]mode=dist(?:&|\z)! && $ | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$url =~ /[?&#]mode=dist(?:&|\z)/ and $url =~ /[?&]query=(.+?)(?:&|\z)/
MC/DC0%0/2
$url =~ /[?&#]mode=dist(?:&|\z)/ and $url =~ /[?&]query=(.+?)(?:&|\z)/
$url =~ /[?&#]mode=dist(?:&|\z)/
$url =~ /[?&]query=(.+?)(?:&|\z)/
Truth table0%0/3
A and B
A= $url =~ /[?&#]mode=dist(?:&|\z)/B= $url =~ /[?&]query=(.+?)(?:&|\z)/
| |||||||||||||||||||||||||||||||||||||||||
| 308 | url =~ m![?&]query=(.+?)(?:&|\z)!) { | ||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $res->{dist} = URI::Escape::uri_unescape($1); | |||||||||||||||||||||||||||||||||||||||
| 311 | ▶ | } elsif ($url =~ m![?&#]mode=author(?:&|\z)! && $ | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$url =~ /[?&#]mode=author(?:&|\z)/ and $url =~ /[?&#]query=(.+?)(?:&|\z)/
MC/DC0%0/2
$url =~ /[?&#]mode=author(?:&|\z)/ and $url =~ /[?&#]query=(.+?)(?:&|\z)/
$url =~ /[?&#]mode=author(?:&|\z)/
$url =~ /[?&#]query=(.+?)(?:&|\z)/
Truth table0%0/3
A and B
A= $url =~ /[?&#]mode=author(?:&|\z)/B= $url =~ /[?&#]query=(.+?)(?:&|\z)/
| |||||||||||||||||||||||||||||||||||||||||
| 312 | url =~ m![?&#]query=(.+?)(?:&|\z)!) { | ||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $res->{author} = URI::Escape::uri_unescape($1); | |||||||||||||||||||||||||||||||||||||||
| 315 | # used by some articles | ||||||||||||||||||||||||||||||||||||||||
| 316 | } elsif ($url =~ m![?&#]module=(.+?)(?:&|\z)!) { | ||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||
| 318 | 0 | $res->{module} = _normalize_mod(URI::Escape::uri_unescape($1)); | |||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||
| 320 | } elsif ($url =~ s!\A~(\w+)/?!!) { | ||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | $res->{author} = $1; | |||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | if ($url =~ s!($re_dist)-($re_version)/?!!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $res->{dist} = $1; | |||||||||||||||||||||||||||||||||||||||
| 324 | 0 | $res->{version} = $2; | |||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ($url =~ m!\Alib/((?:[^/]+/)*\w+)\.(?:pm|pod)!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | $res->{module} = $1; $res->{module} =~ s!/!::!g; | |||||||||||||||||||||||||||||||||||||||
| 327 | } elsif ($url =~ m!\A(?:bin|scripts?)/ | ||||||||||||||||||||||||||||||||||||||||
| 328 | (?:[^/]+/)* | ||||||||||||||||||||||||||||||||||||||||
| 329 | (.+?) | ||||||||||||||||||||||||||||||||||||||||
| 330 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $res->{script} = $1; | |||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||
| 336 | } elsif ($url =~ s!\A$re_proto_http?cpanratings\.perl\.org/?!!i) { | ||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $res->{site} = 'cpanratings'; | |||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ($url =~ m!\Adist/ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 340 | ($re_dist)/? | ||||||||||||||||||||||||||||||||||||||||
| 341 | $re_end_or_q!x) { | ||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $res->{dist} = $1; | |||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||
| 345 | } elsif ($url =~ s!\A$re_proto_http?perldoc\.perl\.org/?!!i) { | ||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | $res->{site} = 'perldoc.perl.org'; | |||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | if ($url =~ m!^(\w+(?:/\w+)*)\.html!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | my $mod = $1; | |||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $mod =~ s!/!::!g; | |||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $res->{module} = $mod; | |||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||
| 354 | } elsif ($url =~ s!\A$re_proto_http?rt\.cpan\.org/?!!i) { | ||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $res->{site} = 'rt'; | |||||||||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | if ($url =~ m!\A(?:Public/)?Dist/Display\.html!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ($url =~ m=(.+?)(?:&|#|\z)!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | require URI::Escape; | |||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $res->{dist} = URI::Escape::uri_unescape($1); | |||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||
| 364 | } elsif ($url =~ s!\A$re_proto_http?mojolicious\.org/?!!i) { | ||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $res->{site} = 'mojo'; | |||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if ($url =~ m!\Aperldoc/([^?&#]+)!) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | my $mod = $1; | |||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $mod =~ s!/!::!g; | |||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $res->{module} = $mod; | |||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||
| 373 | } elsif ($url =~ m!\A(?:$re_proto_http|\w+\@|git://)?(gitlab|github)\.com[:/]([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)(\.git|\z|/)!i) { | ||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $res->{site} = $1; | |||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $res->{github_user} = $2; | |||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $res->{github_repo} = $3; | |||||||||||||||||||||||||||||||||||||||
| 377 | 0 | require CPAN::Dist::FromRepoName; | |||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $dist = CPAN::Dist::FromRepoName::extract_cpan_dist_from_repo_name($3); | |||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ▶ | $res->{dist} = $dist if defined $dist; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 380 | } elsif ($url =~ m!/authors/id/(\w)/\1(\w)/(\1\2\w+) | ||||||||||||||||||||||||||||||||||||||||
| 381 | (?:/ | ||||||||||||||||||||||||||||||||||||||||
| 382 | (?:[^/]+/)* # subdir | ||||||||||||||||||||||||||||||||||||||||
| 383 | (($re_dist)-($re_version)\.(?:tar\.\w+|tar|zip|tgz|tbz|tbz2)) | ||||||||||||||||||||||||||||||||||||||||
| 384 | )? | ||||||||||||||||||||||||||||||||||||||||
| 385 | $re_end_or_q!ix) { | ||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $res->{site} = 'cpan'; | |||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $res->{author} = $3; | |||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if (defined $4) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $res->{release} = $4; | |||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $res->{dist} = $5; | |||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $res->{version} = $6; | |||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $res; | |||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||
| 397 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||
| 398 | # ABSTRACT: Extract/guess information from a URL | ||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||
| 400 | __END__ | ||||||||||||||||||||||||||||||||||||||||