3 # This program generates the list of registered CPAN sites in perlmodlib.PL
14 my $http = HTTP::Tiny->new;
16 my $url = 'http://www.cpan.org/indices/mirrors.json';
18 my $response = $http->get($url);
20 unless ( $response->{success} ) {
21 die "Error downloading $url";
24 die "No content" unless $response->{content};
26 my $json = JSON::PP->new->utf8;
27 my $mirrors = $json->decode( $response->{content} );
31 foreach my $mirror ( sort { $a->{continent} cmp $b->{continent} || $a->{country} cmp $b->{country} } @{ $mirrors } ) {
32 if ( $mirror->{country} eq 'United States' ) {
33 push @{ $sorted{ $mirror->{continent} }{ $mirror->{country} }{ $mirror->{region} } }, $mirror;
36 push @{ $sorted{ $mirror->{continent} }{ $mirror->{country} } }, $mirror;
40 say 'Registered CPAN sites';
42 say '=for maintainers';
43 say 'Generated by Porting/make_modlib_cpan.pl';
46 foreach my $continent ( sort { $a cmp $b } keys %sorted ) {
47 say "=head2 $continent";
51 foreach my $country ( sort { $a cmp $b } keys %{ $sorted{ $continent } } ) {
54 if ( $country eq 'United States' ) {
57 foreach my $state ( sort { $a cmp $b } keys %{ $sorted{ $continent }{ $country } } ) {
60 foreach my $mirror ( @{ $sorted{ $continent }{ $country }{ $state } } ) {
61 say " " . $mirror->{http} if $mirror->{http};
62 say " " . $mirror->{ftp} if $mirror->{ftp};
63 push @rsync, $mirror->{rsync} if $mirror->{rsync};
71 foreach my $mirror ( @{ $sorted{ $continent }{ $country } } ) {
72 say " " . $mirror->{http} if $mirror->{http};
73 say " " . $mirror->{ftp} if $mirror->{ftp};
74 push @rsync, $mirror->{rsync} if $mirror->{rsync};
83 say '=head2 RSYNC Mirrors';
86 foreach my $rsync ( @rsync ) {