line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Protocol::XMLRPC::Client; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
25204
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
654
|
use Protocol::XMLRPC::MethodCall; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Protocol::XMLRPC::MethodResponse; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Carp; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
|
|
|
|
|
|
my $class = shift; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self = {@_}; |
15
|
|
|
|
|
|
|
bless $self, $class; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Carp::croak('http_req_cb is required') unless $self->{http_req_cb}; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub http_req_cb { |
23
|
|
|
|
|
|
|
defined $_[1] ? $_[0]->{http_req_cb} = $_[1] : $_[0]->{http_req_cb}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub call { |
27
|
|
|
|
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
my ($url, $method_name, $args, $cb, $error_cb) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
if (!defined $cb) { |
31
|
|
|
|
|
|
|
($cb, $args) = ($args, []); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif (ref($args) ne 'ARRAY' && !defined $error_cb) { |
34
|
|
|
|
|
|
|
($cb, $error_cb, $args) = ($args, $cb, []); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $method_call = Protocol::XMLRPC::MethodCall->new(name => $method_name); |
38
|
|
|
|
|
|
|
foreach my $arg (@$args) { |
39
|
|
|
|
|
|
|
$method_call->add_param($arg); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $host = $url; |
43
|
|
|
|
|
|
|
$host =~ s|^http(s)?://||; |
44
|
|
|
|
|
|
|
$host =~ s|/.*$||; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $headers = { |
47
|
|
|
|
|
|
|
'Content-Type' => 'text/xml', |
48
|
|
|
|
|
|
|
'User-Agent' => 'Protocol-XMLRPC (Perl)', |
49
|
|
|
|
|
|
|
'Host' => $host |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->http_req_cb->( |
53
|
|
|
|
|
|
|
$self, $url, 'POST', $headers, "$method_call" => |
54
|
|
|
|
|
|
|
sub { |
55
|
|
|
|
|
|
|
my ($self, $status, $headers, $body) = @_; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
unless ($status && $status == 200) { |
58
|
|
|
|
|
|
|
return $error_cb ? $error_cb->($self) : $cb->($self); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $res = Protocol::XMLRPC::MethodResponse->parse($body); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return $cb->($self, $res) if $res; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
return $error_cb ? $error_cb->($self) : $cb->($self); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |