| 1 | package Eixo::Rest::Request; | ||||||||||||
| 2 | |||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | ▶ | use Eixo::Base::Clase; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 3 | ▶ | use Attribute::Handlers; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | has ( | |||||||||||
| 10 | callback=>undef, | ||||||||||||
| 11 | |||||||||||||
| 12 | onProgress => undef, | ||||||||||||
| 13 | onSuccess => undef, | ||||||||||||
| 14 | onError => undef, | ||||||||||||
| 15 | onStart => undef, | ||||||||||||
| 16 | |||||||||||||
| 17 | __format=>'json', | ||||||||||||
| 18 | |||||||||||||
| 19 | buffer=>'', | ||||||||||||
| 20 | |||||||||||||
| 21 | ); | ||||||||||||
| 22 | |||||||||||||
| 23 | 7 | ▶ | sub start{ | ||||||||||
|
Subroutine
start: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||
| 24 | 7 | my ($self) = @_; | |||||||||||
| 25 | |||||||||||||
| 26 | 7 | $self->{buffer} = ''; # truncate the buffer | |||||||||||
| 27 | |||||||||||||
| 28 | 7 | ▶ | if($self->onStart){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | $self->onStart->(); | |||||||||||
| 30 | } | ||||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | 7 | ▶ | sub end{ | ||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 34 | |||||||||||||
| 35 | 7 | my ($self, $response) = @_; | |||||||||||
| 36 | |||||||||||||
| 37 | 7 | my $content = $self->unmarshall($response); | |||||||||||
| 38 | |||||||||||||
| 39 | 7 | &{$self->onSuccess}( | |||||||||||
| 40 | |||||||||||||
| 41 | $self->callback->($content, $self), | ||||||||||||
| 42 | |||||||||||||
| 43 | $content | ||||||||||||
| 44 | |||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 0 | ▶ | sub error{ | ||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 50 | 0 | my ($self, $response) = @_; | |||||||||||
| 51 | |||||||||||||
| 52 | 0 | &{$self->onError}($response); | |||||||||||
| 53 | # $response->code, | ||||||||||||
| 54 | # $response->content, | ||||||||||||
| 55 | # ); | ||||||||||||
| 56 | |||||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | 0 | ▶ | sub progress{ | ||||||||||
|
Subroutine
progress: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 60 | 0 | my ($self, $chunk, $req) = @_; | |||||||||||
| 61 | |||||||||||||
| 62 | 0 | $self->buffer($self->buffer . $chunk); | |||||||||||
| 63 | |||||||||||||
| 64 | 0 | ▶ | $self->onProgress->($chunk, $req) if($self->onProgress); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | 0 | ▶ | sub process {die ref($_[0]) . "::process: MUST BE DEFINED"} | ||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 68 | |||||||||||||
| 69 | 0 | ▶ | sub send {die ref($_[0]) . "::send: MUST BE DEFINED"} | ||||||||||
|
Subroutine
send: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 70 | |||||||||||||
| 71 | 7 | ▶ | sub unmarshall{ | ||||||||||
|
Subroutine
unmarshall: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||
| 72 | 7 | my ($self, $response) = @_; | |||||||||||
| 73 | |||||||||||||
| 74 | 7 | my $content = $response->decoded_content( | |||||||||||
| 75 | default_charset=> 'UTF-8' | ||||||||||||
| 76 | ); | ||||||||||||
| 77 | |||||||||||||
| 78 | # nowadays (HTTP::Message v6.11) | ||||||||||||
| 79 | # decoded_content isn't decoding utf8 charset | ||||||||||||
| 80 | # if content_type is application/json | ||||||||||||
| 81 | 7 | ▶ | if($response->content_type eq 'application/json'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 3 | ▶ | use Encode; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 83 | 0 | $content = Encode::decode('UTF-8', $content); | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 7 | ▶ | if($self->__format eq 'json'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | |||||||||||||
| 88 | 5 | ▶ | return JSON->new->decode($content || '{}') | ||||||||||
|
Condition50%1/2
$content || '{}'
MC/DC0%0/1
$content || '{}'
$content
Truth table50%1/2
A
A= $content
| |||||||||||||
| 89 | } | ||||||||||||
| 90 | else{ | ||||||||||||
| 91 | 2 | return $content; | |||||||||||
| 92 | } | ||||||||||||
| 93 | } | ||||||||||||
| 94 | |||||||||||||
| 95 | |||||||||||||
| 96 | |||||||||||||
| 97 | 3 | 1; | |||||||||||