Zones by Country

EOF

for my $country (
    sort { lc $a->[0] cmp lc $b->[0] }
    map {
        my $country = my_code2country($_);
        warn "no country for $_\n" unless defined $country;
        [ $country, $_ ];
    } grep { $_ ne 'UK' } keys %countries
    ) {

    $zonecatalog .= "=head3 $country->[0] ($country->[1])\n\n";

    for my $zone ( @{ $countries{ $country->[1] } } ) {
        my $line = join ' - ', grep {defined} @{$zone};
        $zonecatalog .= "  $line\n";
    }

    $zonecatalog .= "\n";
}

$zonecatalog .= <<'EOF';
=head2 Linked Zones

A linked zone is an alias from one name to another.

EOF

for my $from ( sort keys %links ) {
    $zonecatalog .= "  $from => $links{$from}\n";
}

$zonecatalog .= "\n";

$zonecatalog .= "=cut\n";

open my $fh, ">lib/DateTime/TimeZone/Catalog.pm" or die $!;
print $fh $zonecatalog or die $!;
close $fh or die $!;
}

sub parse_zone_tab { my $file = File::Spec->catfile( $opts{dir}, 'zone.tab' );

open my $fh, "<$file" or die "Cannot read $file: $!";

my %countries;
while (<$fh>) {
    next if /^\#/;
    chomp;

    my ( $cc, undef, $tz, $desc ) = split /\t+/, $_;

    push @{ $countries{$cc} }, [ $tz, $desc ];
}

return %countries;
}

sub my_code2country { my $code = shift;

return 'South Sudan' if $code eq 'SS';

return code2country($code);
}