1CPAN::Mirrors(3pm) Perl Programmers Reference Guide CPAN::Mirrors(3pm)
2
3
4
6 CPAN::Mirrors - Get CPAN miror information and select a fast one
7
9 use CPAN::Mirrors;
10
11 my $mirrors = CPAN::Mirrors->new;
12 $mirrors->parse_from_file( $mirrored_by_file );
13
14 my $seen = {};
15
16 my $best_continent = $mirrors->find_best_continents( { seen => $seen } );
17 my @mirrors = $mirrors->get_mirrors_by_continents( $best_continent );
18
19 my $callback = sub {
20 my( $m ) = @_;
21 printf "%s = %s\n", $m->hostname, $m->rtt
22 };
23 $mirrors->get_mirrors_timings( \@mirrors, $seen, $callback );
24
25 @mirrors = sort { $a->rtt <=> $b->rtt } @mirrors;
26
27 print "Best mirrors are ", map( { $_->rtt } @mirrors[0..3] ), "\n";
28
30 new( LOCAL_FILE_NAME )
31 continents()
32 Return a list of continents based on those defined in MIRRORED.BY.
33
34 countries( [CONTINENTS] )
35 Return a list of countries based on those defined in MIRRORED.BY.
36 It only returns countries for the continents you specify (as
37 defined in "continents"). If you don't specify any continents, it
38 returns all of the countries listed in MIRRORED.BY.
39
40 mirrors( [COUNTRIES] )
41 Return a list of mirrors based on those defined in MIRRORED.BY. It
42 only returns mirrors for the countries you specify (as defined in
43 "countries"). If you don't specify any countries, it returns all of
44 the mirrors listed in MIRRORED.BY.
45
46 get_mirrors_by_countries( [COUNTRIES] )
47 A more sensible synonym for mirrors.
48
49 get_mirrors_by_continents( [CONTINENTS] )
50 Return a list of mirrors for all of continents you specify. If you
51 don't specify any continents, it returns all of the mirrors.
52
53 get_countries_by_continents( [CONTINENTS] )
54 A more sensible synonym for countries.
55
56 best_mirrors
57 "best_mirrors" checks for the best mirrors based on the list of
58 continents you pass, or, without that, all continents, as defined
59 by "CPAN::Mirrored::By". It pings each mirror, up to the value of
60 "how_many". In list context, it returns up to "how_many" mirror.
61 In scalar context, it returns the single best mirror.
62
63 Arguments
64
65 how_many - the number of mirrors to return. Default: 1
66 callback - a callback for find_best_continents
67 verbose - true or false on all the whining and moaning. Default: false
68 continents - an array ref of the continents to check
69
70 If you don't specify the continents, "best_mirrors" calls
71 "find_best_continents" to get the list of continents to check.
72
73 get_n_random_mirrors_by_continents( N, [CONTINENTS]
74 Returns up to N random mirrors for the specified continents.
75 Specify the continents as an array reference.
76
77 get_mirrors_timings( MIRROR_LIST, SEEN, CALLBACK );
78 Pings the listed mirrors and returns a list of mirrors sorted in
79 ascending ping times.
80
81 find_best_continents( HASH_REF );
82 "find_best_continents" goes through each continent and pings "N"
83 random mirrors on that continent. It then orders the continents by
84 ascending median ping time. In list context, it returns the ordered
85 list of continent. In scalar context, it returns the same list as
86 an anonymous array.
87
88 Arguments:
89
90 n - the number of hosts to ping for each continent. Default: 3
91 seen - a hashref of cached hostname ping times
92 verbose - true or false for noisy or quiet. Default: false
93 callback - a subroutine to run after each ping.
94 ping_cache_limit - how long, in seconds, to reuse previous ping times.
95 Default: 1 day
96
97 The "seen" hash has hostnames as keys and anonymous arrays as
98 values. The anonymous array is a triplet of a "CPAN::Mirrored::By"
99 object, a ping time, and the epoch time for the measurement.
100
101 The callback subroutine gets the "CPAN::Mirrored::By" object, the
102 ping time, and measurement time (the same things in the "seen"
103 hashref) as arguments. "find_best_continents" doesn't care what
104 the callback does and ignores the return value.
105
107 Andreas Koenig "<andk@cpan.org>", David Golden "<dagolden@cpan.org>",
108 brian d foy "<bdfoy@cpan.org>"
109
111 This program is free software; you can redistribute it and/or modify it
112 under the same terms as Perl itself.
113
114 See <http://www.perl.com/perl/misc/Artistic.html>
115
116
117
118perl v5.16.3 2013-03-04 CPAN::Mirrors(3pm)