line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Antispam; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23714
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
58
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
54
|
|
6
|
1
|
|
|
1
|
|
1184
|
use JSON::XS; |
|
1
|
|
|
|
|
10682
|
|
|
1
|
|
|
|
|
97
|
|
7
|
1
|
|
|
1
|
|
1334
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
76166
|
|
|
1
|
|
|
|
|
540
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '1.04'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# JSON object |
12
|
|
|
|
|
|
|
my $json_xs = JSON::XS->new; |
13
|
|
|
|
|
|
|
$json_xs->utf8(1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %connection_params = ( |
16
|
|
|
|
|
|
|
'server_url' => 'http://moderate.cleantalk.ru', |
17
|
|
|
|
|
|
|
'server_url' => 'http://localhost', |
18
|
|
|
|
|
|
|
'api_url' => '/api2.0', |
19
|
|
|
|
|
|
|
'auth_key' => undef, |
20
|
|
|
|
|
|
|
'connection_timeout' => 3, |
21
|
|
|
|
|
|
|
'method_name' => 'check_message', |
22
|
|
|
|
|
|
|
'agent' => 'perl-api-' . $VERSION, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my %response = ( |
26
|
|
|
|
|
|
|
'allow' => 0, |
27
|
|
|
|
|
|
|
'id' => undef, |
28
|
|
|
|
|
|
|
'comment' => '*** Connection error: %s Automoderator cleantalk.org ***', |
29
|
|
|
|
|
|
|
'stop_queue' => 0, |
30
|
|
|
|
|
|
|
'inactive' => 0, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
34
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
35
|
0
|
|
|
|
|
|
my $params = shift; |
36
|
0
|
|
|
|
|
|
my $self = bless {} , $class; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
foreach (keys %connection_params) { |
39
|
0
|
0
|
|
|
|
|
$connection_params{$_} = $$params{$_} if defined($$params{$_}); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return $self; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub request { |
46
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
47
|
0
|
|
|
|
|
|
my $params = shift; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$$params{'auth_key'} = $connection_params{'auth_key'}; |
50
|
0
|
0
|
|
|
|
|
$$params{'method_name'} = $connection_params{'method_name'} if !defined($$params{'method_name'}); |
51
|
0
|
0
|
|
|
|
|
$$params{'agent'} = $connection_params{'agent'} if !defined($$params{'agent'}); |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
54
|
0
|
|
|
|
|
|
$ua->timeout($connection_params{'connection_timeout'}); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
my $server_url = $connection_params{'server_url'} . $connection_params{'api_url'}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(POST => $server_url); |
59
|
0
|
|
|
|
|
|
$request->header('content-type' => 'application/json'); |
60
|
0
|
|
|
|
|
|
$request->content($json_xs->encode($params)); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $result = undef; |
63
|
0
|
|
|
|
|
|
my $response = $ua->request($request); |
64
|
0
|
0
|
|
|
|
|
if ($response->is_success) { |
65
|
0
|
|
|
|
|
|
eval{ |
66
|
0
|
|
|
|
|
|
$result = $json_xs->decode($response->decoded_content); |
67
|
|
|
|
|
|
|
}; |
68
|
0
|
0
|
0
|
|
|
|
if ($@ || ref($result) ne 'HASH') { |
69
|
0
|
|
|
|
|
|
$response{'comment'} = sprintf($response{'comment'}, $response->decoded_content); |
70
|
0
|
|
|
|
|
|
return \%response; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} else { |
73
|
0
|
|
|
|
|
|
$response{'comment'} = sprintf($response{'comment'}, $response->message); |
74
|
0
|
|
|
|
|
|
return \%response; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $result; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |