| 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 JSON (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Net::Correios::Token; | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 9 | 4 | my ($class, $parent) = @_; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 4 | Scalar::Util::weaken($parent); | |||||||||||||||||||||||||||
| 12 | 4 | return bless { parent => $parent }, $class; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | sub autentica { | ||||||||||||||||||||||||||
|
Subroutine
autentica: called CC=7 SCAR=22.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 4 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 17 | 4 | my $parent = $self->{parent}; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | my $endpoint_url = $parent->{base_url} . 'token/v1/autentica'; | |||||||||||||||||||||||||||
| 20 | 4 | my $json_body; | |||||||||||||||||||||||||||
| 21 | # TODO: precisamos entender quais endpoints funcionam com quais tokens. | ||||||||||||||||||||||||||||
| 22 | # muito provavelmente precisaremos de ambos ao mesmo tempo. | ||||||||||||||||||||||||||||
| 23 | 4 | ▶ | if ($args{contrato}) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 24 | 0 | $endpoint_url .= '/contrato'; | |||||||||||||||||||||||||||
| 25 | 0 | $json_body = JSON::encode_json({ numero => $args{contrato} }); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | elsif ($args{cartao}) { | ||||||||||||||||||||||||||||
| 28 | 3 | $endpoint_url .= '/cartaopostagem'; | |||||||||||||||||||||||||||
| 29 | 3 | $json_body = JSON::encode_json({ numero => $args{cartao} }); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | my $res = $parent->{agent}->request( | ||||||||||||||||||||||||||||
| 33 | 'POST', | ||||||||||||||||||||||||||||
| 34 | $endpoint_url, | ||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | headers => { 'Authorization' => 'Basic ' . $parent->{auth_basic} }, | ||||||||||||||||||||||||||||
| 37 | 4 | ▶ | (defined $json_body? (content => $json_body) : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | 4 | ▶ | if ($parent->{debug}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | $parent->_debug( | ||||||||||||||||||||||||||||
| 42 | "curl -X POST '$endpoint_url' -H 'accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Basic $parent->{auth_basic}' " . ((defined $json_body && length($json_body)) ? ("-d '" . $json_body . "'") : ''), | ||||||||||||||||||||||||||||
| 43 | "Response: " . $res->{status} . "\n" . $res->{content} | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $json_body and length $json_body
MC/DC0%0/2
defined $json_body and length $json_body
defined $json_body
length $json_body
Truth table0%0/3
A and B
A= defined $json_bodyB= length $json_body
| |||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 4 | return $parent->parse_response($res); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | 1; | |||||||||||||||||||||||||||