CPAN::Mirrors(3perl)
β¨ CPAN::Mirrors β¨
okay bestie, pull up a chair because we're talking about CPAN::Mirrors(3perl) β the little Perl module from the Perl Programmers Reference Guide that goes and gets you CPAN mirror info and picks a fast one for you. it's giving matchmaker but for servers π
πΈ NAME πΈ
CPAN::Mirrors β Get CPAN mirror information and select a fast one πͺβ¨
π SYNOPSIS π
no cap, this is the whole vibe in one go:
use CPAN::Mirrors;
my $mirrors = CPAN::Mirrors->new( $mirrored_by_file );
my $seen = {};
my $best_continent = $mirrors->find_best_continents( { seen => $seen } );
my @mirrors = $mirrors->get_mirrors_by_continents( $best_continent );
my $callback = sub {
my( $m ) = @_;
printf "%s = %s\n", $m->hostname, $m->rtt
};
$mirrors->get_mirrors_timings( \@mirrors, $seen, $callback, %args );
@mirrors = sort { $a->rtt <=> $b->rtt } @mirrors;
print "Best mirrors are ", map( { $_->rtt } @mirrors[0..3] ), "\n";
π DESCRIPTION π
Every method, every argument, zero skips. let's go π«Ά
new( LOCAL_FILE_NAME )
Makes a brand new CPAN::Mirrors object out of LOCAL_FILE_NAME. And that file? It should look exactly like the one at http://www.cpan.org/MIRRORED.BY β that's the blueprint, bestie πβ¨
continents()
Hands you back a list of continents, based on the ones defined in MIRRORED.BY.
countries( [CONTINENTS] )
Returns a list of countries, again based on what's defined in MIRRORED.BY. It will only give you countries for the continents you pass in (using the continents as defined in continents). And if you don't specify any continents at all? Cute, no problem β you get every single country listed in MIRRORED.BY. π
mirrors( [COUNTRIES] )
Returns a list of mirrors based on those defined in MIRRORED.BY. It only gives you mirrors for the countries you specify (as defined in countries). Don't specify any countries? Then it's the whole list of mirrors from MIRRORED.BY, periodt. πͺπ₯
get_mirrors_by_countries( [COUNTRIES] )
A more sensible synonym for mirrors. slay, same energy π
get_mirrors_by_continents( [CONTINENTS] )
Returns a list of mirrors for all the continents you specify. If you don't specify any continents, you get all of the mirrors, no filter, main character energy π
You can pass a single continent, or an array reference of continents. both work, we love flexibility π¦
get_countries_by_continents( [CONTINENTS] )
A more sensible synonym for countries. same method, cuter name π
default_mirror
Returns the default mirror, http://www.cpan.org/ . This mirror uses dynamic DNS to give you a close mirror β it's lowkey doing the most so you don't have to β¨
best_mirrors
best_mirrors checks for the best mirrors based on the list of continents you pass it β or, without that, all continents, as defined by CPAN::Mirrored::By. It pings each mirror, up to the value of how_many. In list context, it returns up to how_many mirrors. In scalar context, it returns the single best mirror. one (1) iconic winner π
Arguments
how_manyβ the number of mirrors to return. Default:1callbackβ a callback forfind_best_continentsverboseβ true or false on all the whining and moaning. Default:falsecontinentsβ an array ref of the continents to checkexternal_pingβ if true, use external ping viaNet::Ping::External. Default:false
If you don't specify the continents, best_mirrors calls find_best_continents to get the list of continents to check. fr fr, it handles it for you π«Ά
If you don't have Net::Ping v2.13 or later, needed for timings, this returns the default mirror. (yep, that's the fallback.)
β οΈexternal_pingshould be set β and thenNet::Ping::Externalneeds to be installed β if the local network has a transparent proxy.
get_n_random_mirrors_by_continents( N, [CONTINENTS] )
Returns up to N random mirrors for the specified continents. Specify the continents as an array reference. chaos but make it useful π²
get_mirrors_timings( MIRROR_LIST, SEEN, CALLBACK, %ARGS );
Pings the listed mirrors and returns a list of mirrors sorted in ascending ping times. fastest first, as she should π
MIRROR_LIST is an anonymous array of CPAN::Mirrored::By objects to ping.
The optional argument SEEN is a hash reference used to track the mirrors you've already pinged. (no duplicate pings here, we're efficient π
)
The optional argument CALLBACK is a subroutine reference to call after each ping. It gets the CPAN::Mirrored::By object after each ping.
find_best_continents( HASH_REF );
find_best_continents goes through each continent and pings N random mirrors on that continent. It then orders the continents by ascending median ping time. In list context, it returns the ordered list of continent. In scalar context, it returns the same list as an anonymous array. π
Arguments:
nβ the number of hosts to ping for each continent. Default:3seenβ a hashref of cached hostname ping timesverboseβ true or false for noisy or quiet. Default:falsecallbackβ a subroutine to run after each ping.ping_cache_limitβ how long, in seconds, to reuse previous ping times. Default:1 day
The seen hash has hostnames as keys and anonymous arrays as values. The anonymous array is a triplet of a CPAN::Mirrored::By object, a ping time, and the epoch time for the measurement. π¦
The callback subroutine gets the CPAN::Mirrored::By object, the ping time, and measurement time (the same things in the seen hashref) as arguments. find_best_continents doesn't care what the callback does and ignores the return value. it's not nosy, it's just supportive π
β οΈ heads up bestie: with a low value for N, a single mirror might skew the results enough to choose a worse continent. If you have that problem, try a larger value. gotta get that sample size up π
π AUTHOR π
Andreas Koenig <andk@cpan.org>, David Golden <dagolden@cpan.org>, brian d foy <bdfoy@cpan.org>
legends, honestly π«Ά
π LICENSE π
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
and that's the whole page, bestie π this one ships with perl v5.44.0, dated 2026-10-17 β so go forth, ping responsibly, and may your mirrors always be fast πβ¨π¦
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms