line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
27096
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
3
|
|
|
|
|
|
|
package WWW::REST::Simple; |
4
|
1
|
|
|
1
|
|
944
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
57308
|
|
|
1
|
|
|
|
|
46
|
|
5
|
1
|
|
|
1
|
|
221
|
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 method |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use base 'Exporter'; |
13
|
|
|
|
|
|
|
our @EXPORT = qw/get post/; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.004'; |
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, $header) = @_; |
29
|
|
|
|
|
|
|
$args ||= {}; |
30
|
|
|
|
|
|
|
$header ||= {}; |
31
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 }); |
32
|
|
|
|
|
|
|
$ua->timeout(10); |
33
|
|
|
|
|
|
|
$url = URI->new($url); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $resp = do { |
36
|
|
|
|
|
|
|
if ($method eq 'GET') { |
37
|
|
|
|
|
|
|
$url->query_form(%$args); |
38
|
|
|
|
|
|
|
$ua->request( GET $url, %$header); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
|
|
|
|
|
|
$ua->request( POST $url, %$header, Content => $args ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$resp->is_success ? $resp->content : $resp->status_line; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |