This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update experimental to CPAN version 0.019
[perl5.git] / Porting / make_modlib_cpan.pl
CommitLineData
872fa928
LB
1#!perl
2#
3# This program generates the list of registered CPAN sites in perlmodlib.PL
4#
5use strict;
6use warnings;
7use 5.14.0;
8use autodie;
9use HTTP::Tiny;
9ed2d9d9
CBW
10use JSON::PP;
11
12$|=1;
872fa928
LB
13
14my $http = HTTP::Tiny->new;
15
9ed2d9d9
CBW
16my $url = 'http://www.cpan.org/indices/mirrors.json';
17
18my $response = $http->get($url);
19
872fa928
LB
20unless ( $response->{success} ) {
21 die "Error downloading $url";
22}
23
9ed2d9d9 24die "No content" unless $response->{content};
872fa928 25
9ed2d9d9
CBW
26my $json = JSON::PP->new->utf8;
27my $mirrors = $json->decode( $response->{content} );
28my %sorted;
29my @rsync;
872fa928 30
9ed2d9d9
CBW
31foreach 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;
34 }
35 else {
36 push @{ $sorted{ $mirror->{continent} }{ $mirror->{country} } }, $mirror;
37 }
38}
872fa928
LB
39
40say 'Registered CPAN sites';
41say '';
42say '=for maintainers';
43say 'Generated by Porting/make_modlib_cpan.pl';
44say '';
45
9ed2d9d9
CBW
46foreach my $continent ( sort { $a cmp $b } keys %sorted ) {
47 say "=head2 $continent";
48 say '';
49 say '=over 4';
50 say '';
51 foreach my $country ( sort { $a cmp $b } keys %{ $sorted{ $continent } } ) {
52 say "=item $country";
53 say '';
54 if ( $country eq 'United States' ) {
55 say '=over 8';
56 say '';
57 foreach my $state ( sort { $a cmp $b } keys %{ $sorted{ $continent }{ $country } } ) {
58 say "=item $state";
872fa928 59 say '';
9ed2d9d9
CBW
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};
872fa928 64 }
872fa928 65 say '';
9ed2d9d9
CBW
66 }
67 say '=back';
68 say '';
69 }
70 else {
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};
75 }
76 say '';
872fa928 77 }
9ed2d9d9
CBW
78 }
79 say '=back';
80 say '';
81}
82
83say '=head2 RSYNC Mirrors';
84say '';
85
86foreach my $rsync ( @rsync ) {
87 say "\t\t$rsync";
872fa928
LB
88}
89
90say '';