line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
6
|
use Scalar::Util; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
4
|
1
|
|
|
1
|
|
7
|
use JSON (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
622
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Correios::Prazo; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
1
|
|
|
1
|
0
|
3
|
my ($class, $parent) = @_; |
10
|
1
|
|
|
|
|
4
|
Scalar::Util::weaken($parent); |
11
|
1
|
|
|
|
|
10
|
return bless { parent => $parent }, $class; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub nacional { |
15
|
2
|
|
|
2
|
0
|
2135
|
my ($self, @args) = @_; |
16
|
2
|
50
|
|
|
|
7
|
die 'nacional() espera uma sequencia de parametros' unless @args; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
3
|
my $args; |
19
|
2
|
100
|
|
|
|
6
|
if (ref $args[0] eq 'HASH') { |
20
|
1
|
|
|
|
|
4
|
$args = $self->_parse_nacional(@args); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
1
|
|
|
|
|
3
|
$args = {@args}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
4
|
my $parent = $self->{parent}; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# DOC-PATCH: as chamadas à API de prazo exigem número de cartao. |
29
|
2
|
|
|
|
|
25
|
my $raw = $parent->make_request( |
30
|
|
|
|
|
|
|
'cartao', |
31
|
|
|
|
|
|
|
'POST', |
32
|
|
|
|
|
|
|
'prazo/v1/nacional', |
33
|
|
|
|
|
|
|
{ content => JSON::encode_json($args) } |
34
|
|
|
|
|
|
|
); |
35
|
2
|
|
|
|
|
10
|
my $res = $parent->parse_response($raw); |
36
|
2
|
|
|
|
|
5
|
foreach my $r (@$res) { |
37
|
2
|
|
|
|
|
5
|
$r->{codigo} = $r->{coProduto}; |
38
|
2
|
|
|
|
|
5
|
$r->{dias} = $r->{prazoEntrega}; |
39
|
2
|
|
|
|
|
7
|
my ($data, $hora) = split /T/, $r->{dataMaxima}; |
40
|
2
|
|
|
|
|
5
|
$r->{data_maxima} = $data; |
41
|
|
|
|
|
|
|
} |
42
|
2
|
|
|
|
|
10
|
return $res; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _parse_nacional { |
46
|
1
|
|
|
1
|
|
2
|
my ($self, @args) = @_; |
47
|
1
|
|
|
|
|
3
|
my $n = 1; |
48
|
1
|
|
|
|
|
3
|
my %req = ( idLote => 1, parametrosPrazo => [] ); |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
|
|
|
2
|
foreach my $arg (@args) { |
51
|
1
|
|
|
|
|
2
|
my $cep_origem = $arg->{cep_origem}; |
52
|
1
|
|
|
|
|
6
|
$cep_origem =~ s/[\.\-]+//g; |
53
|
1
|
|
|
|
|
3
|
my $cep_destino = $arg->{cep_destino}; |
54
|
1
|
|
|
|
|
4
|
$cep_destino =~ s/[\.\-]+//g; |
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
5
|
foreach my $servico (split /\s*,\s*/ => $arg->{codigo}) { |
57
|
|
|
|
|
|
|
my $params = { |
58
|
|
|
|
|
|
|
nuRequisicao => $n++, |
59
|
|
|
|
|
|
|
coProduto => $servico, |
60
|
|
|
|
|
|
|
cepOrigem => $cep_origem, |
61
|
|
|
|
|
|
|
cepDestino => $cep_destino, |
62
|
2
|
50
|
|
|
|
8
|
($arg->{data} ? (dtEvento => $arg->{data}) : ()), |
63
|
|
|
|
|
|
|
}; |
64
|
2
|
|
|
|
|
5
|
push @{$req{parametrosPrazo}}, $params; |
|
2
|
|
|
|
|
5
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
1
|
|
|
|
|
3
|
return \%req; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |