line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
14240
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
3
|
|
|
|
|
|
|
package WWW::REST::Simple; |
4
|
1
|
|
|
1
|
|
1581
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
51256
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
11
|
use URI; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
828
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
5
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: turns baubles into trinkets |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
40
|
use base 'Exporter'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
445
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw/get post/; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub get { |
16
|
0
|
0
|
|
0
|
0
|
|
die "At least an url is needed!" if @_ < 1; |
17
|
0
|
|
|
|
|
|
_send_request('GET', @_); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub post { |
21
|
0
|
0
|
|
0
|
0
|
|
die "At least an url is needed!" if @_ < 1; |
22
|
0
|
|
|
|
|
|
_send_request('POST', @_); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _send_request { |
26
|
0
|
|
|
0
|
|
|
my ($method, $url, $args) = @_; |
27
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 }); |
28
|
0
|
|
|
|
|
|
$ua->timeout(20); |
29
|
0
|
|
|
|
|
|
$url = URI->new($url); |
30
|
0
|
0
|
|
|
|
|
$url->query_form(%$args) if $method eq 'GET'; |
31
|
0
|
|
|
|
|
|
my $request = new HTTP::Request( $method => $url ); |
32
|
0
|
0
|
|
|
|
|
$request->content($args) if $method eq 'POST'; |
33
|
0
|
|
|
|
|
|
my $resp = $ua->request( $request ); |
34
|
0
|
0
|
|
|
|
|
$resp->is_success ? $resp->content : $resp->status_line; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |