diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-27 20:34:36 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-27 20:34:36 -0300 |
| commit | f2f3e5b5b22f5db49670391fb747a52fd492b9db (patch) | |
| tree | 3d02d13f3111bdd7381470d3fd3db1f58e00bc8c /lib/Cepis.pm | |
| parent | 0bc578d6d334c7f1ccaf329cd61bb8bce76b7f59 (diff) | |
| download | perl-main.tar.gz | |
A CEP that fails is rarely a random number. It is usually someone who knows
the city and guessed the digits, and the classic guess is the -000 that 957
municipalities never received. The API now answers those 404s with a faixa
block naming the municipality that owns the band, so the library can say
"25845000 does not exist in Areal/RJ" instead of "not found".
It stays an error: lookup still throws Cepis::Error::CEPNotFound, and the
faixa hangs off the exception rather than turning a miss into an address.
Parsing it is deliberately forgiving — a missing, empty or malformed block
yields undef, because losing the clean not-found to a parse failure would be
a worse outcome than losing the context.
cep_ini and cep_fim are the smallest and largest CEP that actually exist,
not the bounds the Correios publish, and the interval between them is
sparse. That is why ceps is exposed alongside them and why the docs say
twice that the pair is not a list of valid CEPs.
Diffstat (limited to 'lib/Cepis.pm')
| -rw-r--r-- | lib/Cepis.pm | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/Cepis.pm b/lib/Cepis.pm index 224d80d..1ea5b00 100644 --- a/lib/Cepis.pm +++ b/lib/Cepis.pm @@ -8,10 +8,11 @@ use Exporter 5.57 qw(import); use Cepis::Address; use Cepis::Client; use Cepis::Error; +use Cepis::Faixa; use Cepis::Geo; use Cepis::Health; -our $VERSION = '0.1.0'; +our $VERSION = '0.2.0'; our @EXPORT_OK = qw(lookup lookup_many health normalize_cep); @@ -101,6 +102,18 @@ the lot, and the split below it is by whether retrying helps: } } +A C<CEPNotFound> often knows B<where> the CEP would have been. When the API says +so, C<< $err->faixa >> is a L<Cepis::Faixa> naming the municipality that owns +that band, and the message names it too: + + # "CEP 25845000 does not exist in the DNE database (it would fall in Areal/RJ)" + +It is still a failure — C<faixa> is context for the error, never an address — +and it is C<undef> when the CEP fell in a band no municipality owns. It is worth +checking because a failing CEP is rarely random: it is usually someone who knows +the city and guessed the number, and the classic guess is the C<-000> that 957 +municipalities never received. + =head2 Field names The API surface is English, but the B<data fields keep the API's own Portuguese @@ -169,7 +182,7 @@ The L<Cepis::Client> behind the functions above, built on first use. =head1 SEE ALSO L<Cepis::Client>, L<Cepis::Address>, L<Cepis::Geo>, L<Cepis::Health>, -L<Cepis::Error> +L<Cepis::Error>, L<Cepis::Faixa> The API itself is documented at L<https://cep.is>. |