Skip to content

Instantly share code, notes, and snippets.

@neilb
Created March 11, 2015 23:30
Show Gist options
  • Select an option

  • Save neilb/98b516b1288c4191f5f4 to your computer and use it in GitHub Desktop.

Select an option

Save neilb/98b516b1288c4191f5f4 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