Business-BR-RG

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

                $rg = random_rg(1); # also a correct RG
                $bad_rg = random_rg(0); # an incorrect RG

        Generates a random RG. If $valid is omitted or 1, it is guaranteed
        to be *correct*. If $valid is 0, it is guaranteed to be *incorrect*.
        This function is intented for mass test. (Use it wisely.)

        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 not to
        satisfy the check equations.

  EXPORT
    "test_rg" is exported by default. "canon_rg", "format_rg", "parse_rg"
    and "random_rg" can be exported on demand.

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

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)

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.

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.

    <http://github.com/renatocron/>

    You may be interested too in validation of CPF/CNPJ. So you can look at:

    Business::BR::CNPJ

    Business::BR::CPF

    You should too make a search about the Business::BR namespace.

SUPPORT
  Perldoc
    You can find documentation for this module with the perldoc command (to
    read this)

            perldoc Business\:\:BR\:\:RG

  Github
    If you want to contribute with the code, you can fork this module on
    github:

    <https://github.com/renatocron/Business--BR--RG>

    You can even report a issue.

AUTHOR
    Renato CRON, <rentocron@cpan.org>

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.

AUTHOR
    Renato CRON <rentocron@cpan.org>

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
    the same terms as the Perl 5 programming language system itself.



( run in 5.543 seconds using v1.01-cache-2.11-cpan-63c85eba8c4 )