| 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 | sub start{ | ||||||||||||
| 24 | 5 | ▶ | my ($self) = @_; | ||||||||||
|
Subroutine
start: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||
| 25 | |||||||||||||
| 26 | 5 | $self->{buffer} = ''; # truncate the buffer | |||||||||||
| 27 | |||||||||||||
| 28 | 5 | ▶ | if($self->onStart){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 0 | $self->onStart->(); | |||||||||||
| 30 | } | ||||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | sub end{ | ||||||||||||
| 34 | |||||||||||||
| 35 | 4 | ▶ | my ($self, $response) = @_; | ||||||||||
|
Subroutine
end: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 36 | |||||||||||||
| 37 | 4 | my $content = $self->unmarshall($response); | |||||||||||
| 38 | |||||||||||||
| 39 | 4 | &{$self->onSuccess}( | |||||||||||
| 40 | |||||||||||||
| 41 | $self->callback->($content, $self), | ||||||||||||
| 42 | |||||||||||||
| 43 | $content | ||||||||||||
| 44 | |||||||||||||
| 45 | ); | ||||||||||||
| 46 | |||||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | sub error{ | ||||||||||||
| 50 | 1 | ▶ | my ($self, $response) = @_; | ||||||||||
|
Subroutine
error: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||
| 51 | |||||||||||||
| 52 | 1 | &{$self->onError}($response); | |||||||||||
| 53 | # $response->code, | ||||||||||||
| 54 | # $response->content, | ||||||||||||
| 55 | # ); | ||||||||||||
| 56 | |||||||||||||
| 57 | } | ||||||||||||
| 58 | |||||||||||||
| 59 | sub progress{ | ||||||||||||
| 60 | 0 | ▶ | my ($self, $chunk, $req) = @_; | ||||||||||
|
Subroutine
progress: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 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 | sub unmarshall{ | ||||||||||||
| 72 | 4 | ▶ | my ($self, $response) = @_; | ||||||||||
|
Subroutine
unmarshall: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||
| 73 | |||||||||||||
| 74 | 4 | my $content = $response->content; | |||||||||||
| 75 | |||||||||||||
| 76 | |||||||||||||
| 77 | 4 | ▶ | if($self->__format eq 'json'){ | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | |||||||||||||
| 79 | 3 | ▶ | return JSON->new->utf8->decode($content || '{}') | ||||||||||
|
Condition50%1/2
$content || '{}'
MC/DC0%0/1
$content || '{}'
$content
Truth table50%1/2
A
A= $content
| |||||||||||||
| 80 | } | ||||||||||||
| 81 | else{ | ||||||||||||
| 82 | 1 | return $content; | |||||||||||
| 83 | } | ||||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | |||||||||||||
| 87 | |||||||||||||
| 88 | 3 | 1; | |||||||||||