| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
1
|
|
|
1
|
|
15638
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
3
|
|
|
|
|
|
|
package WWW::REST::Simple; |
|
4
|
1
|
|
|
1
|
|
633
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
35251
|
|
|
|
1
|
|
|
|
|
30
|
|
|
5
|
1
|
|
|
1
|
|
201
|
use LWP::Protocol::https; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use HTTP::Request::Common; |
|
7
|
|
|
|
|
|
|
use URI; |
|
8
|
|
|
|
|
|
|
use utf8; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ABSTRACT: Just provides GET and POST http methods |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use base 'Exporter'; |
|
13
|
|
|
|
|
|
|
our @EXPORT = qw/get post/; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get { |
|
18
|
|
|
|
|
|
|
die "At least a url is needed!" if @_ < 1; |
|
19
|
|
|
|
|
|
|
_send_request('GET', @_); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub post { |
|
23
|
|
|
|
|
|
|
die "At least a url is needed!" if @_ < 1; |
|
24
|
|
|
|
|
|
|
_send_request('POST', @_); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _send_request { |
|
28
|
|
|
|
|
|
|
my ($method, $url, $args) = @_; |
|
29
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 }); |
|
30
|
|
|
|
|
|
|
$ua->timeout(20); |
|
31
|
|
|
|
|
|
|
$url = URI->new($url); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $resp = do { |
|
34
|
|
|
|
|
|
|
if ($method eq 'GET') { |
|
35
|
|
|
|
|
|
|
$url->query_form(%$args); |
|
36
|
|
|
|
|
|
|
$ua->request( GET $url ); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
else { |
|
39
|
|
|
|
|
|
|
$ua->request( POST $url, $args ); |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$resp->is_success ? $resp->content : $resp->status_line; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |