Correios/SRO.pm

filter: Statementstmt 66.2% 49 / 74 Branchbran 36.8% 14 / 38 Conditioncond 30.6% 30 / 98 MC/DCmcdc 4.5% 2 / 44 Subroutinesub 72.7% 8 / 11 Podpod 57.1% 4 / 7 totaltotal 39.3% 107 / 272 SCAR 63.9
CC
56
Cov
44%
nome_do_evento
525.2
sro_ok
30.0
objetos
10.4
CRAP 598.3
↑ Summary Correios.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Net::Correios::SRO;
7  
8 sub new {
9 1 ▶ my ($class, $parent) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
10 1 Scalar::Util::weaken($parent);
11 1 return bless { parent => $parent }, $class;
12 }
13  
14 # minha versão da consulta por SRO ;)
15 sub busca {
16 1 ▶ my ($self, $tipo, @sro) = @_;
Subroutine busca: called CC=6 SCAR=18.1
Pod documented
17  
18 1 ▶ if (length($tipo) > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $tipo > 1) 1 0 1
19 1 unshift @sro, $tipo;
20 1 $tipo = 'T';
21 }
22  
23 1 my $res = $self->objetos( objetos => \@sro, resultado => $tipo );
24 1 my %data;
25 1 foreach my $item (@{$res->{objetos}}) {
26 2 $data{ $item->{codObjeto} } = $item;
27 $data{ $item->{codObjeto} }{situacao} = $tipo eq 'P'
28 ? 'indisponível'
29 : ($item->{mensagem} && $item->{mensagem} =~ /\ASRO-020/) ? 'não encontrado'
30 2 ▶ : $self->nome_do_evento($item->{eventos}[0]{codigo}, $item->{eventos}[0]{tipo});
Branch: 2 branches
BranchTrueFalseTotal
$tipo eq 'P' ? : 0 2 2
$item->{'mensagem'} && $item->{'mensagem'} =~ /\ASRO-020/ ? : 1 1 2
Condition66%2/3
$item->{"mensagem"} and $item->{"mensagem"} =~ /\ASRO-020/
!ll&&!rl&&r
101
MC/DC50%1/2
$item->{"mensagem"} and $item->{"mensagem"} =~ /\ASRO-020/
$item->{"mensagem"} $item->{"mensagem"} =~ /\ASRO-020/
Truth table66%2/3
A and B
A= $item->{"mensagem"}B= $item->{"mensagem"} =~ /\ASRO-020/
ABresult
0X0
100
111
31 }
32 1 return \%data;
33 }
34  
35 sub nome_do_evento {
36 1 ▶ my ($self, $codigo, $tipo) = @_;
Subroutine nome_do_evento: called CC=39 SCAR=62.6
Pod documented
37 1 ▶ return 'indisponivel' unless defined $codigo && defined $tipo;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $codigo and defined $tipo 0 1 1
Condition33%1/3
defined $codigo and defined $tipo
!ll&&!rl&&r
001
MC/DC0%0/2
defined $codigo and defined $tipo
defined $codigo defined $tipo
Truth table33%1/3
A and B
A= defined $codigoB= defined $tipo
ABresult
0X0
100
111
38 1 ▶ if ($codigo eq 'BDR' || $codigo eq 'BDE' || $codigo eq 'BDI') {
Branch: 4 branches
BranchTrueFalseTotal
if ($codigo eq 'BDR' or $codigo eq 'BDE' or $codigo eq 'BDI') { } 1 0 1
elsif ($codigo eq 'FC' and $tipo == 1) { } 0 0 0
elsif ($codigo eq 'OEC' and $tipo == 9) { } 0 0 0
elsif ($codigo eq 'LDI' and $tipo <= 3 || $tipo == 14 or $codigo eq 'OEC' and $tipo == 0) { } 0 0 0
Condition33%2/6
$codigo eq "BDR" or $codigo eq "BDE" or $codigo eq "BDI"
l!l&&r!l&&!r
100
$codigo eq "BDR" or $codigo eq "BDE"
l!l&&r!l&&!r
010
MC/DC0%0/3
$codigo eq "BDR" or $codigo eq "BDE" or $codigo eq "BDI"
$codigo eq "BDR" $codigo eq "BDE" $codigo eq "BDI"
Truth table25%1/4
A or B or C
A= $codigo eq "BDR"B= $codigo eq "BDE"C= $codigo eq "BDI"
ABCresult
1XX1
01X1
0011
0000
39 # estado final. entrega efetuada!
40 1 ▶ return 'entregue' if $tipo <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $tipo <= 1 0 1 1
41  
42 # acionar correios (produto extraviado, etc).
43 1 ▶ return 'erro' if $tipo == 9 || $tipo == 12 || $tipo == 28
Branch: 1 branch
BranchTrueFalseTotal
if $tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43 or $tipo == 50 or $tipo == 51 or $tipo == 52 or $tipo == 80 0 1 1
Condition33%8/24
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43 or $tipo == 50 or $tipo == 51 or $tipo == 52 or $tipo == 80
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43 or $tipo == 50 or $tipo == 51 or $tipo == 52
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43 or $tipo == 50 or $tipo == 51
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43 or $tipo == 50
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12 or $tipo == 28
l!l&&r!l&&!r
001
$tipo == 9 or $tipo == 12
l!l&&r!l&&!r
001
MC/DC0%0/9
$tipo == 9 or $tipo == 12 or $tipo == 28 or $tipo == 37 or $tipo == 43 or $tipo == 50 or $tipo == 51 or $tipo == 52 or $tipo == 80
$tipo == 9 $tipo == 12 $tipo == 28 $tipo == 37 $tipo == 43 $tipo == 50 $tipo == 51 $tipo == 52 $tipo == 80
Truth table10%1/10
A or B or C or D or E or F or G or H or I
A= $tipo == 9B= $tipo == 12C= $tipo == 28D= $tipo == 37E= $tipo == 43F= $tipo == 50G= $tipo == 51H= $tipo == 52I= $tipo == 80
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
44 || $tipo == 37 || $tipo == 43 || $tipo == 50
45 || $tipo == 51 || $tipo == 52 || $tipo == 80
46 ;
47  
48 # pacote aguardando retirada pelo interessado.
49 1 ▶ return 'retirar' if $tipo == 54 || $tipo == 2;
Branch: 1 branch
BranchTrueFalseTotal
if $tipo == 54 or $tipo == 2 0 1 1
Condition33%1/3
$tipo == 54 or $tipo == 2
l!l&&r!l&&!r
001
MC/DC0%0/2
$tipo == 54 or $tipo == 2
$tipo == 54 $tipo == 2
Truth table33%1/3
A or B
A= $tipo == 54B= $tipo == 2
ABresult
1X1
011
000
50  
51 # entrega incompleta, pacote retornando.
52 1 ▶ return 'incompleto'
Branch: 1 branch
BranchTrueFalseTotal
if $tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40 or $tipo == 42 or $tipo == 48 or $tipo == 49 or $tipo == 56 0 1 1
Condition33%10/30
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40 or $tipo == 42 or $tipo == 48 or $tipo == 49 or $tipo == 56
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40 or $tipo == 42 or $tipo == 48 or $tipo == 49
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40 or $tipo == 42 or $tipo == 48
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40 or $tipo == 42
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26
l!l&&r!l&&!r
001
$tipo != 20 and $tipo != 7 and $tipo <= 21
!ll&&!rl&&r
010
$tipo != 20 and $tipo != 7
!ll&&!rl&&r
001
MC/DC0%0/11
$tipo != 20 and $tipo != 7 and $tipo <= 21 or $tipo == 26 or $tipo == 33 or $tipo == 36 or $tipo == 40 or $tipo == 42 or $tipo == 48 or $tipo == 49 or $tipo == 56
$tipo != 20 $tipo != 7 $tipo <= 21 $tipo == 26 $tipo == 33 $tipo == 36 $tipo == 40 $tipo == 42 $tipo == 48 $tipo == 49 $tipo == 56
Truth table3%1/28
A and B and C or D or E or F or G or H or I or J or K
A= $tipo != 20B= $tipo != 7C= $tipo <= 21D= $tipo == 26E= $tipo == 33F= $tipo == 36G= $tipo == 40H= $tipo == 42I= $tipo == 48J= $tipo == 49K= $tipo == 56
ABCDEFGHIJKresult
111XXXXXXXX1
0XX1XXXXXXX1
10X1XXXXXXX1
1101XXXXXXX1
0XX01XXXXXX1
10X01XXXXXX1
11001XXXXXX1
0XX001XXXXX1
10X001XXXXX1
110001XXXXX1
0XX0001XXXX1
10X0001XXXX1
1100001XXXX1
0XX00001XXX1
10X00001XXX1
11000001XXX1
0XX000001XX1
10X000001XX1
110000001XX1
0XX0000001X1
10X0000001X1
1100000001X1
0XX000000011
10X000000011
110000000011
0XX000000000
10X000000000
110000000000
53 if ( ($tipo != 20 && $tipo != 7 && $tipo <= 21)
54 || $tipo == 26 || $tipo == 33 || $tipo == 36
55 || $tipo == 40 || $tipo == 42 || $tipo == 48
56 || $tipo == 49 || $tipo == 56
57 );
58  
59 1 ▶ return 'devolvido' if $tipo == 23;
Branch: 1 branch
BranchTrueFalseTotal
if $tipo == 23 1 0 1
60  
61 0 return 'acompanhar';
62 }
63 ▶ elsif ($codigo eq 'FC' && $tipo == 1) {
Condition0%0/3
$codigo eq "FC" and $tipo == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$codigo eq "FC" and $tipo == 1
$codigo eq "FC" $tipo == 1
Truth table0%0/3
A and B
A= $codigo eq "FC"B= $tipo == 1
ABresult
0X0
100
111
64 0 return 'incompleto';
65 }
66 ▶ elsif ($codigo eq 'OEC' && $tipo == 9) {
Condition0%0/3
$codigo eq "OEC" and $tipo == 9
!ll&&!rl&&r
000
MC/DC0%0/2
$codigo eq "OEC" and $tipo == 9
$codigo eq "OEC" $tipo == 9
Truth table0%0/3
A and B
A= $codigo eq "OEC"B= $tipo == 9
ABresult
0X0
100
111
67 0 return 'incompleto';
68 }
69 ▶ elsif (
Condition0%0/12
$codigo eq "LDI" and $tipo <= 3 || $tipo == 14 or $codigo eq "OEC" and $tipo == 0
l!l&&r!l&&!r
000
$codigo eq "LDI" and $tipo <= 3 || $tipo == 14
!ll&&!rl&&r
000
$tipo <= 3 or $tipo == 14
l!l&&r!l&&!r
000
$codigo eq "OEC" and $tipo == 0
!ll&&!rl&&r
000
MC/DC0%0/5
$codigo eq "LDI" and $tipo <= 3 || $tipo == 14 or $codigo eq "OEC" and $tipo == 0
$codigo eq "LDI" $tipo <= 3 $tipo == 14 $codigo eq "OEC" $tipo == 0
Truth table0%0/8
A and B or C or D and E
A= $codigo eq "LDI"B= $tipo <= 3C= $tipo == 14D= $codigo eq "OEC"E= $tipo == 0
ABCDEresult
11XXX1
101XX1
0XX111
100111
0XX0X0
0XX100
1000X0
100100
70 # pacote aguardando retirada.
71 ($codigo eq 'LDI' && ($tipo <= 3 || $tipo == 14))
72 || ($codigo eq 'OEC' && $tipo == 0)
73 ) {
74 0 return 'retirar';
75 }
76 else {
77 0 return 'acompanhar';
78 }
79 }
80  
81 # http://www.correios.com.br/para-sua-empresa/servicos-para-o-seu-contrato/guias/enderecamento/arquivos/guia_tecnico_encomendas.pdf/at_download/file
82 sub sro_ok {
83 0 ▶ if ( $_[-1] =~ m/^[A-Z|a-z]{2}([0-9]{8})([0-9])BR$/i ) {
Subroutine sro_ok: not called CC=5 SCAR=34.0
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
if ($_[-1] =~ /^[A-Z|a-z]{2}([0-9]{8})([0-9])BR$/i) 0 0 0
84 0 my ( $numeros, $dv ) = ($1, $2);
85 0 my @numeros = split // => $numeros;
86 0 my @magica = ( 8, 6, 4, 2, 3, 5, 9, 7 );
87  
88 0 my $soma = 0;
89 0 foreach ( 0 .. 7 ) {
90 0 $soma += ( $numeros[$_] * $magica[$_] );
91 }
92  
93 0 my $resto = $soma % 11;
94 0 ▶ my $dv_check = $resto == 0 ? 5
Branch: 2 branches
BranchTrueFalseTotal
$resto == 0 ? : 0 0 0
$resto == 1 ? : 0 0 0
95 : $resto == 1 ? 0
96 : 11 - $resto
97 ;
98 0 return $dv == $dv_check;
99 }
100 0 return;
101 }
102  
103 sub objetos {
104 2 ▶ my ($self, %args) = @_;
Subroutine objetos: called CC=9 SCAR=23.4
Pod documented
105  
106 2 my @codes;
107 2 foreach my $code (@{$args{objetos}}) {
108 4 ▶ die "código SRO '$code' é inválido" unless defined $code && length($code) == 13;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code and length $code == 13 0 4 4
Condition33%1/3
defined $code and length $code == 13
!ll&&!rl&&r
004
MC/DC0%0/2
defined $code and length $code == 13
defined $code length $code == 13
Truth table33%1/3
A and B
A= defined $codeB= length $code == 13
ABresult
0X0
100
111
109 4 push @codes, uc($code);
110 }
111 2 ▶ die "pelo menos 1 objeto é necessário para consulta" unless @codes;
Branch: 1 branch
BranchTrueFalseTotal
unless @codes 0 2 2
112 2 ▶ my $tipo = $args{resultado} || 'U';
Condition100%2/2
$args{'resultado'} || 'U'
l!l
11
MC/DC100%1/1
$args{'resultado'} || 'U'
$args{'resultado'}
Truth table100%2/2
A
A= $args{'resultado'}
Aresult
11
00
113 2 ▶ die "resultado precisa ser 'U' (último), 'P' (primeiro) ou 'T' (todos)"
Branch: 1 branch
BranchTrueFalseTotal
unless $tipo eq "T" or $tipo eq "U" or $tipo eq "P" 0 2 2
Condition50%3/6
$tipo eq "T" or $tipo eq "U" or $tipo eq "P"
l!l&&r!l&&!r
200
$tipo eq "T" or $tipo eq "U"
l!l&&r!l&&!r
110
MC/DC0%0/3
$tipo eq "T" or $tipo eq "U" or $tipo eq "P"
$tipo eq "T" $tipo eq "U" $tipo eq "P"
Truth table50%2/4
A or B or C
A= $tipo eq "T"B= $tipo eq "U"C= $tipo eq "P"
ABCresult
1XX1
01X1
0011
0000
114 unless $tipo eq 'T' || $tipo eq 'U' || $tipo eq 'P';
115  
116 2 my $query_string = 'codigosObjetos=' . join('&codigosObjetos=', @codes)
117 . '&resultado=' . $tipo;
118  
119 2 my $url = 'srorastro/v1/objetos?' . $query_string;
120 2 my $parent = $self->{parent};
121  
122 2 my $res = $parent->make_request('cartao', 'GET', $url);
123  
124 2 return $parent->parse_response($res);
125 }
126  
127 sub imagens {
128 0 ▶ my ($self, @codes) = @_;
Subroutine imagens: not called CC=1 SCAR=6.9
Pod undocumented
129 0 my $parent = $self->{parent};
130  
131 0 my $body = '[' . join(',', map qq("$_"), @codes) . ']';
132  
133 0 my $res = $parent->make_request(
134 'cartao',
135 'POST',
136 'srorastro/v1/objetos/imagens',
137 { content => '[' . join(',', map qq("$_"), @codes) . ']' }
138 );
139 0 return $parent->parse_response($res);
140 }
141  
142 sub recibo {
143 0 ▶ my ($self, $recibo) = @_;
Subroutine recibo: not called CC=1 SCAR=6.9
Pod undocumented
144 0 my $parent = $self->{parent};
145  
146 0 my $res = $parent->make_request('cartao', 'GET', 'srorastro/v1/recibo/' . $recibo);
147 0 return $parent->parse_response($res);
148 }
149  
150 1 1;
151 __END__
↑ Summary Correios.pm »