Business-BR-Ids
view release on metacpan or search on metacpan
lib/Business/BR/CPF.pm view on Meta::CPAN
hopefully with a uniform distribution and then compute the check digits.
If $valid==0, the check digits are computed B<not to> satisfy the
check equations.
=back
=head2 EXPORT
C<test_cpf> is exported by default. C<canon_cpf>, C<format_cpf>,
C<parse_cpf> and C<random_cpf> can be exported on demand.
=head1 THE CHECK EQUATIONS
A correct CPF number has two check digits which are computed
from the base 9 first digits. Consider the CPF number
written as 11 digits
c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] dv[1] dv[2]
To check whether a CPF is correct or not, it has to satisfy
the check equations:
c[1]*10+c[2]*9+c[3]*8+c[4]*7+c[5]*6+
c[6]*5+c[7]*4+c[8]*3+c[9]*2+dv[1] = 0 (mod 11) or
= 1 (mod 11) (if dv[1]=0)
and
c[2]*10+c[3]*9+c[4]*8+c[5]*7+c[6]*6+
c[7]*5+c[8]*4+c[9]*3+dv[1]*2+dv[2] = 0 (mod 11) or
= 1 (mod 11) (if dv[2]=0)
=head1 BUGS
I heard that there are exceptions of CPF numbers which don't
obey the check equations and are still authentic. I have never found
one of them.
=head1 SEE ALSO
To make sure this module works, one can try the results obtained against
those found with "Comprovante de Inscrição e de Situação Cadastral no CPF",
a web page which the Brazilian Ministry of Revenue provides for public
consultation on regularity status of the taxpayer.
This page tells if the CPF number is a correct entry (11-digits-long with verified
check digits), if it references a real person and if he/she is regular
with the government body.
Given a bad CPF, the after-submit page tells "CPF incorreto".
If the CPF is a good one but does not reference a real person,
it says "CPF não existe em nossa base de dados" (CPF does not exist
in our database). Otherwise, it shows a details form for the identified
taxpayer.
Note that this module only tests correctness.
It doesn't enter the merit whether the CPF number actually exists
at the Brazilian government databases.
As you might have guessed, this is not the first Perl module
to approach this kind of functionality. Take a look at
http://search.cpan.org/search?module=Brasil::Checar::CPF
http://search.cpan.org/search?query=cpf&mode=all
Please reports bugs via CPAN RT,
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-BR-Ids
By doing so, the author will receive your reports and patches,
as well as the problem and solutions will be documented.
=head1 AUTHOR
A. R. Ferreira, E<lt>ferreira@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2005 by A. R. Ferreira
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.6 or,
at your option, any later version of Perl 5 you may have available.
=cut
( run in 1.903 second using v1.01-cache-2.11-cpan-364913b4093 )