| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package XCAP::Client::Connection; |
|
3
|
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
81327
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use LWP::UserAgent; |
|
7
|
|
|
|
|
|
|
use URI::Split qw(uri_split); |
|
8
|
|
|
|
|
|
|
use HTTP::Status qw(:constants status_message); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has ['uri', 'auth_realm', 'auth_username','auth_password', 'content'] => ( |
|
11
|
|
|
|
|
|
|
is => 'rw', |
|
12
|
|
|
|
|
|
|
isa => 'Str' |
|
13
|
|
|
|
|
|
|
); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has 'useragent' => ( |
|
16
|
|
|
|
|
|
|
is => 'rw', |
|
17
|
|
|
|
|
|
|
isa => 'Object', |
|
18
|
|
|
|
|
|
|
lazy => 1, |
|
19
|
|
|
|
|
|
|
default => sub { LWP::UserAgent->new(agent => 'XCAP::Client') } |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'netloc' => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
isa => 'Str', |
|
25
|
|
|
|
|
|
|
lazy => 1, |
|
26
|
|
|
|
|
|
|
default => sub { |
|
27
|
|
|
|
|
|
|
my $self = shift; |
|
28
|
|
|
|
|
|
|
my ($scheme, $auth) = uri_split($self->uri); |
|
29
|
|
|
|
|
|
|
$auth; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _http_response_code () { |
|
34
|
|
|
|
|
|
|
my ($self, $method, $code) = @_; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# HTTP_CONFLICT - RFC 4825 - Section 11. |
|
37
|
|
|
|
|
|
|
return 0 if $code == HTTP_OK || $code == HTTP_CONFLICT; |
|
38
|
|
|
|
|
|
|
return 0 if $code == HTTP_CREATED && $method eq 'PUT'; |
|
39
|
|
|
|
|
|
|
die status_message($code); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _request () { |
|
43
|
|
|
|
|
|
|
my ($self, $method) = @_; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$self->useragent->credentials($self->netloc, $self->auth_realm, |
|
46
|
|
|
|
|
|
|
$self->auth_username, $self->auth_password); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $request = new HTTP::Request($method => $self->uri); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
if ($method eq 'PUT') { |
|
51
|
|
|
|
|
|
|
$request->header('content-length' => length($self->content)); |
|
52
|
|
|
|
|
|
|
$request->content($self->content); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $response = $self->useragent->request($request); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$self->_http_response_code($method,$response->code) |
|
58
|
|
|
|
|
|
|
if $method ne "DELETE"; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
return ($method eq 'GET' || $response->code == HTTP_CONFLICT) |
|
61
|
|
|
|
|
|
|
? $response->content : $response->code; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get { $_[0]->_request('GET'); } |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub delete { $_[0]->_request('DELETE'); } |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub put { $_[0]->_request('PUT'); } |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |
|
74
|
|
|
|
|
|
|
|