line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Rest::Generic::Utility; |
2
|
|
|
|
|
|
|
|
3
|
7
|
|
|
7
|
|
106
|
use 5.006; |
|
7
|
|
|
|
|
22
|
|
|
7
|
|
|
|
|
248
|
|
4
|
7
|
|
|
7
|
|
41
|
use strict; |
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
237
|
|
5
|
7
|
|
|
7
|
|
37
|
use warnings FATAL => 'all'; |
|
7
|
|
|
|
|
29
|
|
|
7
|
|
|
|
|
218
|
|
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
13482
|
use LWP::UserAgent; |
|
7
|
|
|
|
|
274231
|
|
|
7
|
|
|
|
|
247
|
|
8
|
7
|
|
|
7
|
|
8274
|
use HTTP::Request::Common; |
|
7
|
|
|
|
|
16322
|
|
|
7
|
|
|
|
|
2283
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Net::Rest::Generic::Utility - Utility methods for arbitrary api functionality |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _doRestCall { |
17
|
2
|
|
|
2
|
|
5
|
my ($api, $method, $url, $args) = @_; |
18
|
2
|
|
|
|
|
6
|
$method = uc($method); |
19
|
2
|
|
50
|
|
|
13
|
$args ||= {}; |
20
|
2
|
100
|
66
|
|
|
14
|
if ($api->{useragent_options} && ref($api->{useragent_options}) eq 'HASH') { |
21
|
1
|
|
33
|
|
|
7
|
$api->{ua} ||= LWP::UserAgent->new(%{$api->{useragent_options}}); |
|
1
|
|
|
|
|
10
|
|
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
else { |
24
|
1
|
|
33
|
|
|
16
|
$api->{ua} ||= LWP::UserAgent->new(); |
25
|
|
|
|
|
|
|
} |
26
|
2
|
|
|
|
|
8313
|
my ($request, @params) = _generateRequest($api, $method, $url, $args); |
27
|
2
|
|
|
|
|
11
|
$api->{ua}->request( $request, @params ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _generateRequest { |
31
|
3
|
|
|
3
|
|
3876
|
my ($api, $method, $url, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
9
|
my $ua = $api->{ua}; |
34
|
3
|
|
|
|
|
7
|
my @parameters = ($url, %{$api->{_params}}, %{$args}); |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
10
|
|
35
|
3
|
|
|
|
|
6
|
my $parameterOffset; |
36
|
3
|
50
|
33
|
|
|
132
|
if ($method eq 'PUT'||$method eq 'POST') { |
37
|
3
|
50
|
|
|
|
15
|
$parameterOffset = ref($parameters[1])? 2 : 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
else { |
40
|
0
|
|
|
|
|
0
|
$parameterOffset = 1; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
3
|
|
|
|
|
18
|
my @stuff = $ua->_process_colonic_headers(\@parameters, 0); |
44
|
|
|
|
|
|
|
{ |
45
|
7
|
|
|
7
|
|
57
|
no strict qw(refs); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
950
|
|
|
3
|
|
|
|
|
84
|
|
46
|
3
|
|
|
|
|
9
|
my $request = &{"HTTP::Request::Common::${method}"}( @parameters ); |
|
3
|
|
|
|
|
29
|
|
47
|
3
|
50
|
|
|
|
1208
|
$request->authorization_basic( |
48
|
|
|
|
|
|
|
$api->{authorization_basic}{username}, |
49
|
|
|
|
|
|
|
$api->{authorization_basic}{password} |
50
|
|
|
|
|
|
|
) if $api->{authorization_basic}{username}; |
51
|
3
|
100
|
|
|
|
30
|
$request->content($api->{request_content}) if $api->{request_content}; |
52
|
|
|
|
|
|
|
|
53
|
3
|
|
|
|
|
40
|
return ($request, @stuff); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |