line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Zemanta::Method; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
957
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
53868
|
|
|
1
|
|
|
|
|
35
|
|
7
|
1
|
|
|
1
|
|
1061
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2331
|
|
|
1
|
|
|
|
|
97
|
|
8
|
1
|
|
|
1
|
|
1845
|
use Encode; |
|
1
|
|
|
|
|
22467
|
|
|
1
|
|
|
|
|
110
|
|
9
|
1
|
|
|
1
|
|
1164
|
use JSON; |
|
1
|
|
|
|
|
15600
|
|
|
1
|
|
|
|
|
10
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.7'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $SERVICE_TYPE = "rest"; |
14
|
|
|
|
|
|
|
my $API_VERSION = "0.0"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $UA_SUFFIX = "Perl-Net-Zemanta/$VERSION"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
5
|
|
|
5
|
0
|
8
|
my $class = shift; |
20
|
5
|
|
|
|
|
12
|
my %params = @_; |
21
|
|
|
|
|
|
|
|
22
|
5
|
|
|
|
|
9
|
my $self = \%params; |
23
|
|
|
|
|
|
|
|
24
|
5
|
50
|
|
|
|
25
|
$self->{ua} = LWP::UserAgent->new() or return undef; |
25
|
|
|
|
|
|
|
|
26
|
5
|
100
|
|
|
|
4316
|
$self->{APIKEY} or return undef; |
27
|
3
|
50
|
|
|
|
9
|
$self->{METHOD} or return undef; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# NOTE: trailing space leaves LWP::UserAgent agent string in place |
30
|
3
|
|
|
|
|
7
|
my $agent = "$UA_SUFFIX "; |
31
|
3
|
50
|
|
|
|
8
|
$agent = "$params{USER_AGENT} $agent" if $params{USER_AGENT}; |
32
|
3
|
|
|
|
|
10
|
$self->{ua}->agent($agent); |
33
|
|
|
|
|
|
|
|
34
|
3
|
|
|
|
|
171
|
$self->{service_url} = "http://api.zemanta.com/services/$SERVICE_TYPE/$API_VERSION"; |
35
|
|
|
|
|
|
|
|
36
|
3
|
|
|
|
|
25
|
bless $self, $class; |
37
|
|
|
|
|
|
|
|
38
|
3
|
|
|
|
|
8
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub execute { |
42
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
my %params = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my %merged_params = ( 'method' => $self->{METHOD}, |
46
|
|
|
|
|
|
|
'format' => 'json', |
47
|
|
|
|
|
|
|
'api_key' => $self->{APIKEY}, |
48
|
|
|
|
|
|
|
%params ); |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $response = $self->{ua}->request(POST $self->{service_url}, |
51
|
|
|
|
|
|
|
\%merged_params ); |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
unless ($response->is_success) { |
54
|
0
|
|
|
|
|
|
$self->{error} = $response->status_line; |
55
|
0
|
|
|
|
|
|
return undef; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $result = from_json($response->content); |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
if ($result->{status} ne 'ok') { |
61
|
0
|
|
|
|
|
|
$self->{error} = "method returned " . $result->{status}; |
62
|
0
|
|
|
|
|
|
return undef; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->{error} = undef; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $result; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub error { |
71
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $self->{error}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |