Business-BR-Ids-0.0022/0000755000175000017500000000000011032441002014551 5ustar ferreiraferreiraBusiness-BR-Ids-0.0022/README0000644000175000017500000000514010713621552015450 0ustar ferreiraferreiraBusiness-BR-Ids version 0.00_21 =============================== The intention of this distribution is to provide facilities to deal with Brazilian identification numbers and codes. It is part of a set of distributions to approach programming on Brazilian business-related subjects. The distribution is starting up with support to CPF and CNPJ (tests for correctness, canonicalization, formatting, parsing, random generation for mass tests). More is to come. The actually supported codes follow along with a brief explanation of what they are good for and who emits them. * CPF - to identify citizens as taxpayers in nation-wide context, emitted by the Brazilian Ministry of Revenue * CNPJ - to identify companies as taxpayers in nation-wide context, emitted by the Brazilian Ministry of Revenue * PIS - to identify citizens as users of the public health services * IE/AC IE/AL IE/AP IE/AM IE/BA IE/MA IE/MG IE/PR IE/RO IE/RR IE/SP - to identify companies as taxpayers in state-wide context, emitted by Revenue Secretariats of Brazilian States (by now supporting only the states of Acre, Alagoas, Amapá, Maranhão, Minas Gerais, Rondônia, Roraima, São Paulo and Paraná) Some of the next ones to be supported are: * IE - to identify companies as taxpayers in state-wide contexts, emitted by the Secretariat of Revenue of each state * TE - to identify citizens as allowed voters, emitted by Regional Electoral Courts under the control of the Superior Electoral Court INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES Scalar::Util 1.11 Test::More TO DO * write tests for module Business::BR::CNPJ * introduce Business::BR::TE * write article 'br-docs.pod' * get rid of Business::BR::Biz * random_cnpj() calls for a better pseudo-random distribution when selecting variation in Business::BR::CNPJ * introduce the $canon argument to test_*(), format_*(), parse_*() methods * write tests for module Business::BR::Ids * what about Business::BR::Passport? * complete Business::BR::IE * enhance Business::BR::Ids docs * parse_ie_sp() is missing * document Business::BR::PIS * 0.01 milestone: complete code for IE of each Brazilian state COPYRIGHT AND LICENCE Copyright (C) 2005-2007 by A. R. Ferreira This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Business-BR-Ids-0.0022/t/0000755000175000017500000000000011032441002015014 5ustar ferreiraferreiraBusiness-BR-Ids-0.0022/t/001_dot.t0000644000175000017500000000165410713621552016374 0ustar ferreiraferreira use lib qw(t/lib); use IO::Capture qw(open_s close_s); use Test::More tests => 8; BEGIN { use_ok('Business::BR::Ids::Common', '_dot') }; my @a = (1,1,1,1); my @b = (1,1,1,1); is(_dot(\@a, \@b), 4, "_dot works"); my @c = (1,undef,1,1); is(_dot(\@a, \@c), 3, "untrue's are discarded"); # the following tests are expected to emit warnings. # To test this, the STDERR is captured and checked to be non-empty my @d = (1,1,1,1,1); { local *STDERR; open_s *STDERR; is(_dot(\@a, \@d), 4, "_dot works for \@a < \@b"); my $stderr = close_s *STDERR; ok($stderr, "but it does complain"); } my @e = (1,1,1); { local *STDERR; open_s(*STDERR); is(_dot(\@a, \@e), 3, "_dot works for \@a > \@b"); my $stderr = close_s *STDERR; ok($stderr, "but it does complain"); } { my @a = (1,2,3,3); my @b = (2,5,2,6); is( _dot( \@a, \@b ), 36, "the synopsis example works"); } Business-BR-Ids-0.0022/t/009_cnpj_rand.t0000644000175000017500000000072010713621552017545 0ustar ferreiraferreira use constant N => 100; use Test::More tests => 1+2*N; BEGIN { use_ok('Business::BR::CNPJ', 'random_cnpj', 'test_cnpj') }; # the seed is set so that the test is reproducible srand(161803398874989); for ( my $i=0; $i= 5.008 # because it uses in-core files my $memory; sub open_s8 { my $glob = shift; $memory = ''; open $glob, ">", \$memory or die $!; } sub close_s8 { my $glob = shift; close $glob or die $!; return $memory; } # this works anywhere # but is uses a temp file my $tmp_fn = 't/0.tmp'; sub slurp_tmp { local $/; open TMP, $tmp_fn or die $!; my $tmp = ; close TMP or die $!; return $tmp } sub open_s6 { my $glob = shift; open $glob, ">$tmp_fn" or die; } sub close_s6 { my $glob = shift; close $glob or die $!; my $memory = slurp_tmp; unlink $tmp_fn or die $!; return $memory } 1; __END__ =head1 NAME IO::Capture - Capture the output sent to a glob =head1 SYNOPSIS use IO::Capture qw(open_s close_s); local *STDOUT; # localize STDOUT open_s *STDOUT; # print to STDOUT: output is saved my $out = close_s *STDOUT; # and returned here =head1 DESCRIPTION This is a very fragile code. This is for testing warnings to STDERR in "t/001_dot.t". Business-BR-Ids-0.0022/t/002_cpf_test.t0000644000175000017500000000143110713621552017407 0ustar ferreiraferreira use Test::More; my (@valid_cpf, @invalid_cpf); BEGIN { @valid_cpf = ( '56451416010', '78625488250', '390.533.447-05', '88427734336', '16595458977', '100.000.000-19', ' 263. 946. 533 - 3 0 ', '#333%444*2.3+2-23', '099.998.112-99', 99_998_112_99, ); @invalid_cpf = ( '', '1', '888111999000', '231.002.999-00', '271.222.111-11', '999.221.222-00', '00001100017', '999.444.333-55', '72000088855', ' 779.288.222-55 ', '#333%444*2a3s2z~23', ); } BEGIN { plan tests => 1 + @valid_cpf + @invalid_cpf; } BEGIN { use_ok('Business::BR::CPF') }; for (@valid_cpf) { ok(test_cpf($_), "'$_' is correct"); } for (@invalid_cpf) { ok(!test_cpf($_), "'$_' is incorrect"); } Business-BR-Ids-0.0022/t/015_pis_test.t0000644000175000017500000000071710713621552017444 0ustar ferreiraferreira use Test::More; my @valid_pis; my @invalid_pis; BEGIN { @valid_pis = ( '121.51144.13-7', '12151144137', ); @invalid_pis = ( '', '1', '121.51144.13-0', ); } BEGIN { plan tests => 1 + @valid_pis + @invalid_pis; } BEGIN { use_ok('Business::BR::PIS') }; for (@valid_pis) { ok(test_pis($_), "'$_' is correct"); } for (@invalid_pis) { ok(!test_pis($_), "'$_' is incorrect"); } Business-BR-Ids-0.0022/t/016_pis_rand.t0000644000175000017500000000070110713621552017403 0ustar ferreiraferreira use constant N => 100; use Test::More tests => 1+2*N; BEGIN { use_ok('Business::BR::PIS', 'random_pis', 'test_pis') }; # the seed is set so that the test is reproducible srand(271828182845905); for ( my $i=0; $i 14; BEGIN { use_ok('Business::BR::IE', 'parse_ie') }; my ($base, $dv); my $info; ($base, $dv) = parse_ie('ac', "01.004.823/001-12"); is($base, '01004823001', 'parsing IE/AC works (list context)...'); is($dv, '12', 'parsing IE/AC works (indeed)'); $info = parse_ie('ac', "01.004.823/001-12"); is_deeply($info, { base => '01004823001', dv => '12' }, 'parsing IE/AC works (scalar context)'); $info = parse_ie('al', "11.122.333-9"); is_deeply($info, { base => '11122333', dv => '9', type => 1, t_name => 'normal' }, 'parsing IE/AL works (scalar context)'); $info = parse_ie('am', "11.111.111-0"); is_deeply($info, { base => '11111111', dv => '0' }, 'parsing IE/AM works'); $info = parse_ie('ba', "123456-63"); is_deeply($info, { base => '123456', dv => '63' }, 'parsing IE/BA works'); $info = parse_ie('ma', "00.111.222-9"); is_deeply($info, { base => '00111222', dv => '9' }, 'parsing IE/MA works'); is_deeply( scalar parse_ie('mg', '062.307.904/0081'), { municipio => '062', inscricao => '307904', ordem => '00', dv => '81' }, 'parsing IE/MG works' ); $info = parse_ie('ro', "7268466176825-6"); is_deeply($info, { base => '7268466176825', dv => '6' }, 'parsing IE/RO works'); $info = parse_ie('rr', "24004145-5"); is_deeply($info, { base => '24004145', dv => '5' }, 'parsing IE/RR works'); ($base, $dv) = parse_ie('pr', "123.45678-50"); is($base, '12345678', 'parsing IE/PR works (list context)...'); is($dv, '50', 'parsing IE/PR works (indeed)'); $info = parse_ie('pr', "123.45678-50"); is_deeply($info, { base => '12345678', dv => '50' }, 'parsing IE/PR works (scalar context)'); # SP ? Business-BR-Ids-0.0022/t/013_ie_rand.t0000644000175000017500000000123510713621552017205 0ustar ferreiraferreira use constant N => 100; use constant STATES => [ qw(AC AL AP AM BA MA MG RO RR SP PR) ]; # by now #use constant STATES => [ qw(BA) ]; use constant N_STATES => 0+@{+STATES}; use Test::More tests => 1+2*N*N_STATES; BEGIN { use_ok('Business::BR::IE', 'random_ie', 'test_ie') }; # the seed is set so that the test is reproducible srand(161803398874989); for my $s (@{+STATES}) { for ( my $i=0; $i 3; BEGIN { use_ok('Business::BR::Ids::Common', '_dot_10') }; { my @a = (1,1,1,1); my @b = (1,1,1,1); is(_dot_10(\@a, \@b), 4, "_dot_10 works"); } { my @a = (1,2,3,3); my @b = (2,5,2,6); is(_dot_10(\@a, \@b), 18, "_dot_10 works"); } Business-BR-Ids-0.0022/t/010_ie_canon.t0000644000175000017500000000230310713621552017351 0ustar ferreiraferreira use Test::More tests => 15; BEGIN { use_ok('Business::BR::IE', 'canon_ie') }; is(canon_ie('ac', '00 000 000 000 99'), '0000000000099', 'discards formatting and extras'); is(canon_ie('al', '00:000:000:9'), '000000009', 'canon for IE/AL ok'); is(canon_ie('ap', '03.012.345-9'), '030123459', 'canon for IE/AP ok'); is(canon_ie('ap', '11.111.111-0'), '111111110', 'canon for IE/AM ok'); is( canon_ie('ba', '123345-63'), '12334563', 'canon for IE/BA ok' ); is(canon_ie('ma', '11 222 333 4'), '112223334', 'canon for IE/MA ok'); is ( canon_ie('mg', '062.307.904/0081'), '0623079040081', 'canon for IE/MG ok' ); is(canon_ie('ro', '726 84661 76825 6'), '72684661768256', 'canon for IE/RO ok'); is(canon_ie('rr', '24006628-1'), '240066281', 'canon for IE/RR ok'); is(canon_ie('sp', 99), '000000000099', 'amenable to ints'); is(canon_ie('sp', '999.999.999.999'), '999999999999', 'discards formatting'); is(canon_ie('sp', 111_222_333_444_555), '111222333444555', 'too long ints pass through'); is(canon_ie('sp', '111_222_333_444_555'), '111222333444555', 'as well as other too long inputs'); is(canon_ie('sp', '000x000x000x000'), '000x000x000x000', 'letters are not stripped anymore'); Business-BR-Ids-0.0022/t/005_cpf_parse.t0000644000175000017500000000073410713621552017552 0ustar ferreiraferreira use Test::More tests => 4; BEGIN { use_ok('Business::BR::CPF', 'parse_cpf') }; ($base, $dv) = parse_cpf('000.111.222-00'); is($base, '000111222', "at list context: base ok"); is($dv, '00', "at list context: dv ok"); $hashref = parse_cpf('999.222.111-00'); is_deeply($hashref, { base => '999222111', dv => '00' }, "scalar context works ok"); # do I need tests for extended short ints? # do I need tests for pruned CPF candidates? # what about long inputs? Business-BR-Ids-0.0022/t/011_ie_test.t0000644000175000017500000000632510713621552017243 0ustar ferreiraferreira use Test::More tests => 46; #use Test::More no_plan => 1; BEGIN { use_ok('Business::BR::IE', 'test_ie') }; ok(test_ie('ac', '01.004.823/001-12'), '"01.004.823/001-12" is a correct IE/AC'); ok(!test_ie('ac', '01.004.823/001-02'), '"01.004.823/001-02" is an incorrect IE/AC'); ok(!test_ie('ac', '01.004.823/001-13'), '"01.004.823/001-13" is an incorrect IE/AC'); ok(test_ie('al', '24.000.004-8'), '"24.000.004-8" is a correct IE/AL'); ok(!test_ie('ap', '00.000.000-0'), '"00.000.000-0" is an incorrect IE/AP'); # does not begin with '03' ok(test_ie('ap', '03.012.345-9'), '"03.012.345-9" is a correct IE/AP'); # 1st class, 03.000.001-x up to 03.017.000-x for (qw( 030210852 030235103 030172588 030010751 030110543 030231159 030221013 030218373 030184403 )) { ok(test_ie('ap', $_), "\"$_\" is a correct IE/AP"); } # 1st class, 03.000.001-x up to 03.017.000-x # 2nd class, 03.017.001-x up to 03.019.022-x # 3rd class, from 03.019.023-x and on ok(test_ie('am', '11.111.111-0'), '"11.111.111-0" is a correct IE/AM'); ok( test_ie('ba', '123456-63'), '"123456-63" is a correct IE/BA' ); ok( test_ie('ba', '612345-57'), '"612345-57" is a correct IE/BA' ); ok(test_ie('ma', '12.000.038-5'), '"12.000.038-5" is a correct IE/MA'); ok( test_ie('mg', '062.307.904/0081'), q{'062.307.904/0081' is a correct IE/MG} ); ok(test_ie('ro', '0000000062521-3'), '"0000000062521-3" is a correct IE/RO'); ok(test_ie('ro', '42360936787181'), '"42360936787181" is a correct IE/RO'); ok(!test_ie('ro', '72684661768256'), '"0000000062521-3" is an incorrect IE/RO'); ok(test_ie('rr', '24006628-1'), '"24006628-1" is a correct IE/RR'); ok(test_ie('rr', '24001755-6'), '"24001755-6" is a correct IE/RR'); ok(test_ie('rr', '24003429-0'), '"24003429-0" is a correct IE/RR'); ok(test_ie('rr', '24001360-3'), '"24001360-3" is a correct IE/RR'); ok(test_ie('rr', '24008266-8'), '"24008266-8" is a correct IE/RR'); ok(test_ie('rr', '24006153-6'), '"24006153-6" is a correct IE/RR'); ok(test_ie('rr', '24007356-2'), '"24007356-2" is a correct IE/RR'); ok(test_ie('rr', '24005467-4'), '"24005467-4" is a correct IE/RR'); ok(test_ie('rr', '24004145-5'), '"24004145-5" is a correct IE/RR'); ok(test_ie('rr', '24001340-7'), '"24001340-7" is a correct IE/RR'); ok(test_ie('pr', '123.45678-50'), '"123.45678-50" is a correct IE/PR'); ok(test_ie('sp', '110.042.490.114'), '"110.042.490.114" is a correct IE/SP'); ok(test_ie('sp', '645.095.752.110'), '"645.095.752.110" is a correct IE/SP'); ok(!test_ie('sp', '110.042.490.110'), '"110.042.490.110" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.111'), '"110.042.490.111" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.112'), '"110.042.490.112" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.113'), '"110.042.490.113" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.115'), '"110.042.490.115" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.116'), '"110.042.490.116" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.117'), '"110.042.490.117" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.118'), '"110.042.490.118" is an incorrect IE/SP'); ok(!test_ie('sp', '110.042.490.119'), '"110.042.490.119" is an incorrect IE/SP'); Business-BR-Ids-0.0022/t/003_cpf_canon.t0000644000175000017500000000057610713621552017540 0ustar ferreiraferreira use Test::More tests => 5; BEGIN { use_ok('Business::BR::CPF', 'canon_cpf') }; is(canon_cpf(99), '00000000099', 'amenable to ints'); is(canon_cpf('999.999.999-99'), '99999999999', 'discards formatting'); is(canon_cpf(111_222_333_444), '111222333444', 'too long ints pass through'); is(canon_cpf('111_222_333_444'), '111222333444', 'as well as other too long inputs'); Business-BR-Ids-0.0022/t/006_cnpj_test.t0000644000175000017500000000030310713621552017572 0ustar ferreiraferreira use Test::More tests => 3; BEGIN { use_ok('Business::BR::CNPJ') }; ok(test_cnpj('90.117.749/7654-80'), "works for good ones"); ok(!test_cnpj('88.222.111/0001-10'), "works for bad ones"); Business-BR-Ids-0.0022/t/012_ie_format.t0000644000175000017500000000222710713621552017552 0ustar ferreiraferreira use Test::More tests => 14; BEGIN { use_ok('Business::BR::IE', 'format_ie') }; is(format_ie('ac', '00 000 000 000 99'), '00.000.000/000-99', 'IE/AC formatting works'); is(format_ie('al', '00:000:000:9'), '00.000.000-9', 'formatting IE/AL ok'); is(format_ie('ap', '030123459'), '03.012.345-9', 'formatting IE/AP ok'); is(format_ie('am', '111111110'), '11.111.111-0', 'formatting IE/AM ok'); is(format_ie('ba', '12345663'), '123456-63', 'formatting IE/BA ok'); is(format_ie('ma', '0 0 1 1 1 2 2 2 3'), '00.111.222-3', 'formatting IE/MA ok'); is( format_ie('mg', '0623079040081'), '062.307.904/0081', 'formatting IE/MG ok' ); is(format_ie('ro', '72684661768256'), '7268466176825-6', 'formatting IE/RO ok'); is(format_ie('rr', '24008266-8'), '24.008.266-8', 'formatting IE/RR ok'); is(format_ie('sp','000000000000'), '000.000.000.000', 'works ok'); is(format_ie('sp', 6688822200), '006.688.822.200', 'works even for short ints'); is(format_ie('sp', '000#000@000~000'), '000.000.000.000', 'argument is flattened before formatting'); is(format_ie('sp', '1234567890123'), '123.456.789.012', 'only 1st 12 digits matter for long inputs'); Business-BR-Ids-0.0022/t/008_cpf_rand.t0000644000175000017500000000070110713621552017361 0ustar ferreiraferreira use constant N => 100; use Test::More tests => 1+2*N; BEGIN { use_ok('Business::BR::CPF', 'random_cpf', 'test_cpf') }; # the seed is set so that the test is reproducible srand(271828182845905); for ( my $i=0; $i 5; BEGIN { use_ok('Business::BR::CPF', 'format_cpf') }; is(format_cpf('00000000000'), '000.000.000-00', 'works ok'); is(format_cpf(6688822200), '066.888.222-00', 'works even for short ints'); is(format_cpf('000 000#000@00'), '000.000.000-00', 'argument is flattened before formatting'); is(format_cpf('000000000000'), '000.000.000-00', 'only 1st 11 digits matter for long inputs'); Business-BR-Ids-0.0022/t/007_ids_test.t0000644000175000017500000000070510713621552017426 0ustar ferreiraferreira use Test::More tests => 7; BEGIN { use_ok('Business::BR::Ids') }; ok(test_id('cpf', '56451416010'), "works for good CPF"); ok(!test_id('cpf', '231.002.999-00'), "works for bad CPF"); ok(test_id('cnpj', '90.117.749/7654-80'), "works for good CNPJ"); ok(!test_id('cnpj', '88.222.111/0001-10'), "works for bad CNPJ"); ok(test_id('ie', 'pr', '123.45678-50'), "works for good IE"); ok(test_id('pis', '121.51144.13-7'), "works for good PIS");Business-BR-Ids-0.0022/lib/0000755000175000017500000000000011032441002015317 5ustar ferreiraferreiraBusiness-BR-Ids-0.0022/lib/Business/0000755000175000017500000000000011032441002017112 5ustar ferreiraferreiraBusiness-BR-Ids-0.0022/lib/Business/BR/0000755000175000017500000000000011032441002017415 5ustar ferreiraferreiraBusiness-BR-Ids-0.0022/lib/Business/BR/IE.pm0000644000175000017500000007427211032440553020276 0ustar ferreiraferreira package Business::BR::IE; use 5; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( canon_ie format_ie parse_ie random_ie ); our @EXPORT = qw( test_ie ); our $VERSION = '0.0022'; $VERSION = eval $VERSION; use Business::BR::Ids::Common qw( _dot _dot_10 _canon_id ); ### AC ### # http://www.sintegra.gov.br/Cad_Estados/cad_AC.html sub canon_ie_ac { return _canon_id(shift, size => 13); } sub test_ie_ac { my $ie = canon_ie_ac shift; return undef if length $ie != 13; return 0 unless $ie =~ /^01/; my @ie = split '', $ie; my $s1 = _dot([4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], \@ie) % 11; unless ($s1==0 || $s1==1 && $ie[11]==0) { return 0; } my $s2 = _dot([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1], \@ie) % 11; return ($s2==0 || $s2==1 && $ie[12]==0) ? 1 : 0; } sub format_ie_ac { my $ie = canon_ie_ac shift; $ie =~ s|^(..)(...)(...)(...)(..).*|$1.$2.$3/$4-$5|; # 01.004.823/001-12 return $ie; } sub _dv_ie_ac { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-PR invalid) my @base = split '', substr($base, 0, 11); my $dv1 = -_dot([4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], \@base) % 11 % 10; my $dv2 = (-_dot([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], [ @base, $dv1 ]) + $dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 11, 2) = "$dv1$dv2"; return $base; } sub random_ie_ac { my $valid = @_ ? shift : 1; # valid IE-SP by default my $base = sprintf "01%09s", int(rand(1E9)); # '01' and 9 digits return scalar _dv_ie_ac($base, $valid); } sub parse_ie_ac { my $ie = canon_ie_ac shift; my ($base, $dv) = $ie =~ /(\d{11})(\d{2})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } ### AL ### # http://www.sefaz.al.gov.br/sintegra/cad_AL.asp # http://www.sintegra.gov.br/Cad_Estados/cad_AL.html my %AL_TYPES = ( 0 => "normal", 1 => "normal", 3 => "produtor rural", 5 => "substituta", 6 => "empresa pequeno porte", 7 => "micro empresa ambulante", 8 => "micro empresa", 9 => "especial" ); my @AL_TYPES = keys %AL_TYPES; sub canon_ie_al { return _canon_id(shift, size => 9); } sub test_ie_al { my $ie = canon_ie_al shift; return undef if length $ie != 9; return 0 unless $ie =~ /^24/; my @ie = split '', $ie; return 0 unless $AL_TYPES{$ie[2]}; my $s1 = _dot([90, 80, 70, 60, 50, 40, 30, 20, -1], \@ie) % 11; #print "ie: $ie, s1: $s1\n"; return ($s1==0 || $s1==10 && $ie[8]==0) ? 1 : 0; } sub format_ie_al { my $ie = canon_ie_al shift; $ie =~ s|^(..)(...)(...)(.).*|$1.$2.$3-$4|; # 24.000.004-8 return $ie; } sub _dv_ie_al { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-AL invalid) my @base = split '', $base; my $dv1 = (_dot([90, 80, 70, 60, 50, 40, 30, 20], \@base) + $dev) % 11 % 10; return ($dv1) if wantarray; substr($base, 8, 1) = $dv1; return $base; } sub random_ie_al { my $valid = @_ ? shift : 1; # valid IE-AL by default my $base = sprintf "24%1s%05s", $AL_TYPES[int(rand(@AL_TYPES))], int(rand(1E5)); # '24', type and 5 digits return scalar _dv_ie_al($base, $valid); } sub parse_ie_al { my $ie = canon_ie_al shift; my ($base, $dv) = $ie =~ /(\d{8})(\d{1})/; if (wantarray) { return ($base, $dv); } my $type = substr($ie, 2, 1); return { base => $base, dv => $dv, type => $type, t_name => $AL_TYPES{$type} }; } ### AP ### #*** sub canon_ie_ap { return _canon_id(shift, size => 9); } sub test_ie_ap { my $ie = canon_ie_ap shift; return undef if length $ie != 9; return 0 unless $ie =~ /^03/; my $nr_empresa = substr($ie, 2, -1); my ($p, $d) = ($nr_empresa >= 1) && ($nr_empresa <= 17000) ? (5, 0) : # 1st class, 03.000.001-x up to 03.017.000-x ($nr_empresa >= 17001) && ($nr_empresa <= 19022) ? (9, 1) : # 2nd class, 03.017.001-x up to 03.019.022-x (0, 0); # 3rd class, from 03.019.023-x and on # print "(p, d) = ($p, $d)\n"; my @ie = split '', $ie; my $sum = -($p + _dot([9, 8, 7, 6, 5, 4, 3, 2, 1], \@ie)) % 11; # print "# ie: $ie, sum: $sum\n"; # *** return ($sum==0 || $sum==10 && $ie[8]==0) ? 1 : 0; } # FIXME: this is not QUITE RIGHT !!!!!!!!! sub format_ie_ap { my $ie = canon_ie_ap shift; $ie =~ s|^(..)(...)(...)(.).*|$1.$2.$3-$4|; # 03.012.245-9 return $ie; } sub _dv_ie_ap { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 3; # deviation (to make IE-AP invalid) my @base = split '', $base; my $nr_empresa = substr($base, 2, -1); my ($p, $d) = ($nr_empresa >= 1) && ($nr_empresa <= 17000) ? (5, 0) : # 1st class, 03.000.001-x up to 03.017.000-x ($nr_empresa >= 17001) && ($nr_empresa <= 19022) ? (9, 1) : # 2nd class, 03.017.001-x up to 03.019.022-x (0, 0); # 3rd class, from 03.019.023-x and on my $dv1 = -($p + _dot([9, 8, 7, 6, 5, 4, 3, 2, 0], \@base) + $dev) % 11 % 10; return ($dv1) if wantarray; substr($base, 8, 1) = $dv1; return $base; } sub random_ie_ap { my $valid = @_ ? shift : 1; # valid IE-AP by default my $base = sprintf "03%06d*", int(rand(1E6)); # '03', 6 digits, dv return scalar _dv_ie_ap($base, $valid); } sub parse_ie_ap { my $ie = canon_ie_ap shift; my ($base, $dv) = $ie =~ /(\d{8})(\d{1})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv, range => '?' }; } ### AM ### # http://www.sintegra.gov.br/Cad_Estados/cad_AM.html sub canon_ie_am { return _canon_id( shift, size => 9 ); } sub test_ie_am { my $ie = canon_ie_am(shift); return undef if length $ie != 9; my @ie = split '', $ie; my $s1 = _dot( [ 9, 8, 7, 6, 5, 4, 3, 2, 1 ], \@ie ) % 11; return ( $s1==0 || $s1==1 && $ie[8]==0 ) ? 1 : 0; } sub format_ie_am { my $ie = canon_ie_am(shift); $ie =~ s|^(..)(...)(...)(.).*|$1.$2.$3-$4|; # 11.111.111-0 return $ie; } sub parse_ie_am { my $ie = canon_ie_am(shift); my ($base, $dv) = $ie =~ /(\d{8})(\d{1})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv, }; } sub _dv_ie_am { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE/AM invalid) my @base = split '', substr($base, 0, 8); my $dv1 = (-_dot([9, 8, 7, 6, 5, 4, 3, 2], \@base)+$dev) % 11 % 10; return ($dv1) if wantarray; substr($base, 8, 1) = $dv1; return $base; } sub random_ie_am { my $valid = @_ ? shift : 1; # valid IE-SP by default my $base = sprintf "%08s", int(rand(1E8)); # 8 digits # XXX IE/AM begins with '04'? return scalar _dv_ie_am($base, $valid); } ### BA ### # http://www.sintegra.gov.br/Cad_Estados/cad_BA.html sub canon_ie_ba { return _canon_id(shift, size => 8); } sub test_ie_ba { my $ie = canon_ie_ba(shift); return undef if length $ie != 8; my @ie = split '', $ie; if ( $ie =~ /^[0123458]/ ) { # calculo pelo modulo 10 my $s2 = _dot( [ 7, 6, 5, 4, 3, 2, undef, 1 ], \@ie ) % 10; unless ( $s2==0 ) { return 0; } my $s1 = _dot( [ 8, 7, 6, 5, 4, 3, 1, 2 ], \@ie ) % 10; return ( $s1==0 ) ? 1 : 0; } else { # $ie =~ /^[679]/ # calculo pelo modulo 11 my $s2 = _dot( [ 7, 6, 5, 4, 3, 2, undef, 1 ], \@ie ) % 11; unless ( $s2==0 || $s2==1 && $ie[7]==0 ) { return 0; } my $s1 = _dot( [ 8, 7, 6, 5, 4, 3, 1, 2 ], \@ie ) % 11; return ( $s1==0 || $s1==1 && $ie[6]==0 ) ? 1 : 0; } } sub format_ie_ba { my $ie = canon_ie_ba(shift); $ie =~ s|^(......)(..).*|$1-$2|; # 123456-63 return $ie; } sub parse_ie_ba { my $ie = canon_ie_ba(shift); my ($base, $dv) = $ie =~ /^(\d{6})(\d{2})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv, }; } # ??? sub _dv_ie_ba { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE/BA invalid) my @base = split '', substr($base, 0, 6); if ( $base =~ /^[0123458]/ ) { # calculo pelo modulo 10) my $dv2 = -_dot( [ 7, 6, 5, 4, 3, 2 ], \@base) % 10; my $dv1 = (-_dot( [ 8, 7, 6, 5, 4, 3, 2 ], [ @base, $dv2 ])+$dev) % 10; return ($dv1, $dv2) if wantarray; substr($base, 6, 2) = "$dv1$dv2"; return $base; } else { # =~ /^[679]/ # calculo pelo modulo 11 my $dv2 = -_dot( [ 7, 6, 5, 4, 3, 2 ], \@base) % 11 % 10; my $dv1 = (-_dot( [ 8, 7, 6, 5, 4, 3, 2 ], [ @base, $dv2 ])+$dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 6, 2) = "$dv1$dv2"; return $base; } } sub random_ie_ba { my $valid = @_ ? shift : 1; # valid IE/BA by default my $base = sprintf "%06s", int(rand(1E6)); # 6 digits return scalar _dv_ie_ba($base, $valid); } ### CE ### sub canon_ie_ce { return _canon_id(shift, size => 9); } ### DF ### sub canon_ie_df { return _canon_id(shift, size => 13); } ### ES ### sub canon_ie_es { return _canon_id(shift, size => 9); } ### GO ### sub canon_ie_go { return _canon_id(shift, size => 9); } ### MA ### # http://www.sintegra.gov.br/Cad_Estados/cad_MA.html sub canon_ie_ma { return _canon_id(shift, size => 9); } sub test_ie_ma { my $ie = canon_ie_ma shift; return undef if length $ie != 9; return 0 unless $ie =~ /^12/; my @ie = split '', $ie; my $s1 = _dot([9, 8, 7, 6, 5, 4, 3, 2, 1], \@ie) % 11; return ($s1==0 || $s1==1 && $ie[8]==0) ? 1 : 0; } sub format_ie_ma { my $ie = canon_ie_ma shift; $ie =~ s|^(..)(...)(...)(.).*|$1.$2.$3-$4|; # 12.000.038-5 return $ie; } sub _dv_ie_ma { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-MA invalid) my @base = split '', substr($base, 0, 8); my $dv1 = (-_dot([9, 8, 7, 6, 5, 4, 3, 2], \@base)+$dev) % 11 % 10; return ($dv1) if wantarray; substr($base, 8, 1) = $dv1; return $base; } sub random_ie_ma { my $valid = @_ ? shift : 1; # valid IE-SP by default my $base = sprintf "12%06s", int(rand(1E6)); # '12' and 6 digits return scalar _dv_ie_ma($base, $valid); } sub parse_ie_ma { my $ie = canon_ie_ma shift; my ($base, $dv) = $ie =~ /(\d{8})(\d{1})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } ### MT ### sub canon_ie_mt { return _canon_id(shift, size => 11); } ### MS ### sub canon_ie_ms { return _canon_id(shift, size => 9); } ### MG ### # http://www.sintegra.gov.br/Cad_Estados/cad_MG.html sub canon_ie_mg { return _canon_id( shift, size => 13 ); } sub test_ie_mg { my $ie = canon_ie_mg( shift ); return undef if length $ie != 13; my @ie = split '', $ie; my $c1 = - _dot_10( [1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, undef, undef], \@ie ) % 10; unless ( $ie[11] eq $c1 ) { return 0; } my $s2 = _dot( [ 3, 2, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 ], \@ie ) % 11; return ( $s2==0 || $s2==1 && $ie[12]==0 ) ? 1 : 0; } sub format_ie_mg { my $ie = canon_ie_mg shift; $ie =~ s|^(...)(...)(...)(..)(..).*|$1.$2.$3/$4$5|; # 062.307.904/0081 return $ie; } sub parse_ie_mg { my $ie = canon_ie_mg shift; my ($municipio, $inscricao, $ordem, $dv) = $ie =~ /(\d{3})(\d{6})(\d{2})(\d{2})/; if (wantarray) { return ($municipio, $inscricao, $ordem, $dv); } return { municipio => $municipio, inscricao => $inscricao, ordem => $ordem, dv => $dv, }; } sub _dv_ie_mg { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE/MG invalid) my @base = split '', substr($base, 0, 11); my $dv1 = -_dot_10([ 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2 ], \@base) % 10; my $dv2 = (-_dot([ 3, 2, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 ], [ @base, $dv1 ]) + $dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 11, 2) = "$dv1$dv2"; return $base; } sub random_ie_mg { my $valid = @_ ? shift : 1; # valid IE/MG by default my $base = sprintf "%011s", int(rand(1E11)); # 11 digits return scalar _dv_ie_mg($base, $valid); } ### PA ### sub canon_ie_pa { return _canon_id(shift, size => 9); } ### PB ### sub canon_ie_pb { return _canon_id(shift, size => 9); } ### PR ### #PR - http://www.fazenda.pr.gov.br/icms/calc_dgv.asp # Formato da Inscrição: NNN NNN NN-DD (10 dígitos) # Cálculo do Primeiro Dígito: Módulo 11 com pesos de 2 a 7, aplicados da direita para esquerda, sobre as 8 primeiras posições. # Cálculo do Segundo Dígito: Módulo 11 com pesos de 2 a 7, aplicados da direita para esquerda, sobre as 9 primeiras posições (inclui o primeiro dígito). # Exemplo: CAD 123.45678-50 #PR - http://www.sintegra.gov.br/Cad_Estados/cad_PR.html # Formato da Inscrição NNN.NNNNN-DD (1o dígitos) [ NNN NNN NN-DD ] # Exemplo: 123.45678-50 sub canon_ie_pr { return _canon_id(shift, size => 10); } sub test_ie_pr { my $ie = canon_ie_pr shift; return undef if length $ie != 10; my @ie = split '', $ie; my $s1 = _dot([3, 2, 7, 6, 5, 4, 3, 2, 1, 0], \@ie) % 11; my $s2 = _dot([4, 3, 2, 7, 6, 5, 4, 3, 2, 1], \@ie) % 11; unless ($s1==0 || $s1==1 && $ie[8]==0) { return 0; } return ($s2==0 || $s2==1 && $ie[9]==0) ? 1 : 0; } sub format_ie_pr { my $ie = canon_ie_pr shift; $ie =~ s|^(...)(.....)(..).*|$1.$2-$3|; return $ie; } sub _dv_ie_pr { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-PR invalid) my @base = split '', substr($base, 0, 8); my $dv1 = -_dot([3, 2, 7, 6, 5, 4, 3, 2], \@base) % 11 % 10; my $dv2 = (-_dot([4, 3, 2, 7, 6, 5, 4, 3, 2], [ @base, $dv1 ]) + $dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 8, 2) = "$dv1$dv2"; return $base; } sub random_ie_pr { my $valid = @_ ? shift : 1; # valid IE-SP by default my $base = sprintf "%08s", int(rand(1E8)); # 8 dígitos return scalar _dv_ie_pr($base, $valid); } sub parse_ie_pr { my $ie = canon_ie_pr shift; my ($base, $dv) = $ie =~ /(\d{8})(\d{2})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } ### PE ### sub canon_ie_pe { return _canon_id(shift, size => 14); } ### PI ### sub canon_ie_pi { return _canon_id(shift, size => 9); } ### RJ ### sub canon_ie_rj { return _canon_id(shift, size => 9); } ### RN ### sub canon_ie_rn { return _canon_id(shift, size => 9); } ### RS ### sub canon_ie_rs { return _canon_id(shift, size => 10); } ### RO ### # http://www.sintegra.gov.br/Cad_Estados/cad_RO.html sub canon_ie_ro { return _canon_id(shift, size => 14); } sub test_ie_ro { my $ie = canon_ie_ro shift; return undef if length $ie != 14; my @ie = split '', $ie; my $s1 = _dot([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1], \@ie) % 11; return $s1==0 || $ie[13]==0 && $s1==1; } sub format_ie_ro { my $ie = canon_ie_ro shift; $ie =~ s|^(.............)(.).*|$1-$2|; return $ie; } sub _dv_ie_ro { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-RO invalid) my @base = split '', substr($base, 0, 13); my $dv = (-_dot([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], \@base)+$dev) % 11 % 10; return ($dv) if wantarray; substr($base, 13, 1) = $dv; return $base; } sub random_ie_ro { my $valid = @_ ? shift : 1; # valid IE-RO by default my $base = sprintf "%013s", int(rand(1E13)); # 13 dígitos # devia ter maior probabilidade para 000 00000 AAAAA D return scalar _dv_ie_ro($base, $valid); } sub parse_ie_ro { my $ie = canon_ie_ro shift; my ($base, $dv) = $ie =~ /(\d{13})(\d{1})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } ### RR ### # http://www.sintegra.gov.br/Cad_Estados/cad_RR.html sub canon_ie_rr { return _canon_id(shift, size => 9); } sub test_ie_rr { my $ie = canon_ie_rr shift; return undef if length $ie != 9; return 0 unless $ie =~ /^24/; my @ie = split '', $ie; my $s1 = _dot([1, 2, 3, 4, 5, 6, 7, 8, -1], \@ie) % 9; return $s1==0 ? 1 : 0; } sub format_ie_rr { my $ie = canon_ie_rr shift; $ie =~ s|^(..)(...)(...)(.).*|$1.$2.$3-$4|; # 24.006.628-1 return $ie; } sub _dv_ie_rr { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-PR invalid) my @base = split '', substr($base, 0, 8); my $dv1 = (_dot([1, 2, 3, 4, 5, 6, 7, 8], \@base)+$dev) % 9; return ($dv1) if wantarray; substr($base, 8, 1) = $dv1; return $base; } sub random_ie_rr { my $valid = @_ ? shift : 1; # valid IE-SP by default my $base = sprintf "24%06s", int(rand(1E6)); # '24' and 6 digits return scalar _dv_ie_rr($base, $valid); } sub parse_ie_rr { my $ie = canon_ie_rr shift; my ($base, $dv) = $ie =~ /(\d{8})(\d{1})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } ### SC ### sub canon_ie_sc { return _canon_id(shift, size => 9); } ### SP ### sub canon_ie_sp { return _canon_id(shift, size => 12); } #SP - http://www.csharpbr.com.br/arquivos/csharp_mostra_materias.asp?escolha=0021 # Exemplo: Inscrição Estadual 110.042.490.114 # 12 dígitos, 9o. e 12o. são DVs # dv[1] = (1, 3, 4, 5, 6, 7, 8, 10) .* (c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8]) (mod 11) # dv[2] = (3 2 10 9 8 7 6 5 4 3 2 1) .* (c[1] ... c[11]) (mod 11) sub test_ie_sp { my $ie = canon_ie_sp shift; return undef if length $ie != 12; my @ie = split '', $ie; my $s1 = _dot([1, 3, 4, 5, 6, 7, 8, 10, -1, 0, 0, 0], \@ie) % 11; unless ($s1==0 || $s1==10 && $ie[8]==0) { return 0; } my $s2 = _dot([3, 2, 10, 9, 8, 7, 6, 5, 4, 3, 2, -1], \@ie) % 11; return ($s2==0 || $s2==10 && $ie[11]==0) ? 1 : 0; } sub format_ie_sp { my $ie = canon_ie_sp shift; $ie =~ s|^(...)(...)(...)(...).*|$1.$2.$3.$4|; return $ie; } # my ($dv1, $dv2) = _dv_ie_sp('') # => $dv1 = ?, $dv2 = ? # my ($dv1, $dv2) = _dv_ie_sp('', 0) # computes non-valid check digits # # computes the check digits of the candidate IE-SP number given as argument # (only the first 12 digits enter the computation) (9th and 12nd are ignored) # # In list context, it returns the check digits. # In scalar context, it returns the complete IE-SP (base and check digits) sub _dv_ie_sp { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make IE-SP invalid) my @base = split '', substr($base, 0, 12); my $dv1 = _dot([1, 3, 4, 5, 6, 7, 8, 10, 0, 0, 0, 0], \@base) % 11 % 10; my $dv2 = (_dot([3, 2, 10, 9, 8, 7, 6, 5, 0, 3, 2, 0], \@base) + 4*$dv1 + $dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 8, 1) = $dv1; substr($base, 11, 1) = $dv2; return $base } # generates a random (correct or incorrect) IE-SP # $ie = rand_ie_sp(); # $ie = rand_ie_sp($valid); # # if $valid==0, produces an invalid IE-SP sub random_ie_sp { my $valid = @_ ? shift : 1; # correct IE-SP by default my $ie = sprintf "%08s0%02s0", int(rand(1E8)), int(rand(1E2)); # 10 dígitos aleatórios return scalar _dv_ie_sp($ie, $valid); } sub parse_ie_sp { my $ie = canon_ie_sp shift; my ($base, $dv) = $ie =~ /(\d{8})(\d{2})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } ### SE ### sub canon_ie_se { return _canon_id(shift, size => 9); } ### TO ### sub canon_ie_to { return _canon_id(shift, size => 11); } # a dispatch table is used here, because we know beforehand # the list of Brazilian states. I am not sure it is # better than using symbolic references. my %dispatch_table = ( # AC test_ie_ac => \&test_ie_ac, canon_ie_ac => \&canon_ie_ac, format_ie_ac => \&format_ie_ac, random_ie_ac => \&random_ie_ac, parse_ie_ac => \&parse_ie_ac, # AL test_ie_al => \&test_ie_al, canon_ie_al => \&canon_ie_al, format_ie_al => \&format_ie_al, random_ie_al => \&random_ie_al, parse_ie_al => \&parse_ie_al, # AM test_ie_am => \&test_ie_am, canon_ie_am => \&canon_ie_am, format_ie_am => \&format_ie_am, random_ie_am => \&random_ie_am, parse_ie_am => \&parse_ie_am, # AP test_ie_ap => \&test_ie_ap, canon_ie_ap => \&canon_ie_ap, format_ie_ap => \&format_ie_ap, random_ie_ap => \&random_ie_ap, parse_ie_ap => \&parse_ie_ap, # BA test_ie_ba => \&test_ie_ba, canon_ie_ba => \&canon_ie_ba, format_ie_ba => \&format_ie_ba, random_ie_ba => \&random_ie_ba, parse_ie_ba => \&parse_ie_ba, # CE canon_ie_ce => \&canon_ie_ce, # DF canon_ie_df => \&canon_ie_df, # ES canon_ie_es => \&canon_ie_es, # GO canon_ie_go => \&canon_ie_go, # MA test_ie_ma => \&test_ie_ma, canon_ie_ma => \&canon_ie_ma, format_ie_ma => \&format_ie_ma, random_ie_ma => \&random_ie_ma, parse_ie_ma => \&parse_ie_ma, # MG test_ie_mg => \&test_ie_mg, canon_ie_mg => \&canon_ie_mg, format_ie_mg => \&format_ie_mg, random_ie_mg => \&random_ie_mg, parse_ie_mg => \&parse_ie_mg, # MT canon_ie_mt => \&canon_ie_mt, # MS canon_ie_ms => \&canon_ie_ms, # PE canon_ie_pe => \&canon_ie_pe, # PA canon_ie_pa => \&canon_ie_pa, # PB canon_ie_pb => \&canon_ie_pb, # PI canon_ie_pi => \&canon_ie_pi, # PR test_ie_pr => \&test_ie_pr, canon_ie_pr => \&canon_ie_pr, format_ie_pr => \&format_ie_pr, random_ie_pr => \&random_ie_pr, parse_ie_pr => \&parse_ie_pr, # RJ canon_ie_rj => \&canon_ie_rj, # RN canon_ie_rn => \&canon_ie_rn, # RO test_ie_ro => \&test_ie_ro, canon_ie_ro => \&canon_ie_ro, format_ie_ro => \&format_ie_ro, random_ie_ro => \&random_ie_ro, parse_ie_ro => \&parse_ie_ro, # RR test_ie_rr => \&test_ie_rr, canon_ie_rr => \&canon_ie_rr, format_ie_rr => \&format_ie_rr, random_ie_rr => \&random_ie_rr, parse_ie_rr => \&parse_ie_rr, # RS canon_ie_rs => \&canon_ie_rs, # SC canon_ie_sc => \&canon_ie_sc, # SE canon_ie_se => \&canon_ie_se, # SP test_ie_sp => \&test_ie_sp, canon_ie_sp => \&canon_ie_sp, format_ie_sp => \&format_ie_sp, random_ie_sp => \&random_ie_sp, #parse_ie_sp # TO canon_ie_to => \&canon_ie_to, ); sub _invoke { my $subname = shift; my $sub = $dispatch_table{$subname}; die "$subname not implemented" unless $sub; return &$sub(@_); } sub test_ie { my $uf = lc shift; return _invoke("test_ie_$uf", @_); } sub canon_ie { my $uf = lc shift; return _invoke("canon_ie_$uf", @_); } sub format_ie { my $uf = lc shift; return _invoke("format_ie_$uf", @_); } sub random_ie { my $uf = lc shift; return _invoke("random_ie_$uf", @_); } sub parse_ie { my $uf = lc shift; return _invoke("parse_ie_$uf", @_); } 1; __END__ =head1 NAME Business::BR::IE - Perl module to test for correct IE numbers =head1 SYNOPSIS use Business::BR::IE qw(test_ie canon_ie format_ie random_ie); test_ie('sp', '110.042.490.114') # 1 test_ie('pr', '123.45678-50') # 1 test_ie('ac', '01.004.823/001-12') # 1 test_ie('al', '24.000.004-8') # 1 test_ie('am', '04.117.161-6') # 1 test_ie('ba', '123456-63') # 1 test_ie('ma', '12.000.038-5') # 1 test_ie('mg', '062.307.904/0081') #1 test_ie('rr', '24.006.628-1') # 1 test_ie('ap', '03.012.345-9') # 1 =head1 DESCRIPTION YET TO COME. Handles IE for the states of Acre (AC), Alagoas (AL), Amapá (AP), Amazonas (AM), Bahia (BA), Maranhão (MA), Minas Gerais (MG), Paraná (PR), Rondônia (RO), Roraima (RR) and Sao Paulo (SP) by now. =head2 EXPORT C is exported by default. C, C, C and C can be exported on demand. =head1 DETAILS Each state has its own rules for IE numbers. In this section, we gloss over each one of these =head2 AC The state of Acre uses: =over 4 =item * 13-digits number =item * the last two are check digits =item * the usual formatting is like C<'01.004.823/001-12'> =item * if the IE-AC number is decomposed into digits like this a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 a_9 a_10 a_11 d_1 d_2 it is correct if a_1 a_2 = 0 1 (that is, it always begin with "01") and if it satisfies the check equations: 4 a_1 + 3 a_2 + 2 a_3 + 9 a_4 + 8 a_5 + 7 a_6 + 6 a_7 + 5 a_8 + 4 a_9 + 3 a_10 + 2 a_11 + d_1 = 0 (mod 11) or = 1 (mod 11) (if d_1 = 0) 5 a_1 + 4 a_2 + 3 a_3 + 2 a_4 + 9 a_5 + 8 a_6 + 7 a_7 + 6 a_8 + 5 a_9 + 4 a_10 + 3 a_11 + 2 d_1 + d_2 = 0 (mod 11) or = 1 (mod 11) (if d_2 = 0) =back =head2 AL The state of Alagoas uses: =over 4 =item * 9-digits number =item * the last one is a check digit =item * the usual formatting is like C<'24.000.004-8'> =item * if the IE-AL number is decomposed into digits like this a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 d_1 it is correct if it always begin with "24" (the code for the state of Alagoas), a_1 a_2 = 2 4 if the following digit identifies a valid company type 0 - "normal" 1 - "normal" 3 - "produtor rural" 5 - "substituta" 6 - "empresa pequeno porte" 7 - "micro empresa ambulante" 8 - "micro empresa" 9 - "especial" and if it satisfies the check equation: ( 9 a_1 + 2 a_2 + 3 a_3 + 4 a_4 + 5 a_5 6 a_6 + 7 a_7 + 8 a_8 ) * 10 - d_1 = 0 (mod 11) or = 10 (mod 11) (if d_1 = 0) =back =head2 AM The state of Amazonas uses: =over 4 =item * 9-digits number =item * the last one is a check digit =item * the usual formatting is like C<'11.111.111-0'> =item * if the IE-AM number is decomposed into digits like this a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 d_1 it is correct if it satisfies the check equation: 9 a_1 + 8 a_2 + 7 a_3 + 6 a_4 + 5 a_5 4 a_6 + 3 a_7 + 2 a_8 + d_1 = 0 (mod 11) or = 1 (mod 11) (if d_1 = 0) =back =head2 BA The state of Bahia uses: =over 4 =item * 8-digits number =item * the last two are check digits =item * the usual formatting is like C<'123456-63'> =back =head2 MA The state of Maranhão uses: =over 4 =item * 9-digits number =item * the 9th is a check digit =item * the usual formatting is like C<'12.000.038-5'> =item * if the IE-MA number is decomposed into digits like this a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 d_1 it is correct if it always begin with "12" (the code for the state of Maranhão), a_1 a_2 = 1 2 and if it satisfies the check equation: ( 9 a_1 + 8 a_2 + 7 a_3 + 6 a_4 + 5 a_5 4 a_6 + 3 a_7 + 2 a_8 ) - d_1 = 0 (mod 11) or = 10 (mod 11) (if d_1 = 0) =back =head2 MG The state of Minas Gerais uses: =over 4 =item * 13-digits number =item * the 11th and 12th are check digits =item * the usual formatting is like C<'062.307.904/0081'> =item * to determine if IE/MG number is correct, the computation rules in http://www.sintegra.gov.br/Cad_Estados/cad_MG.html must be followed. (Yes, they are boring and hard to describe.) =back =head2 PR The state of Paraná uses: =over 4 =item * 10-digits number =item * the 9th and 10th are check digits =item * the usual formatting is like C<'123.45678-50'> =back =head2 RO The state of Rondônia uses: =over 4 =item * 14-digits number =item * the 14th is a check digit =item * the usual formatting is like C<'0000000062521-3'> =item * if the IE-RO number is decomposed into digits like this a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 a_9 a_10 a_11 a_12 a_13 d_1 it is correct if it satisfies the check equation: ( 6 a_1 + 5 a_2 + 4 a_3 + 3 a_4 + 2 a_5 + 9 a_6 + 8 a_7 + 7 a_8 + 6 a_9 + 5 a_10 + 4 a_11 + 3 a_12 + 2 a_13 + d_1 = 0 (mod 11) or = 1 (mod 11) if d_1 = 0 =back =head2 RR The state of Roraima uses: =over 4 =item * 9-digits number =item * the 9th is a check digit =item * the usual formatting is like C<'24.006.628-1'> =item * if the IE-RR number is decomposed into digits like this a_1 a_2 a_3 a_4 a_5 a_6 a_7 a_8 d_1 it is correct if it always begin with "24" (the code for the state of Roraima), a_1 a_2 = 2 4 and if it satisfies the check equation: ( 1 a_1 + 2 a_2 + 3 a_3 + 4 a_4 + 5 a_5 6 a_6 + 7 a_7 + 8 a_8 ) - d_1 = 0 (mod 9) =back =head2 SP The state of São Paulo uses: =over 4 =item * 12-digits number =item * the 9th and 12nd are check digits =item * the usual formatting is like C<'110.042.490.114'> =back =head1 BUGS =over 4 =item * This documentation is faulty =item * If you want handling more than AC, AL, AM, MA, MG, PR, RO, RO and SP, you'll have to wait for the next releases =item * The handling of IE-SP does not include yet the special rule for testing correctness of registrations of rural producers. =item * the case of unfair digits must be handled satisfactorily (in this and other Business::BR::Ids modules) =back =head1 SEE ALSO 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, Eferreira@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2005-2007 by A. R. Ferreira This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Business-BR-Ids-0.0022/lib/Business/BR/CPF.pm0000644000175000017500000002215711032440541020401 0ustar ferreiraferreira package Business::BR::CPF; use 5; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); #our %EXPORT_TAGS = ( 'all' => [ qw() ] ); #our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); #our @EXPORT = qw(); our @EXPORT_OK = qw( canon_cpf format_cpf parse_cpf random_cpf ); our @EXPORT = qw( test_cpf ); our $VERSION = '0.0022'; #use Scalar::Util qw(looks_like_number); use Business::BR::Ids::Common qw(_dot _canon_id); sub canon_cpf { return _canon_id(shift, size => 11); } # there is a subtle difference here between the return for # for an input which is not 11 digits long (undef) # and one that does not satisfy the check equations (0). # Correct CPF numbers return 1. sub test_cpf { my $cpf = canon_cpf shift; return undef if length $cpf != 11; my @cpf = split '', $cpf; my $s1 = _dot([10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], \@cpf) % 11; my $s2 = _dot([0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1], \@cpf) % 11; unless ($s1==0 || $s1==1 && $cpf[9]==0) { return 0; } return ($s2==0 || $s2==1 && $cpf[10]==0) ? 1 : 0; } sub format_cpf { my $cpf = canon_cpf shift; $cpf =~ s/^(...)(...)(...)(..).*/$1.$2.$3-$4/; return $cpf; } sub parse_cpf { my $cpf = canon_cpf shift; my ($base, $dv) = $cpf =~ /(\d{9})(\d{2})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } # my ($dv1, $dv2) = _dv_cpf('390.533.447-05') # => $dv1 = 0, $dv2 = 5 # my ($dv1, $dv2) = _dv_cpf('390.533.447-05', 0) # computes non-valid check digits # # computes the check digits of the candidate CPF number given as argument # (only the first 9 digits enter the computation) # # In list context, it returns the check digits. # In scalar context, it returns the complete CPF (base and check digits) sub _dv_cpf { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make CPF invalid) my @base = split '', substr($base, 0, 9); my $dv1 = -_dot([10, 9, 8, 7, 6, 5, 4, 3, 2], \@base) % 11 % 10; my $dv2 = (-_dot([0, 10, 9, 8, 7, 6, 5, 4, 3, 2], [ @base, $dv1 ]) + $dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 9, 2) = "$dv1$dv2"; return $base; } # generates a random (correct or incorrect) CPF # $cpf = rand_cpf(); # $cpf = rand_cpf($valid); # # if $valid==0, produces an invalid CPF. sub random_cpf { my $valid = @_ ? shift : 1; # valid CPF by default my $base = sprintf "%09s", int(rand(1E9)); # 9 dígitos return scalar _dv_cpf($base, $valid); } 1; __END__ =head1 NAME Business::BR::CPF - Perl module to test for correct CPF numbers =head1 SYNOPSIS use Business::BR::CPF; print "ok " if test_cpf('390.533.447-05'); # prints 'ok ' print "bad " unless test_cpf('231.002.999-00'); # prints 'bad ' =head1 DESCRIPTION The CPF number is an identification number of Brazilian citizens emitted by the Brazilian Ministry of Revenue, which is called "Ministério da Fazenda". CPF stands for "Cadastro de Pessoa Física" (literally, physical person registration) as opposed to the CNPJ number for companies. The CPF is comprised of a base of 9 digits and 2 check digits. It is usually written like '231.002.999-00' so as to be more human-readable. This module provides C for checking that a CPF number is I. Here a I means =over 4 =item * it is 11 digits long =item * it satisfies the two check equations mentioned below =back Before checking, any non-digit letter is stripped, making it easy to test formatted entries like '231.002.999-00' and entries with extra blanks like ' 999.221.222-00 '. =over 4 =item B test_cpf('999.444.333-55') # incorrect CPF, returns 0 test_cpf(' 263.946.533-30 ') # is ok, returns 1 test_cpf('888') # nope, returns undef Tests whether a CPF number is correct. Before testing, any non-digit character is stripped. Then it is expected to be 11 digits long and to satisfy two check equations which validate the last two check digits. See L. The policy to get rid of '.' and '-' is very liberal. It indeeds discards anything that is not a digit (0, 1, ..., 9) or letter. That is handy for discarding spaces as well test_cpf(' 263.946.533-30 ') # is ok, returns 1 But extraneous inputs like '#333%444*2.3+2-00' are also accepted. If you are worried about this kind of input, just check against a regex: warn "bad CPF: only digits (11) expected" unless ($cpf =~ /^\d{11}$/); warn "bad CPF: does not match mask '___.___.___-__'" unless ($cpf =~ /^\d{3}\.\d{3}\.\d{3}-\d{2}$/); NOTE. Integer numbers like 9999811299 (or 99_998_112_99) with fewer than 11 digits will be normalized (eg. to "09999811299") before testing. =item B canon_cpf(99); # returns '00000000099' canon_cpf('999.999.999-99'); # returns '99999999999' Brings a candidate for a CPF number to a canonical form. In case, the argument is an integer, it is formatted to at least eleven digits. Otherwise, it is stripped of any non-alphanumeric characters and returned as it is. =item B format_cpf('00000000000'); # returns '000.000.000-00' Formats its input into '000.000.000-00' mask. First, the argument is canon'ed and then dots and hyphen are added to the first 11 digits of the result. =item B ($base, $dv) = parse_cpf($cpf); $hashref = parse_cpf('999.222.111-00'); # { base => '999222111', dv => '00' } Splits a candidate for CPF number into base and check digits (dv - dígitos de verificação). It canon's the argument before splitting it into 9- and 2-digits parts. In a list context, returns a two-element list with the base and the check digits. In a scalar context, returns a hash ref with keys 'base' and 'dv' and associated values. =item B $rand_cpf = random_cpf($valid); $correct_cpf = random_cpf(); $cpf = random_cpf(1); # also a correct CPF $bad_cpf = random_cpf(0); # an incorrect CPF Generates a random CPF. If $valid is omitted or 1, it is guaranteed to be I. If $valid is 0, it is guaranteed to be I. This function is intented for mass test. (Use it wisely.) The implementation is simple: just generate a 9-digits random number, hopefully with a uniform distribution and then compute the check digits. If $valid==0, the check digits are computed B satisfy the check equations. =back =head2 EXPORT C is exported by default. C, C, C and C 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, Eferreira@cpan.orgE =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 Business-BR-Ids-0.0022/lib/Business/BR/PIS.pm0000644000175000017500000000757711032440567020445 0ustar ferreiraferreira package Business::BR::PIS; use 5; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); #our %EXPORT_TAGS = ( 'all' => [ qw() ] ); #our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); #our @EXPORT = qw(); our @EXPORT_OK = qw( canon_pis format_pis parse_pis random_pis ); our @EXPORT = qw( test_pis ); our $VERSION = '0.0022'; use Business::BR::Ids::Common qw(_dot _canon_id); sub canon_pis { return _canon_id(shift, size => 11); } # there is a subtle difference here between the return for # for an input which is not 11 digits long (undef) # and one that does not satisfy the check equations (0). # Correct PIS numbers return 1. sub test_pis { my $pis = canon_pis shift; return undef if length $pis != 11; my @pis = split '', $pis; my $sum = _dot([qw(3 2 9 8 7 6 5 4 3 2 1)], \@pis) % 11; return ($sum==0 || $sum==1 && $pis[10]==0) ? 1 : 0; } sub format_pis { my $pis = canon_pis shift; $pis =~ s/^(...)(.....)(..)(.).*/$1.$2.$3-$4/; # 999.99999.99-9 return $pis; } sub parse_pis { my $pis = canon_pis shift; my ($base, $dv) = $pis =~ /(\d{10})(\d{1})/; if (wantarray) { return ($base, $dv); } return { base => $base, dv => $dv }; } # my $dv = _dv_pis('121.51144.13-7') # => $dv1 = # my $dv = _dv_pis('121.51144.13-7', 0) # computes non-valid check digit # # computes the check digit of the candidate PIS number given as argument # (only the first 10 digits enter the computation) # # In list context, it returns the check digit. # In scalar context, it returns the complete PIS (base and check digits) sub _dv_pis { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make PIS invalid) my @base = split '', substr($base, 0, 10); my $dv = (-_dot([qw(3 2 9 8 7 6 5 4 3 2)], \@base) + $dev) % 11 % 10; return ($dv) if wantarray; substr($base, 10, 1) = $dv; return $base; } # generates a random (correct or incorrect) PIS # $pis = rand_pis(); # $pis = rand_pis($valid); # # if $valid==0, produces an invalid PIS. sub random_pis { my $valid = @_ ? shift : 1; # valid PIS by default my $base = sprintf "%010s?", int(rand(1E10)); # 10 dígitos return scalar _dv_pis($base, $valid); } 1; __END__ =head1 NAME Business::BR::PIS - Perl module to test for correct PIS numbers =head1 SYNOPSIS use Business::BR::PIS; print "ok " if test_pis('121.51144.13-7'); # prints 'ok ' print "bad " unless test_pis('121.51144.13-0'); # prints 'bad ' =head1 DESCRIPTION This module handles PIS numbers, testing, formatting, etc. =head2 EXPORT C is exported by default. C, C, C and C can be exported on demand. =head1 THE CHECK EQUATIONS A correct PIS number has a check digit which is computed from the base 10 first digits. Consider the PIS number written as 11 digits c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] dv[1] To check whether a PIS is correct or not, it has to satisfy the check equation: c[1]*3+c[2]*2+c[3]*9+c[4]*8+c[5]*7+ c[6]*6+c[7]*5+c[8]*4+c[9]*3+c[10]*2+dv[1] = 0 (mod 11) or = 1 (mod 11) (if dv[1]=0) =head1 BUGS Absolute lack of documentation by now. =head1 SEE ALSO 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, Eferreira@cpan.orgE =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 Business-BR-Ids-0.0022/lib/Business/BR/Ids.pm0000644000175000017500000001044511032440521020503 0ustar ferreiraferreira package Business::BR::Ids; use 5; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( canon_id parse_id format_id random_id ); our @EXPORT = qw( test_id ); our $VERSION = '0.0022'; $VERSION = eval $VERSION; use Carp; # a hash from entity types to packages my %types = ( cpf => 'Business::BR::CPF', cnpj => 'Business::BR::CNPJ', ie => 'Business::BR::IE', pis => 'Business::BR::PIS', ); # invoke($type, $subroot, @args) sub _invoke { my $type = lc shift; my $subroot = shift; my $package = $types{$type} or croak "unknown '$type'\n"; eval "require $package"; croak $@ if $@; no strict 'refs'; return &{"${package}::${subroot}${type}"}(@_); } sub test_id { return _invoke(shift, 'test_', @_); } sub canon_id { return _invoke(shift, 'canon_', @_); } sub format_id { return _invoke(shift, 'format_', @_); } sub parse_id { return _invoke(shift, 'parse_', @_); } sub random_id { return _invoke(shift, 'random_', @_); } 1; __END__ =head1 NAME Business::BR::Ids - Modules for dealing with Brazilian identification codes (CPF, CNPJ, ...) =head1 SYNOPSIS use Business::BR::Ids; my $cpf = '390.533.447-05'; print "ok as CPF" if test_id('cpf', $cpf); my $cnpj = '90.117.749/7654-80'; print "ok as CNPJ" if test_id('cnpj', $cnpj); =head1 DESCRIPTION This is a generic module for handling the various supported operations on Brazilian identification numbers and codes. For example, it is capable to test the correctness of CPF, CNPJ and IE numbers without the need for explicitly 'requiring' or 'using' this modules (doing it automatically on demand). =over 4 =item B test_id($entity_type, @args); test_id('cpf', $cpf); # the same as "require Business::BR::CPF; Business::BR::CPF::test_cpf($cpf)" Tests for correct inputs of ids which have a corresponding Business::BR module. For now, the supported id types are 'cpf', 'cnpj', 'ie', and 'pis'. =item B canon_id($entity_type, @args) Transform the input to a canonical form. The canonical form is well-defined and as short as possible. For instance, C returns C<'02912812911'> which has exactly 11 digits and no extra character. =back =head2 EXPORT C is exported by default. C, C, C and C are exported on demand. =begin comment =head1 OVERVIEW test_* canon_* format_* parse_* random_* =head1 ETHICS The facilities provided here can be used for bad purposes, like generating correct codes for trying frauds. This is specially true of the C functions. But anyway with only C functions, it is also very easy to try typically 100 choices and find a correct code as well. Unethical programmers (as any unethical people) should not be a reason to conceal things (like code) that can benefit a community. And I felt that this kind of code sometimes is hidden by other wrong reasons: to keep such a knowledge restricted to a group of people wanting to make money of it. But this is (or should be) public information. If institutions were really worried about this, they should publish validation equations like the ones listed in the documentation here instead of computation algorithms for check digits. If one does not know enough math to solve the equations, probably they don't need the solutions anyway. For modules on this distribution, only correctness is tested. For doing business, usually codes must be verified against the databases of the information owners, usually government bodies. =end comment =head1 SEE ALSO Details on handling CPF, CNPJ, IE and PIS can be found in the specific modules: =over 4 =item * Business::BR::CPF =item * Business::BR::CNPJ =item * Business::BR::IE =item * Business::BR::PIS =back Please reports bugs via CPAN RT, http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-BR-Ids =head1 AUTHOR A. R. Ferreira, Eferreira@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2005-2007 by A. R. Ferreira This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Business-BR-Ids-0.0022/lib/Business/BR/CNPJ.pm0000644000175000017500000002356611032440622020530 0ustar ferreiraferreira package Business::BR::CNPJ; use 5; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); #our %EXPORT_TAGS = ( 'all' => [ qw() ] ); #our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); #our @EXPORT = qw(); our @EXPORT_OK = qw( canon_cnpj format_cnpj parse_cnpj random_cnpj ); our @EXPORT = qw( test_cnpj ); our $VERSION = '0.0022'; use Business::BR::Ids::Common qw(_dot _canon_id); sub canon_cnpj { return _canon_id(shift, size => 14); } # there is a subtle difference here between the return for # for an input which is not 14 digits long (undef) # and one that does not satisfy the check equations (0). # Correct CNPJ numbers return 1. sub test_cnpj { my $cnpj = canon_cnpj shift; return undef if length $cnpj != 14; my @cnpj = split '', $cnpj; my $s1 = _dot([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], \@cnpj) % 11; my $s2 = _dot([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2, 1], \@cnpj) % 11; unless ($s1==0 || $s1==1 && $cnpj[12]==0) { return 0; } return ($s2==0 || $s2==1 && $cnpj[13]==0) ? 1 : 0; } sub format_cnpj { my $cnpj = canon_cnpj shift; $cnpj =~ s|^(..)(...)(...)(....)(..).*|$1.$2.$3/$4-$5|; return $cnpj; } sub parse_cnpj { my $cnpj = canon_cnpj shift; my ($base, $filial, $dv) = $cnpj =~ /(\d{8})(\d{4})(\d{2})/; if (wantarray) { return ($base, $filial, $dv); } return { base => $base, filial => $filial, dv => $dv }; } # my ($dv1, $dv2) = _dv_cnpj('') # => $dv1 = ?, $dv2 = ? # my ($dv1, $dv2) = _dv_cnpj('', 0) # computes non-valid check digits # # computes the check digits of the candidate CNPJ number given as argument # (only the first 12 digits enter the computation) # # In list context, it returns the check digits. # In scalar context, it returns the complete CNPJ (base and check digits) sub _dv_cnpj { my $base = shift; # expected to be canon'ed already ?! my $valid = @_ ? shift : 1; my $dev = $valid ? 0 : 2; # deviation (to make CNPJ invalid) my @base = split '', substr($base, 0, 12); my $dv1 = -_dot([5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], \@base) % 11 % 10; my $dv2 = (-_dot([6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2], [ @base, $dv1 ]) + $dev) % 11 % 10; return ($dv1, $dv2) if wantarray; substr($base, 12, 2) = "$dv1$dv2"; return $base; } # generates a random (correct or incorrect) CNPJ # $cpf = rand_cnpj(); # $cpf = rand_cnpj($valid); # # if $valid==0, produces an invalid CNPJ. sub random_cnpj { my $valid = @_ ? shift : 1; # valid CNPJ by default my $base = sprintf "%08s", int(rand(1E8)); # 8 dígitos my $var = sprintf "%04s", ((rand()<0.95) ? "0001" : int(sqrt rand(1E8))); return scalar _dv_cnpj("$base$var", $valid); } 1; __END__ =head1 NAME Business::BR::CNPJ - Perl module to test for correct CNPJ numbers =head1 SYNOPSIS use Business::BR::CNPJ; print "ok " if test_cnpj('90.117.749/7654-80'); # prints 'ok ' print "bad " unless test_cnpj('88.222.111/0001-10'); # prints 'bad ' =head1 DESCRIPTION The CNPJ number is an identification number of Brazilian companies emitted by the Brazilian Ministry of Revenue, which is called "Ministério da Fazenda". CNPJ stands for "Cadastro Nacional de Pessoa Jurídica" (literally, national juridical person registration) as opposed to the CPF number for natural persons. Sometime ago, it was called CGC ("Cadastro Geral de Contribuinte" or general taxpayer registration). The CNPJ is comprised of a base of 8 digits, a 4-digits radical and 2 check digits. It is usually written like '11.111.111/0001-55' so as to be more human-readable. This module provides C for checking that a CNPJ number is I. Here a I means =over 4 =item * it is 14 digits long =item * it satisfies the two check equations mentioned below =back Before checking, any non-digit letter is stripped, making it easy to test formatted entries like '11.111.111/0001-55' and entries with extra blanks like ' 43.337.004 / 0001-72 '. =over 4 =item B test_cnpj('48.999.764/0001-60') # incorrect CPF, returns 0 test_cnpj(' 43.337.004/0001-72 ') # is ok, returns 1 test_cnpj('888') # nope, returns undef Tests whether a CNPJ number is correct. Before testing, any non-digit character is stripped. Then it is expected to be 14 digits long and to satisfy two check equations which validate the last two check digits. See L. The policy to get rid of '.', '/' and '-' is very liberal. It indeeds discards anything that is not a digit (0, 1, ..., 9) or letter. That is handy for discarding spaces as well. test_cnpj(' 66.818.021/0001-27 ') # is ok, returns 1 But extraneous inputs like 'a53##045%4-20**0001!50' are also accepted. If you are worried about this kind of input, just check against a regex: warn "bad CNPJ: only digits (14) expected" unless ($cnpj =~ /^\d{14}$/); warn "bad CNPJ: does not match mask '__.___.___/____-__'" unless ($cnpj =~ /^\d{2}\.\d{3}\.\d{3}/\d{4}-\d{2}$/); NOTE. Integer numbers like 3337004000158 (or 3_337_004_0001_58) with fewer than 14 digits will be normalized (eg. to 03_337_004_0001_58) before testing. =item B canon_cnpj(1); # returns '00000000000001' canon_cnpj('99.999.222/0001-12'); # returns '99999222000112' Canon's a candidate for a CNPJ number. In case, the argument is an integer, it is formatted to at least fourteen digits. Otherwise, it is stripped of any non-alphanumeric characters and returned as it is. =item B format_cnpj('00 000 000 0000 00'); # returns '00.000.000/0000-00' Formats its input into '00.000.000/0000-00' mask. First, the argument is canon'ed and then dots, slash and hyphen are added to the first 14 digits of the result. =item B ($base, $filial, $dv) = parse_cnpj($cpf); $hashref = parse_cnpj('11.222.333/4444-00'); # { base => '11222333', filial => '4444' dv => '00' } Splits a candidate for CNPJ number into base, radical and check digits (dv - dígitos de verificação). It canon's the argument before splitting it into 8-, 4- and 2-digits parts. In a list context, returns a three-element list with the base, the radical and the check digits. In a scalar context, returns a hash ref with keys 'base', 'filial' and 'dv' and associated values. =item B $rand_cnpj = random_cnpj($valid); $good_cnpj = random_cnpj(); $cnpj = random_cnpj(1); # also a good one $bad_cnpj = random_cnpj(0); # bad CNPJ Generates a random CNPJ. If $valid is omitted or 1, it is guaranteed to be I. If $valid is 0, it is guaranteed to be I. This function is intented for mass test. (Use it wisely.) The implementation is: generate a 8-digits random number for the base, and the variation is chosen 95% of the time to be '0001' and the other 5% a skewed random distribution with the expression C is used. A uniform distribution is expected from C. With the base and variation, the check digits are computed. If $valid==0, the check digits are computed B satisfy the check equations. =back =head2 EXPORT C is exported by default. C, C, C and C can be exported on demand. =head1 THE CHECK EQUATIONS A correct CNPJ number has two check digits which are computed from the 12 first digits. Consider the CNPJ number written as 14 digits c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] c[12] dv[1] dv[2] To check whether a CNPJ is correct or not, it has to satisfy the check equations: 5*c[1]+4*c[2]+3*c[3]+2*c[4]+9*c[5]+ 8*c[6]+7*c[7]+6*c[8]+5*c[9]+4*c[10]+ 3*c[11]+2*c[12]+dv[1] = 0 (mod 11) or = 1 (mod 11) (if dv[1]=0) and 6*c[1]+5*c[2]+4*c[3]+3*c[4]+2*c[5]+ 9*c[6]+8*c[7]+7*c[8]+6*c[9]+5*c[10]+ 4*c[11]+3*c[12]+2*dv[1]+dv[2] = 0 (mod 11) or = 1 (mod 11) (if dv[2]=0) =head1 BUGS I heard that there are exceptions of CNPJ 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 "Emissão de Comprovante de Inscrição e de Situação Cadastral de Pessoa Jurídica", a web page which the Brazilian Ministry of Revenue provides for public consultation on regularity status of the taxpayer. This page tells if the CNPJ number is a correct entry (14-digits-long with verified check digits), if it references a real company and if it is regular with the government body. Given a bad CNPJ, the after-submit page tells "O número do CNPJ não é válido" (the CNPJ number is not valid). If the CNPJ is a good one but does not reference a real company, it says "CNPJ não existe em nossa base de dados" (CNPJ 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 CNPJ 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::CGC 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, Eferreira@cpan.orgE =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 Business-BR-Ids-0.0022/lib/Business/BR/Biz.pm0000644000175000017500000000621410713621552020521 0ustar ferreiraferreira package Business::BR::Biz; use 5; use strict; use warnings; our $VERSION = '0.00_09'; 1; __END__ =head1 NAME Business::BR::Biz - DEPRECATED (was: Modules for Brazilian business-related subjects) =head1 SYNOPSIS use Business::BR::Biz; # does nothing, it is here because of POD and $VERSION =head1 DESCRIPTION This module was a placeholder for the overview of the 'biz-br' distribution, now called 'Business-BR-Ids'. Soon we will get rid of it, by moving the introductory documentation contained here to Business::BR::Ids. =head2 EXPORT None by default. =head1 TESTING CORRECTNESS Among the functionalities to be made available in this distribution, we'll have tests for correctness of typical identification numbers and codes. I will mean here to satisfy certain easily computed rules. For example, a CPF number is correct if it is 11-digits-long and satisfy two check equations which validate the check digits. The modules C will provide subroutines C for testing the correctness of such concepts. To be I does not mean that an identification number or code had been I to stand for some real entry, like an actual Brazilian taxpayer citizen in the case of CPF. This would require access to government databases which may or may not be available in a public basis. And besides, to I something will not be I in general, implying access to databases and applying specialized rules. Here we'll be trying to stick to a consistent terminology and 'correct' will always be used for validity against syntactical forms and shallow semantics. In turn, 'verified' will be used for telling if an entity really makes sense in the real world. This convention is purely arbitrary and for the sake of being formal in some way. Terms like 'test', 'verify', 'check', 'validate', 'correct', 'valid' are often used interchangeably in colloquial prose. =head1 EXAMPLES As a rule, the documentation and tests choose correct identification codes which are verified to be invalid by the time of the distribution update. That is, in Business::BR::CPF, the mentioned correct CPF number '390.533.447-05' is correct, but doesn't actually exist in government databases. =head1 SEE ALSO As you might have guessed, this is not the first Perl distribution to approach this kind of functionality. Take a look at http://search.cpan.org/search?module=Brasil::Checar::CPF http://search.cpan.org/search?module=Brasil::Checar::CGC http://search.cpan.org/~mamawe/Algorithm-CheckDigits-0.38/CheckDigits/M11_004.pm If you want to find out about the namespace L, follow the link. Please reports bugs via CPAN RT, http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-BR-Ids =head1 AUTHOR A. R. Ferreira, Eferreira@cpan.orgE =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 Business-BR-Ids-0.0022/lib/Business/BR/Ids/0000755000175000017500000000000011032441002020134 5ustar ferreiraferreiraBusiness-BR-Ids-0.0022/lib/Business/BR/Ids/Common.pm0000644000175000017500000001010511032440675021736 0ustar ferreiraferreira package Business::BR::Ids::Common; use 5; use strict; use warnings; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw( _dot _dot_10 _canon_i _canon_id ); our $VERSION = '0.0022'; $VERSION = eval $VERSION; sub _dot { my $a = shift; my $b = shift; warn "arguments a and b should have the same length" unless (@$a==@$b); my $s = 0; for ( my $i=0; $i<@$a; $i++ ) { my ($x, $y) = ($a->[$i], $b->[$i]); if ($x && $y) { $s += $x*$y; } } return $s; } sub _dot_10 { my $a = shift; my $b = shift; warn "arguments a and b should have the same length" unless (@$a==@$b); my $s = 0; for ( my $i=0; $i<@$a; $i++ ) { my ($x, $y) = ($a->[$i], $b->[$i]); if ( $x && $y ) { my $xy = $x*$y; $s += $_ for split('', $xy); # sum each digit of the product } } return $s; } use Scalar::Util qw(looks_like_number); # usage: _canon_i($piece, size => 12) sub _canon_i { my $piece = shift; my %options = @_; if (looks_like_number($piece) && int($piece)==$piece) { return sprintf('%0*s', $options{size}, $piece) } else { $piece =~ s/\D//g; return $piece; } } sub _canon_id { my $piece = shift; my %options = @_; if (looks_like_number($piece) && int($piece)==$piece) { return sprintf('%0*s', $options{size}, $piece) } else { $piece =~ s/[\W_]//g; return $piece; } } 1; __END__ =head1 NAME Business::BR::Ids::Common - Common code used in Business-BR-Ids modules =head1 SYNOPSIS use Business::BR::Ids::Common qw(_dot _canon_i _canon_id); my @digits = (1, 2, 3, 3); my @weights = (2, 5, 2, 6); my $dot = _dot(\@weights, \@digits); # computes 2*1+5*2+2*3+6*3 = 36 # computes the sum of digits of ( 2*1, 5*2, 2*3, 6*3 ) # which is 2 + (1 + 0) + 6 + (1 + 8) = 18 my $s = _dot_10(\@weights, \@digits); _canon_i(342222, size => 7); # returns '0342222' _canon_i('12.28.8', size => 5); # returns '12288' _canon_i(342222, size => 7); # returns '0342222' _canon_i('12.28.8', size => 5); # returns '12288' _canon_id('A12.3-B', size => 5); # returns 'A123B' =head1 DESCRIPTION This module is meant to be private for Business-BR-Ids distributions. It is a common placeholder for code which is shared among other modules of the distribution. Actually, the only code here is the computation of the scalar product between two array refs. In the future, this module can disappear being more aptly named and even leave the Business::BR namespace. =over 4 =item B<_dot> $s = _dot(\@a, \@b); Computes the scalar (or dot) product of two array refs: sum( a[i]*b[i], i = 0..$#a ) Note that due to this definition, the second argument should be at least as long as the first argument. =item B<_dot_10> $s = _dot_10(\@a, \@b); Computes the product of corresponding elements in the array refs and then takes the sum of its digits. (Used for computing IE/MG.) =item B<_canon_i> $qs = _canon_i($s, size => 8) If the argument is a number, formats it to the specified size. Then, strips any non-digit character. If the argument is a string, it just strips non-digit characters. =item B<_canon_id> $qs = _canon_id($s, size => 8) If the argument is a number, formats it to the specified size. Then, strips any non-digit character. If the argument is a string, it just strips characters matching C. =back =head2 EXPORT None by default. You can explicitly ask for C<_dot()> which is a sub to compute the dot product between two array refs (used for computing check digits). There are also C<_dot_10>, C<_canon_i> and C<_canon_id> to be exported on demand. =head1 SEE ALSO Please reports bugs via CPAN RT, http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-BR-Ids =head1 AUTHOR A. R. Ferreira, Eferreira@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2005-2007 by A. R. Ferreira This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut Business-BR-Ids-0.0022/lib/Business/BR.pm0000644000175000017500000000306711032440705017772 0ustar ferreiraferreira package Business::BR; use 5; use strict; use warnings; #require Exporter; #our @ISA = qw(Exporter); #our %EXPORT_TAGS = ( 'all' => [ qw() ] ); #our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); #our @EXPORT = qw(); our $VERSION = '0.0022'; 1; __END__ =head1 NAME Business::BR - Root for namespace of Brazilian business-related modules =head1 SYNOPSIS use Business::BR; # does nothing, it is just a placeholder =head1 DESCRIPTION This module is meant to provide a root for the namespace C. It is meant as a placeholder to reserve and explain how the namespace can be used. To see actual code, take a look at C modules http://search.cpan.org/search?query=Business%3A%3ABR&mode=module =head1 SEE ALSO The namespace has been chosen based on similar modules for other countries, like Business::FR::SSN which tests the French "Numéro de Sécurité Sociale", the C L and C L modules. Please reports bugs via CPAN RT, http://rt.cpan.org/NoAuth/Bugs.html?Dist=Business-BR-Ids =head1 AUTHOR A. R. Ferreira, Eferreira@cpan.orgE =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 Business-BR-Ids-0.0022/Makefile.PL0000644000175000017500000000103510713621552016541 0ustar ferreiraferreira use 5; use ExtUtils::MakeMaker; my $EUMM_VERSION = eval $ExtUtils::MakeMaker::VERSION; WriteMakefile( NAME => 'Business-BR-Ids', VERSION_FROM => 'lib/Business/BR/Ids.pm', PREREQ_PM => { Scalar::Util => 1.11, Test::More => 0, }, ($] >= 5.005 ? ( ABSTRACT_FROM => 'lib/Business/BR/Ids.pm', AUTHOR => 'A. R. Ferreira ' ) : ()), ($EUMM_VERSION >= 6.31 ? ( LICENSE => 'perl', ) :()) ); Business-BR-Ids-0.0022/Changes0000644000175000017500000001505711032440460016063 0ustar ferreiraferreiraRevision history for Perl extension Business-BR-Ids. 0.0022 Tue Jul 1 2008 - promoted to a "stable" release 0.00_21 Mon Sep 17 2007 - fixed t/002_cpf_test.t and t/015_pis_rand.t which did "BEGIN { use_ok }" before setting the plan 0.00_20 Tue Aug 7 2007 - 11 in 27 states supported in Business::BR::IE - added support for IE/BA 0.00_19 Sat Jul 28 2007 - 10 in 27 states (37.0%) supported in Business::BR::IE - added support for IE-AM 0.00_18 Sat Jul 28 2007 - 9 in 27 states (33.3%) supported in Business::BR::IE - added support for IE-MG 0.00_17 Tue May 16 2005 (unreleased) - 8 in 27 states (29.6%) supported in Business::BR::IE - added support for IE-AP 0.00_16 Wed Oct 26 2005 - in canon_*(), instead of stripping all non-digits, alphanumeric characters are preserved - canon_ie_*() for each of the 27 states (untested) 0.00_15 Wed Oct 26 2005 - 7 in 27 states (25.9%) supported in Business::BR::IE - added support for IE-RO 0.00_14 Tue Oct 25 2005 - the check equation for IE-AL was wrong: this releases fixes the bug - the problem was test sample too small 0.00_13 Wed Oct 19 2005 - one more id: the PIS number - new files: "lib/Business/BR/PIS.pm" and two tests "t/*_pis_*.t" 0.00_12 Tue Aug 11 2005 - added support for IE-RR - Scalar::Util 1.11 is needed (this is the release which introduces "looks_like_number") 0.00_11 Tue Aug 09 2005 - added support for IE-MA 0.00_10 Sun Jul 17 2005 - 4 in 27 states (14.8%) supported in Business::BR::IE - added support for IE-AL - "t/001_dot.t" now works for other Perls < 5.008 - _dot now deals with untrue's avoiding to do a computation which would throw a warning - _flatten in Business::BR::Ids::Common renamed to _canon_i - references to 'flatten' renamed to 'canon' - test, flatten, parse, format, random in Business::BR::Ids renamed to test_id, flatten_id, parse_id, format_id, random_id: no more issues with clash with core 'format' and functions names are better: not so general and yet short 0.00_09 Sat Jul 16 2005 - new test script "t/014_ie_parse.t" - parse_ie() in Business::BR:IE - tests added for IE-AC (test, flatten, format, random) - support for IE-AC (Acre) - fixed a typo in Business::BR::Biz - "t/007_ids_test.t" now includes testing IE - pale additions to Business::BR::Ids docs 0.00_08 Sat Jul 16 2005 - 0.00_07 was not indexed by CPAN: maybe it was because of files that changed but didn't have their versions incremented - the bug below was fixed by explicit "scalar" conversions - a bug slipped when semantics of _dv_*() changed, allowing to reduce the code of random_*(). But then, instead of knowing only about scalar context, random_*() returned the check digits on list context (like in "print random_cnpj()" 0.00_07 Fri Jul 15 2005 - the IE functions were made case-insensitive ('MG' works the same as 'mg') - added IE handling for PR state (test, flatten, format, random, and parse) - introduced _flatten in Business::BR::Ids::Common, avoiding the redundant code of the various flatten_*() methods - changed semantics of calling _dv_*() in scalar context - instead of returning a concatenation of the check digits, it returns a complete entity with check digits in (in IE-SP the check digits are the ninth and 12nd - so that the concatenation of check digits is good for nothing) 0.00_06 Thu Jul 14 2005 - added tests for Business::BR::IE - added IE handling for SP state (test, flatten, format, and random) 0.00_05 Fri Jun 10 2005 - Deprecates Business::BR::Biz (waiting for the move of its content somewhere else) - README file revised - first revision to POD in Business::BR::CNPJ - new test "t/009_cnpj_rand.t" - random_cnpj() in Business::BR::CNPJ - test scripts renamed (eg. "t/dot.t" to "t/001_dot.t") - random() in Business::BR::Ids - new test "t/008_cpf_rand.t" - random_cpf() in Business::BR::CPF - introduced flatten() and parse() to Business::BR::Ids with a small refactoring avoiding redundant code - fixed synopsis of Business::BR::Ids - test for _dot() with @a < @b now works for $] < 5.8 - fixed broken links at Business::BR, I hope 0.00_04 Thu Jun 9 2005 - I thought about letting MakeMaker generate META.yml automatically again - but it does not generate the 'author' and 'licence' keys which CPAN uses - so I insist on that - distribution renamed to Business-BR-Ids reflecting the orientation of this set of files to deal with identification codes (CPF, CNPJ for now) - added test "t/ids_test.t" - added Business::BR::Ids as a generic entry point for dealing with Brazilian identification entities 0.00_03 Wed Jun 8 2005 - tests "t/*_cpf.t" renamed to "t/cpf_*.t" - added new module Business::BR::CNPJ but POD is not finished and tests aren't provided (except for a partial "t/cnpj_test.t") - the heart of the distribution goes to Business::BR::Biz - "_dot" goes to Business::BR::Biz::Common - the ABSTRACT fix of the previous version was not enough for correct CPAN display - now using a META.yml with 'abstract' key - Adam Kennedy pointed that the general CPAN convention for naming distributions would suggest Business-BR instead of biz-br: I would like to stick to this distribution name to mean a partial bundle of Business::BR::* modules I will be authoring 0.00_02 Tue Jun 7 2005 - fixed the missing ABSTRACT - added flatten_cpf(), format_cpf(), parse_cpf() to Business::BR::CPF - added corresponding tests 0.00_01 Tue Jun 7 2005 - Business::BR::CPF provides test_cpf() - submitted to CPAN 0.01 Tue Jun 7 08:06:16 2005 - original version; created by h2xs 1.23 with options -AX -n biz-br Business-BR-Ids-0.0022/META.yml0000644000175000017500000000102611032441002016021 0ustar ferreiraferreira--- #YAML:1.0 name: Business-BR-Ids version: 0.0022 abstract: Modules for dealing with Brazilian identification codes (CPF, CNPJ, ...) license: perl author: - A. R. Ferreira generated_by: ExtUtils::MakeMaker version 6.44 distribution_type: module requires: Scalar::Util: 1.11 Test::More: 0 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.3.html version: 1.3 Business-BR-Ids-0.0022/MANIFEST0000644000175000017500000000142611032441002015705 0ustar ferreiraferreiraChanges Makefile.PL MANIFEST README lib/Business/BR.pm lib/Business/BR/CPF.pm lib/Business/BR/CNPJ.pm lib/Business/BR/IE.pm lib/Business/BR/PIS.pm lib/Business/BR/Ids.pm lib/Business/BR/Ids/Common.pm lib/Business/BR/Biz.pm DEPRECATED t/001_dot.t t/051_dot_10.t t/002_cpf_test.t t/003_cpf_canon.t t/004_cpf_format.t t/005_cpf_parse.t t/006_cnpj_test.t t/007_ids_test.t t/008_cpf_rand.t t/009_cnpj_rand.t t/010_ie_canon.t t/011_ie_test.t t/012_ie_format.t t/013_ie_rand.t t/014_ie_parse.t t/015_pis_test.t t/016_pis_rand.t #t/017_pis_canon.t #t/018_pis_format.t #t/019_pis_parse.t t/lib/IO/Capture.pm Used in t/001_dot.t to capture STDERR META.yml Module meta-data (added by MakeMaker)