line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eixo::Rest::Request; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1000
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
75
|
|
4
|
3
|
|
|
3
|
|
10
|
use Eixo::Base::Clase; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
196
|
use Attribute::Handlers; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
14
|
|
7
|
3
|
|
|
3
|
|
54
|
use Carp; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
819
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
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
|
7
|
|
|
7
|
0
|
8
|
my ($self) = @_; |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
|
|
8
|
$self->{buffer} = ''; # truncate the buffer |
27
|
|
|
|
|
|
|
|
28
|
7
|
50
|
|
|
|
20
|
if($self->onStart){ |
29
|
0
|
|
|
|
|
0
|
$self->onStart->(); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub end{ |
34
|
|
|
|
|
|
|
|
35
|
7
|
|
|
7
|
0
|
13
|
my ($self, $response) = @_; |
36
|
|
|
|
|
|
|
|
37
|
7
|
|
|
|
|
28
|
my $content = $self->unmarshall($response); |
38
|
|
|
|
|
|
|
|
39
|
7
|
|
|
|
|
41
|
&{$self->onSuccess}( |
|
7
|
|
|
|
|
3351
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->callback->($content, $self), |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$content |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub error{ |
50
|
0
|
|
|
0
|
0
|
0
|
my ($self, $response) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
&{$self->onError}($response); |
|
0
|
|
|
|
|
0
|
|
53
|
|
|
|
|
|
|
# $response->code, |
54
|
|
|
|
|
|
|
# $response->content, |
55
|
|
|
|
|
|
|
# ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub progress{ |
60
|
0
|
|
|
0
|
0
|
0
|
my ($self, $chunk, $req) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$self->buffer($self->buffer . $chunk); |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
0
|
$self->onProgress->($chunk, $req) if($self->onProgress); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
0
|
0
|
sub process {die ref($_[0]) . "::process: MUST BE DEFINED"} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
0
|
0
|
sub send {die ref($_[0]) . "::send: MUST BE DEFINED"} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub unmarshall{ |
72
|
7
|
|
|
7
|
0
|
7
|
my ($self, $response) = @_; |
73
|
|
|
|
|
|
|
|
74
|
7
|
|
|
|
|
43
|
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
|
50
|
|
|
|
4984
|
if($response->content_type eq 'application/json'){ |
82
|
3
|
|
|
3
|
|
1408
|
use Encode; |
|
3
|
|
|
|
|
19345
|
|
|
3
|
|
|
|
|
308
|
|
83
|
0
|
|
|
|
|
0
|
$content = Encode::decode('UTF-8', $content); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
7
|
100
|
|
|
|
161
|
if($self->__format eq 'json'){ |
87
|
|
|
|
|
|
|
|
88
|
5
|
|
50
|
|
|
135
|
return JSON->new->decode($content || '{}') |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else{ |
91
|
2
|
|
|
|
|
22
|
return $content; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |