CPAN::Mirrors(3pm)
okay so this is CPAN::Mirrors(3pm) straight out of the Perl Programmers Reference Guide, and yes bestie it's giving "official documentation but make it make sense" energy π
π NAME π
CPAN::Mirrors β Get CPAN mirror information and select a fast one. literally that's the whole job. it gets mirror info and picks a speedy one. iconic of it honestly β¨
π¦ SYNOPSIS π¦
here's the whole vibe start to finish, no notes:
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";
like... look at her go π«Ά
β¨ DESCRIPTION β¨
π new( LOCAL_FILE_NAME )
Makes you a brand new CPAN::Mirrors object out of LOCAL_FILE_NAME. that file should look exactly like the one at http://www.cpan.org/MIRRORED.BY β that's the blueprint, don't deviate, mwah π
π continents()
Returns a list of continents, based on the ones defined in MIRRORED.BY. simple. clean. no cap.
π countries( [CONTINENTS] )
Returns a list of countries, based on the ones defined in MIRRORED.BY. she only gives you countries for the continents you actually specify (as defined in "continents"). and if you don't specify any continents? she returns all the countries listed in MIRRORED.BY. generous queen πΈ
π mirrors( [COUNTRIES] )
Returns a list of mirrors based on the ones defined in MIRRORED.BY. only returns mirrors for the countries you specify (as defined in "countries"). if you don't specify any countries, you get all the mirrors listed in MIRRORED.BY. the whole buffet. π₯
π get_mirrors_by_countries( [COUNTRIES] )
A more sensible synonym for mirrors. that's it, that's the whole thing. she said "let me name this properly" π
π get_mirrors_by_continents( [CONTINENTS] )
Returns a list of mirrors for all of the continents you specify. if you don't specify any continents, she returns all of the mirrors. all of them. every last one. π
You can specify a single continent or an array reference of continents β either works, she's flexible like that.
π get_countries_by_continents( [CONTINENTS] )
A more sensible synonym for countries. again: better name, same energy. π
π default_mirror
Returns the default mirror, http://www.cpan.org/. this mirror uses dynamic DNS to give you a close mirror, which is lowkey genius of it.
π best_mirrors
"best_mirrors" checks for the best mirrors based on the list of continents you pass β or, if you don't pass any, 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. main character energy only π
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. she's not gonna guess, she's gonna go find out π§
β οΈ If you don't have Net::Ping v2.13 or later β which is what timings need β this returns the default mirror. so like, no fancy ping for you, you get the standard one. π
β οΈ"external_ping"should be set, and then"Net::Ping::External"needs to be installed, if the local network has a transparent proxy. don't skip this, fr fr π
π get_n_random_mirrors_by_continents( N, [CONTINENTS] )
Returns up to N random mirrors for the specified continents. you specify the continents as an array reference. random but make it continental π²
π 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, obviously, we're not waiting around π¨
"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. so you don't double-ping, we're not doing that here. - 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. then she 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. same data, different outfit π
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. that anonymous array is a triplet of a "CPAN::Mirrored::By" object, a ping time, and the epoch time for the measurement. trio! π
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. she is unbothered, moisturized, in her lane π
π«Ά 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. like, don't let one weird mirror ruin the whole selection, ok?
π AUTHOR π
Andreas Koenig "<andk@cpan.org>", David Golden "<dagolden@cpan.org>", brian d foy "<bdfoy@cpan.org>" β the trio behind the whole thing. 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> β go read it, it's the receipts. π
and that's the page!! this was perl v5.42.3, dated 2026-11-03, living in the Perl Programmers Reference Guide β ty for coming to my TED talk, ily, go pick a fast mirror ππ¦β¨
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms