1CPAN::Mirrors(3) User Contributed Perl Documentation CPAN::Mirrors(3)
2
3
4
6 CPAN::Mirrors - Get CPAN mirror information and select a fast one
7
9 use CPAN::Mirrors;
10
11 my $mirrors = CPAN::Mirrors->new( $mirrored_by_file );
12
13 my $seen = {};
14
15 my $best_continent = $mirrors->find_best_continents( { seen => $seen } );
16 my @mirrors = $mirrors->get_mirrors_by_continents( $best_continent );
17
18 my $callback = sub {
19 my( $m ) = @_;
20 printf "%s = %s\n", $m->hostname, $m->rtt
21 };
22 $mirrors->get_mirrors_timings( \@mirrors, $seen, $callback, %args );
23
24 @mirrors = sort { $a->rtt <=> $b->rtt } @mirrors;
25
26 print "Best mirrors are ", map( { $_->rtt } @mirrors[0..3] ), "\n";
27
29 new( LOCAL_FILE_NAME )
30 Create a new CPAN::Mirrors object from LOCAL_FILE_NAME. This file
31 should look like that in http://www.cpan.org/MIRRORED.BY .
32
33 continents()
34 Return a list of continents based on those defined in MIRRORED.BY.
35
36 countries( [CONTINENTS] )
37 Return a list of countries based on those defined in MIRRORED.BY.
38 It only returns countries for the continents you specify (as
39 defined in "continents"). If you don't specify any continents, it
40 returns all of the countries listed in MIRRORED.BY.
41
42 mirrors( [COUNTRIES] )
43 Return a list of mirrors based on those defined in MIRRORED.BY. It
44 only returns mirrors for the countries you specify (as defined in
45 "countries"). If you don't specify any countries, it returns all of
46 the mirrors listed in MIRRORED.BY.
47
48 get_mirrors_by_countries( [COUNTRIES] )
49 A more sensible synonym for mirrors.
50
51 get_mirrors_by_continents( [CONTINENTS] )
52 Return a list of mirrors for all of continents you specify. If you
53 don't specify any continents, it returns all of the mirrors.
54
55 You can specify a single continent or an array reference of
56 continents.
57
58 get_countries_by_continents( [CONTINENTS] )
59 A more sensible synonym for countries.
60
61 default_mirror
62 Returns the default mirror, http://www.cpan.org/ . This mirror uses
63 dynamic DNS to give a close mirror.
64
65 best_mirrors
66 "best_mirrors" checks for the best mirrors based on the list of
67 continents you pass, or, without that, all continents, as defined
68 by "CPAN::Mirrored::By". It pings each mirror, up to the value of
69 "how_many". In list context, it returns up to "how_many" mirrors.
70 In scalar context, it returns the single best mirror.
71
72 Arguments
73
74 how_many - the number of mirrors to return. Default: 1
75 callback - a callback for find_best_continents
76 verbose - true or false on all the whining and moaning. Default: false
77 continents - an array ref of the continents to check
78 external_ping - if true, use external ping via Net::Ping::External. Default: false
79
80 If you don't specify the continents, "best_mirrors" calls
81 "find_best_continents" to get the list of continents to check.
82
83 If you don't have Net::Ping v2.13 or later, needed for timings,
84 this returns the default mirror.
85
86 "external_ping" should be set and then "Net::Ping::External" needs
87 to be installed, if the local network has a transparent proxy.
88
89 get_n_random_mirrors_by_continents( N, [CONTINENTS] )
90 Returns up to N random mirrors for the specified continents.
91 Specify the continents as an array reference.
92
93 get_mirrors_timings( MIRROR_LIST, SEEN, CALLBACK, %ARGS );
94 Pings the listed mirrors and returns a list of mirrors sorted in
95 ascending ping times.
96
97 "MIRROR_LIST" is an anonymous array of "CPAN::Mirrored::By" objects
98 to ping.
99
100 The optional argument "SEEN" is a hash reference used to track the
101 mirrors you've already pinged.
102
103 The optional argument "CALLBACK" is a subroutine reference to call
104 after each ping. It gets the "CPAN::Mirrored::By" object after each
105 ping.
106
107 find_best_continents( HASH_REF );
108 "find_best_continents" goes through each continent and pings "N"
109 random mirrors on that continent. It then orders the continents by
110 ascending median ping time. In list context, it returns the ordered
111 list of continent. In scalar context, it returns the same list as
112 an anonymous array.
113
114 Arguments:
115
116 n - the number of hosts to ping for each continent. Default: 3
117 seen - a hashref of cached hostname ping times
118 verbose - true or false for noisy or quiet. Default: false
119 callback - a subroutine to run after each ping.
120 ping_cache_limit - how long, in seconds, to reuse previous ping times.
121 Default: 1 day
122
123 The "seen" hash has hostnames as keys and anonymous arrays as
124 values. The anonymous array is a triplet of a "CPAN::Mirrored::By"
125 object, a ping time, and the epoch time for the measurement.
126
127 The callback subroutine gets the "CPAN::Mirrored::By" object, the
128 ping time, and measurement time (the same things in the "seen"
129 hashref) as arguments. "find_best_continents" doesn't care what the
130 callback does and ignores the return value.
131
132 With a low value for "N", a single mirror might skew the results
133 enough to choose a worse continent. If you have that problem, try a
134 larger value.
135
137 Andreas Koenig "<andk@cpan.org>", David Golden "<dagolden@cpan.org>",
138 brian d foy "<bdfoy@cpan.org>"
139
141 This program is free software; you can redistribute it and/or modify it
142 under the same terms as Perl itself.
143
144 See <http://www.perl.com/perl/misc/Artistic.html>
145
146
147
148perl v5.34.0 2021-07-22 CPAN::Mirrors(3)