{
    "mode": "perldoc",
    "parameter": "CPAN::Mirrors",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/CPAN%3A%3AMirrors/json",
    "generated": "2026-06-17T13:21:10Z",
    "synopsis": "use CPAN::Mirrors;\nmy $mirrors = CPAN::Mirrors->new( $mirroredbyfile );\nmy $seen = {};\nmy $bestcontinent = $mirrors->findbestcontinents( { seen => $seen } );\nmy @mirrors        = $mirrors->getmirrorsbycontinents( $bestcontinent );\nmy $callback = sub {\nmy( $m ) = @;\nprintf \"%s = %s\\n\", $m->hostname, $m->rtt\n};\n$mirrors->getmirrorstimings( \\@mirrors, $seen, $callback, %args );\n@mirrors = sort { $a->rtt <=> $b->rtt } @mirrors;\nprint \"Best mirrors are \", map( { $->rtt } @mirrors[0..3] ), \"\\n\";",
    "sections": {
        "NAME": {
            "content": "CPAN::Mirrors - Get CPAN mirror information and select a fast one\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use CPAN::Mirrors;\n\nmy $mirrors = CPAN::Mirrors->new( $mirroredbyfile );\n\nmy $seen = {};\n\nmy $bestcontinent = $mirrors->findbestcontinents( { seen => $seen } );\nmy @mirrors        = $mirrors->getmirrorsbycontinents( $bestcontinent );\n\nmy $callback = sub {\nmy( $m ) = @;\nprintf \"%s = %s\\n\", $m->hostname, $m->rtt\n};\n$mirrors->getmirrorstimings( \\@mirrors, $seen, $callback, %args );\n\n@mirrors = sort { $a->rtt <=> $b->rtt } @mirrors;\n\nprint \"Best mirrors are \", map( { $->rtt } @mirrors[0..3] ), \"\\n\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "",
            "subsections": [
                {
                    "name": "new",
                    "content": "Create a new CPAN::Mirrors object from LOCALFILENAME. This file should look like that in\nhttp://www.cpan.org/MIRRORED.BY .\n"
                },
                {
                    "name": "continents",
                    "content": "Return a list of continents based on those defined in MIRRORED.BY.\n"
                },
                {
                    "name": "countries",
                    "content": "Return a list of countries based on those defined in MIRRORED.BY. It only returns countries\nfor the continents you specify (as defined in \"continents\"). If you don't specify any\ncontinents, it returns all of the countries listed in MIRRORED.BY.\n"
                },
                {
                    "name": "mirrors",
                    "content": "Return a list of mirrors based on those defined in MIRRORED.BY. It only returns mirrors for\nthe countries you specify (as defined in \"countries\"). If you don't specify any countries,\nit returns all of the mirrors listed in MIRRORED.BY.\n"
                },
                {
                    "name": "get_mirrors_by_countries",
                    "content": "A more sensible synonym for mirrors.\n"
                },
                {
                    "name": "get_mirrors_by_continents",
                    "content": "Return a list of mirrors for all of continents you specify. If you don't specify any\ncontinents, it returns all of the mirrors.\n\nYou can specify a single continent or an array reference of continents.\n"
                },
                {
                    "name": "get_countries_by_continents",
                    "content": "A more sensible synonym for countries.\n\ndefaultmirror\nReturns the default mirror, http://www.cpan.org/ . This mirror uses dynamic DNS to give a\nclose mirror.\n\nbestmirrors\n\"bestmirrors\" checks for the best mirrors based on the list of continents you pass, or,\nwithout that, all continents, as defined by \"CPAN::Mirrored::By\". It pings each mirror, up\nto the value of \"howmany\". In list context, it returns up to \"howmany\" mirrors. In scalar\ncontext, it returns the single best mirror.\n\nArguments\n\nhowmany      - the number of mirrors to return. Default: 1\ncallback      - a callback for findbestcontinents\nverbose       - true or false on all the whining and moaning. Default: false\ncontinents    - an array ref of the continents to check\nexternalping - if true, use external ping via Net::Ping::External. Default: false\n\nIf you don't specify the continents, \"bestmirrors\" calls \"findbestcontinents\" to get the\nlist of continents to check.\n\nIf you don't have Net::Ping v2.13 or later, needed for timings, this returns the default\nmirror.\n\n\"externalping\" should be set and then \"Net::Ping::External\" needs to be installed, if the\nlocal network has a transparent proxy.\n"
                },
                {
                    "name": "get_n_random_mirrors_by_continents",
                    "content": "Returns up to N random mirrors for the specified continents. Specify the continents as an\narray reference.\n"
                },
                {
                    "name": "get_mirrors_timings",
                    "content": "Pings the listed mirrors and returns a list of mirrors sorted in ascending ping times.\n\n\"MIRRORLIST\" is an anonymous array of \"CPAN::Mirrored::By\" objects to ping.\n\nThe optional argument \"SEEN\" is a hash reference used to track the mirrors you've already\npinged.\n\nThe optional argument \"CALLBACK\" is a subroutine reference to call after each ping. It gets\nthe \"CPAN::Mirrored::By\" object after each ping.\n"
                },
                {
                    "name": "find_best_continents",
                    "content": "\"findbestcontinents\" goes through each continent and pings \"N\" random mirrors on that\ncontinent. It then orders the continents by ascending median ping time. In list context, it\nreturns the ordered list of continent. In scalar context, it returns the same list as an\nanonymous array.\n\nArguments:\n\nn        - the number of hosts to ping for each continent. Default: 3\nseen     - a hashref of cached hostname ping times\nverbose  - true or false for noisy or quiet. Default: false\ncallback - a subroutine to run after each ping.\npingcachelimit - how long, in seconds, to reuse previous ping times.\nDefault: 1 day\n\nThe \"seen\" hash has hostnames as keys and anonymous arrays as values. The anonymous array is\na triplet of a \"CPAN::Mirrored::By\" object, a ping time, and the epoch time for the\nmeasurement.\n\nThe callback subroutine gets the \"CPAN::Mirrored::By\" object, the ping time, and measurement\ntime (the same things in the \"seen\" hashref) as arguments. \"findbestcontinents\" doesn't\ncare what the callback does and ignores the return value.\n\nWith a low value for \"N\", a single mirror might skew the results enough to choose a worse\ncontinent. If you have that problem, try a larger value.\n"
                }
            ]
        },
        "AUTHOR": {
            "content": "Andreas Koenig \"<andk@cpan.org>\", David Golden \"<dagolden@cpan.org>\", brian d foy\n\"<bdfoy@cpan.org>\"\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee <http://www.perl.com/perl/misc/Artistic.html>\n",
            "subsections": []
        }
    },
    "summary": "CPAN::Mirrors - Get CPAN mirror information and select a fast one",
    "flags": [],
    "examples": [],
    "see_also": []
}