#!/usr/bin/env perl
# ABSTRACT: Returns city data for a given CEP
# PODNAME: cep2city


use strict;
use utf8;
use warnings qw(all);

use open qw(:locale);

our $VERSION = '0.6'; # VERSION

use Geo::CEP;
use Pod::Usage;

pod2usage(
    -exitval    => 0,
    -verbose    => 99,
) unless @ARGV;

my $gc = Geo::CEP->new;

for my $cep (@ARGV) {
    $cep =~ s/\D//gx;
    if ($cep && (my $r = $gc->find($cep))) {
        $r->{cep} = $cep;
        printf "%-10s\t%s\n", $_, $r->{$_} for sort keys %{$r};
        print "\n";
    } else {
        printf STDERR "'%s' not found!\n", $cep;
    }
}

__END__

=pod

=encoding utf8

=head1 NAME

cep2city - Returns city data for a given CEP

=head1 VERSION

version 0.6

=head1 SYNOPSIS

cep2city CEP [ CEP2 CEP3 ... ]

=head1 DESCRIPTION

Prints available details for a given CEP number:

    $ cep2city.pl 12420-010
    cep       	12420010
    city      	Pindamonhangaba
    ddd       	12
    lat       	-22.9166667
    lon       	-45.4666667
    state     	SP
    state_long	São Paulo

=head1 SEE ALSO

=over 4

=item *

L<Geo::CEP>

=item *

L<WWW::Correios::CEP>

=back

=head1 AUTHOR

Stanislaw Pusep <stas@sysd.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Stanislaw Pusep.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
