The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl

use strict;
use warnings;

use CPAN::Mirrors;
use Data::Dumper;

my $mirrored_by_file = '/Users/brian/.cpan/sources/MIRRORED.BY';
my $mirrors = CPAN::Mirrors->new( $mirrored_by_file );

my $seen = {};
my $n = 5;

my $best_continent = $mirrors->find_best_continents( n => $n, seen => $seen, verbose => 1 );
print "Best continent is $best_continent\n";

my @mirrors = $mirrors->get_mirrors_by_continents( $best_continent );

my $callback = sub { 
	my( $m ) = @_; 
	printf "%s = %s ms\n", $m->hostname, 1000 * $m->rtt
	};
my @sorted_mirrors = $mirrors->get_mirrors_timings( \@mirrors, $seen, $callback );

print "Best mirrors are ",
	join ' ', map( $_->hostname, @sorted_mirrors[0..$n-1] ),
	"\n";

print "Best urls are\n\t",
	join( "\n\t", map( $_->http, @sorted_mirrors[0..$n-1] ) ),
	"\n";