Business-BR-RG
view release on metacpan or search on metacpan
lib/Business/BR/RG.pm view on Meta::CPAN
The implementation is simple: just generate a 8-digits random number,
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_rg> is exported by default. C<canon_rg>, C<format_rg>,
C<parse_rg> and C<random_rg> can be exported on demand.
=head1 NAME
Business::BR::RG - Perl module to test for correct RG numbers
ABSTRACT:
use Business::BR::RG;
print "ok " if test_rg('390.533.447-05'); # prints 'ok '
print "bad " unless test_rg('231.002.999-00'); # prints 'bad '
using all methods
use Business::BR::RG qw /canon_rg test_rg random_rg format_rg parse_rg/;
test_rg('48.391.390-x') # 1
canon_rg('11.456.789-x') # '11456789X'
test_rg('48.190.390-X') # 0
test_rg('48.190') # undef
format_rg('48.19.0.3.9.0.X') # '48.190.390-X'
my ($base, $dv) = parse_rg('48.19.0.3.9.0.X');
print $base # '48190390'
print $dv # 'X'
my $hashref = parse_rg('48.19.0.3.9.0.X');
print $hashref->{base} . '-' . $hashref->{dv}; # 48190390-X
=head1 THE CHECK EQUATIONS
A correct RG number has one check digit which are computed
from the base 8 first digits. Consider the RG number
written as 9 digits
c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] dv[1]
To check whether a RG is correct or not, it has to satisfy
the check equations:
c[1]*2 + c[2]*3 + c[3]*4 + c[4]*5 + c[5]*6 + c[6]*7 + c[7]*8 + c[8]*9 +
dv[9] * 100 = 0 (mod 11)
=head1 BUGS
until now I do not found any RG that has less than 8 digits.
But, I guess, old people still have it.
For now, this is the only way that I found to check RG.
If you found any bug, feel free to send e-mail, open an issue on github or open a RT.
=head1 SEE ALSO
Note that this module only tests correctness.
It doesn't enter the merit whether the RG number actually exists
at the Brazilian government databases.
Please reports bugs via CPAN RT or github.
L<http://github.com/renatocron/>
You may be interested too in validation of CPF/CNPJ. So you can look at:
L<Business::BR::CNPJ>
L<Business::BR::CPF>
You should too make a search about the L<Business::BR> namespace.
=head1 SUPPORT
=head2 Perldoc
You can find documentation for this module with the perldoc command (to read this)
perldoc Business\:\:BR\:\:RG
=head2 Github
If you want to contribute with the code, you can fork this module on github:
L<https://github.com/renatocron/Business--BR--RG>
You can even report a issue.
=head1 AUTHOR
Renato CRON, E<lt>rentocron@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 by Renato CRON
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.1 or,
at your option, any later version of Perl 5 you may have available.
=cut
=head1 AUTHOR
Renato CRON <rentocron@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Renato CRON.
This is free software; you can redistribute it and/or modify it under
( run in 3.747 seconds using v1.01-cache-2.11-cpan-364913b4093 )