1CPAN::Mirrors(3)      User Contributed Perl Documentation     CPAN::Mirrors(3)
2
3
4

NAME

6       CPAN::Mirrors - Get CPAN mirror information and select a fast one
7

SYNOPSIS

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 );
23
24           @mirrors = sort { $a->rtt <=> $b->rtt } @mirrors;
25
26           print "Best mirrors are ", map( { $_->rtt } @mirrors[0..3] ), "\n";
27

DESCRIPTION

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" mirror.
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
79           If you don't specify the continents, "best_mirrors" calls
80           "find_best_continents" to get the list of continents to check.
81
82           If you don't have Net::Ping v2.13 or later, needed for timings,
83           this returns the default mirror.
84
85       get_n_random_mirrors_by_continents( N, [CONTINENTS] )
86           Returns up to N random mirrors for the specified continents.
87           Specify the continents as an array reference.
88
89       get_mirrors_timings( MIRROR_LIST, SEEN, CALLBACK );
90           Pings the listed mirrors and returns a list of mirrors sorted in
91           ascending ping times.
92
93           "MIRROR_LIST" is an anonymous array of "CPAN::Mirrored::By" objects
94           to ping.
95
96           The optional argument "SEEN" is a hash reference used to track the
97           mirrors you've already pinged.
98
99           The optional argument "CALLBACK" is a subroutine reference to call
100           after each ping. It gets the "CPAN::Mirrored::By" object after each
101           ping.
102
103       find_best_continents( HASH_REF );
104           "find_best_continents" goes through each continent and pings "N"
105           random mirrors on that continent. It then orders the continents by
106           ascending median ping time. In list context, it returns the ordered
107           list of continent. In scalar context, it returns the same list as
108           an anonymous array.
109
110           Arguments:
111
112               n        - the number of hosts to ping for each continent. Default: 3
113               seen     - a hashref of cached hostname ping times
114               verbose  - true or false for noisy or quiet. Default: false
115               callback - a subroutine to run after each ping.
116               ping_cache_limit - how long, in seconds, to reuse previous ping times.
117                   Default: 1 day
118
119           The "seen" hash has hostnames as keys and anonymous arrays as
120           values.  The anonymous array is a triplet of a "CPAN::Mirrored::By"
121           object, a ping time, and the epoch time for the measurement.
122
123           The callback subroutine gets the "CPAN::Mirrored::By" object, the
124           ping time, and measurement time (the same things in the "seen"
125           hashref) as arguments. "find_best_continents" doesn't care what the
126           callback does and ignores the return value.
127
128           With a low value for "N", a single mirror might skew the results
129           enough to choose a worse continent. If you have that problem, try a
130           larger value.
131

AUTHOR

133       Andreas Koenig "<andk@cpan.org>", David Golden "<dagolden@cpan.org>",
134       brian d foy "<bdfoy@cpan.org>"
135

LICENSE

137       This program is free software; you can redistribute it and/or modify it
138       under the same terms as Perl itself.
139
140       See <http://www.perl.com/perl/misc/Artistic.html>
141
142
143
144perl v5.26.3                      2019-05-14                  CPAN::Mirrors(3)
Impressum