line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TSVRPC::Client; |
2
|
6
|
|
|
6
|
|
32
|
use strict; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
192
|
|
3
|
6
|
|
|
6
|
|
32
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
141
|
|
4
|
6
|
|
|
6
|
|
114
|
use 5.008001; |
|
6
|
|
|
|
|
65
|
|
|
6
|
|
|
|
|
342
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
6
|
6
|
|
|
6
|
|
2982
|
use TSVRPC::Parser; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
299
|
|
7
|
6
|
|
|
6
|
|
2843
|
use TSVRPC::Util; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
187
|
|
8
|
6
|
|
|
6
|
|
9475
|
use Furl::HTTP qw/HEADERS_NONE/; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my $class = shift; |
12
|
|
|
|
|
|
|
my %args = @_==1 ? %{$_[0]} : @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $base = $args{base} or Carp::croak("missing argument named 'base' for rpc base url"); |
15
|
|
|
|
|
|
|
$base .= '/' unless $base =~ m{/$}; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $timeout = exists( $args{timeout} ) ? $args{timeout} : 1; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $agent = $args{agent} || "$class/$VERSION"; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $furl = Furl::HTTP->new( |
22
|
|
|
|
|
|
|
timeout => $timeout, |
23
|
|
|
|
|
|
|
useragent => $agent, |
24
|
|
|
|
|
|
|
header_format => HEADERS_NONE, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
return bless {furl => $furl, base => $base}, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub call { |
31
|
|
|
|
|
|
|
my ( $self, $method, $args, $req_encoding ) = @_; |
32
|
|
|
|
|
|
|
$req_encoding ||= 'B'; # default encoding is base64. because base64 is very fast. |
33
|
|
|
|
|
|
|
my $content = TSVRPC::Parser::encode_tsvrpc($args, $req_encoding); |
34
|
|
|
|
|
|
|
my $furl = $self->{furl}; |
35
|
|
|
|
|
|
|
my %special_headers = ('content-type' => undef); |
36
|
|
|
|
|
|
|
my ( $minor_version, $code, $msg, $headers, $body ) = $furl->request( |
37
|
|
|
|
|
|
|
url => $self->{base} . $method, |
38
|
|
|
|
|
|
|
headers => [ |
39
|
|
|
|
|
|
|
"Content-Type" => "text/tab-separated-values; colenc=$req_encoding", |
40
|
|
|
|
|
|
|
"Content-Length" => length($content), |
41
|
|
|
|
|
|
|
], |
42
|
|
|
|
|
|
|
method => 'POST', |
43
|
|
|
|
|
|
|
content => $content, |
44
|
|
|
|
|
|
|
special_headers => \%special_headers, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
my $decoded_body; |
47
|
|
|
|
|
|
|
if (my $content_type = $special_headers{'content-type'}) { |
48
|
|
|
|
|
|
|
my $res_encoding = TSVRPC::Util::parse_content_type( $content_type ); |
49
|
|
|
|
|
|
|
$decoded_body = defined($res_encoding) ? TSVRPC::Parser::decode_tsvrpc( $body, $res_encoding ) : undef; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
return ($code, $decoded_body, $msg); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
__END__ |