line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package WWW::Kickstarter::HttpClient::Lwp; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5040
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
6
|
1
|
|
|
1
|
|
6
|
no autovivification; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
677
|
use HTTP::Headers qw( ); |
|
1
|
|
|
|
|
8789
|
|
|
1
|
|
|
|
|
34
|
|
10
|
1
|
|
|
1
|
|
493
|
use HTTP::Request::Common qw( GET POST ); |
|
1
|
|
|
|
|
10807
|
|
|
1
|
|
|
|
|
71
|
|
11
|
1
|
|
|
1
|
|
528
|
use LWP::Protocol::https qw( ); |
|
1
|
|
|
|
|
122037
|
|
|
1
|
|
|
|
|
41
|
|
12
|
1
|
|
|
1
|
|
660
|
use LWP::UserAgent qw( ); |
|
1
|
|
|
|
|
13730
|
|
|
1
|
|
|
|
|
39
|
|
13
|
1
|
|
|
1
|
|
8
|
use WWW::Kickstarter::Error qw( my_croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
389
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
0
|
|
|
0
|
0
|
|
my ($class, %opts) = @_; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $agent = delete($opts{agent}); |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
if (my @unrecognized = keys(%opts)) { |
22
|
0
|
|
|
|
|
|
my_croak(400, "Unrecognized parameters @unrecognized"); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $http_client = LWP::UserAgent->new( |
26
|
|
|
|
|
|
|
default_headers => HTTP::Headers->new( |
27
|
|
|
|
|
|
|
Accept => 'application/json; charset=utf-8', |
28
|
|
|
|
|
|
|
), |
29
|
|
|
|
|
|
|
env_proxy => 1, |
30
|
|
|
|
|
|
|
); |
31
|
0
|
0
|
|
|
|
|
$http_client->agent($agent) if $agent; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $self = bless({}, $class); |
34
|
0
|
|
|
|
|
|
$self->{http_client} = $http_client; |
35
|
0
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub request { |
40
|
0
|
|
|
0
|
0
|
|
my ($self, $method, $url, $req_content) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $http_request; |
43
|
0
|
0
|
|
|
|
|
if ($method eq 'GET' ) { |
|
|
0
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$http_request = GET($url); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
elsif ($method eq 'POST') { |
47
|
0
|
|
|
|
|
|
$http_request = POST($url, |
48
|
|
|
|
|
|
|
Content_Length => length($req_content), |
49
|
|
|
|
|
|
|
Content_Type => 'application/x-www-form-urlencoded', |
50
|
|
|
|
|
|
|
Content => $req_content, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
else { |
54
|
0
|
|
|
|
|
|
my_croak(400, "Unexpected argument"); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $http_response = $self->{http_client}->request($http_request); |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $status_code = $http_response->code(); |
60
|
0
|
|
|
|
|
|
my $status_line = $http_response->status_line(); |
61
|
0
|
|
|
|
|
|
my $content_type = $http_response->content_type(); # Lowercase with "parameters" filtered out. |
62
|
0
|
|
|
|
|
|
my $content_encoding = $http_response->content_type_charset(); |
63
|
0
|
|
|
|
|
|
my $content = $http_response->decoded_content( charset => 'none' ); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return ( $status_code, $status_line, $content_type, $content_encoding, $content ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |