Skip to content

Instantly share code, notes, and snippets.

@mishin
Forked from neilb/cpan-repository-hosts.pl
Last active August 29, 2015 14:17
Show Gist options
  • Save mishin/7ec77d934029a2ac5a36 to your computer and use it in GitHub Desktop.
Save mishin/7ec77d934029a2ac5a36 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
#
# cpan-repository-hosts
#
# Generate list of the different hosts that appear in the CPAN repository field
# Get a list of all the repository strings from MetaCPAN, then chop them around
# to get the host part
#
use strict;
use warnings;
use MetaCPAN::Client;
my $client = MetaCPAN::Client->new();
my $query = { all => [
{ status => 'latest' },
{ 'resources.repository.url' => '*' }
]};
my $params = { fields => [qw/ resources /] };
my $result_set = $client->release($query, $params);
my %count;
while (my $release = $result_set->next ) {
my $repo = $release->resources->{repository}{url};
next unless defined($repo) && $repo =~ m!^([^:]+)://(.*?)/!;
(my $host = $2) =~ s!.*@!!;
$host =~ s!:.*$!!;
$count{$host}++;
}
my $index = 1;
foreach my $host (sort { $count{$b} <=> $count{$a} } keys %count) {
printf "%3d) %5d %s\n", $index++, $count{$host}, $host;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment