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

eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'   ## no critic
    if 0;                                   # not running under some shell


use common::sense;
use open ':locale';
use strict;

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

our $VERSION = '1.0';

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

my $gc = new Geo::CEP;

for my $cep (@ARGV) {
    $cep =~ s/\D//g;
    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.2

=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) 2011 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

