line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Akismet::Protocol; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
28399
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use integer; |
7
|
|
|
|
|
|
|
use LWP::UserAgent; |
8
|
|
|
|
|
|
|
use HTTP::Request::Common; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'url' => ( isa => 'Str',is=>'rw' ); |
13
|
|
|
|
|
|
|
has 'key' => ( isa => 'Str',is=>'rw' ); |
14
|
|
|
|
|
|
|
has 'ua' => ( isa => 'LWP::UserAgent', default=>sub { LWP::UserAgent->new()},is=>'rw'); |
15
|
|
|
|
|
|
|
has 'api_version' => ( isa => "Str", default=>"1.1",is=>'rw' ); |
16
|
|
|
|
|
|
|
has 'host' => ( isa => "Str", default=>"api.antispam.typepad.com",is=>'rw' ); |
17
|
|
|
|
|
|
|
has 'ua_string' => ( isa => 'Str', default=> "Perl-Net-Akismet-Protocol/$VERSION",is=>'rw'); |
18
|
|
|
|
|
|
|
has 'response' => ( isa => 'HTTP::Response',is=>'rw'); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub BUILD { |
21
|
|
|
|
|
|
|
my ($self,$params)=@_; |
22
|
|
|
|
|
|
|
$self->ua->agent($self->ua_string); |
23
|
|
|
|
|
|
|
return $self if $self->_verify_key(); |
24
|
|
|
|
|
|
|
die "Could not verify ".$self->key; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub _verify_key { |
28
|
|
|
|
|
|
|
my $self=shift; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $response = $self->ua->post( |
31
|
|
|
|
|
|
|
'http://'.$self->host.'/'.$self->api_version.'/verify-key', |
32
|
|
|
|
|
|
|
[ |
33
|
|
|
|
|
|
|
key => $self->key, |
34
|
|
|
|
|
|
|
blog => $self->url, |
35
|
|
|
|
|
|
|
] |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
($response && $response->is_success() && 'valid' eq $response->content()) or return undef; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return 1; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub check { |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$self->_submit('comment-check', {@_}) or return undef; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$self->response->content eq'true' || $self->response->content eq 'false' || die $self->response->content; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return $self->response->content eq 'true' ? 1 : 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub spam { |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $self->_submit('submit-spam', {@_}); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub ham { |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $self = shift; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
return $self->_submit('submit-ham', {@_}); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _submit { |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $action = shift || 'comment-check'; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $comment = shift; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$comment->{user_ip} && $comment->{user_agent} || die "User IP and User Agent required"; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $response = $self->{ua}->post( |
80
|
|
|
|
|
|
|
'http://'.$self->key.'.'.$self->host.'/'.$self->api_version.'/'.$action, |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
[ |
83
|
|
|
|
|
|
|
blog => $self->url, |
84
|
|
|
|
|
|
|
user_ip => $comment->{user_ip}, |
85
|
|
|
|
|
|
|
user_agent => $comment->{user_agent}, |
86
|
|
|
|
|
|
|
referrer => $comment->{referrer}, |
87
|
|
|
|
|
|
|
permalink => $comment->{permalink}, |
88
|
|
|
|
|
|
|
comment_type => $comment->{comment_type}, |
89
|
|
|
|
|
|
|
comment_author => $comment->{comment_author}, |
90
|
|
|
|
|
|
|
comment_author_email => $comment->{comment_author_email}, |
91
|
|
|
|
|
|
|
comment_author_url => $comment->{comment_author_url}, |
92
|
|
|
|
|
|
|
comment_content => $comment->{comment_content}, |
93
|
|
|
|
|
|
|
] |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$self->response( $response); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
return 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 NAME |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Net::Akismet::Protocol - Perl interface to Akismet Protocol - comment and trackback spam fighter |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $akismet = Net::Akismet::Protocol->new( |
114
|
|
|
|
|
|
|
key => 'secret-baba-API-key', |
115
|
|
|
|
|
|
|
url => 'http://example.blog.net/', |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
my $verdict = $akismet->check( |
119
|
|
|
|
|
|
|
user_ip => '10.10.10.11', |
120
|
|
|
|
|
|
|
user_agent => 'Mozilla/5.0', |
121
|
|
|
|
|
|
|
comment_content => 'Run, Lola, Run, the spam will catch you!', |
122
|
|
|
|
|
|
|
comment_author => 'dosser', |
123
|
|
|
|
|
|
|
coment_author_email => 'dosser@subway.de', |
124
|
|
|
|
|
|
|
referrer => 'http://lola.home/', |
125
|
|
|
|
|
|
|
) or die('Is the server here?'); |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
if ( $verdict == 1) { |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
print "I found spam. I am a spam-finder!\n"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
=head1 DESCRIPTION |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This module implements the Akismet anti-spam API. It's based on L<Net::Akismet>, |
134
|
|
|
|
|
|
|
but has been rewritten using Moose, and it you allows to use different servers |
135
|
|
|
|
|
|
|
as long as they implement the same REST spec as Akismet. By default, the module |
136
|
|
|
|
|
|
|
will use Typepad Antispam. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 METHODS |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 B<new()> |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Net::Akismet->new(PARAM => ...); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Acceptable parameters: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=over 4 |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item key |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The API key being verified for use with the API. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item url |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The front page or home URL of the instance making the request. For a blog or wiki this would be the front page. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item ua |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The LWP::UserAgent to use |
160
|
|
|
|
|
|
|
´ |
161
|
|
|
|
|
|
|
=item ua_string |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
This will be set as your user agent string at build time if supplied. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item api_version |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Akismet API version in use. Defaults to '1.1' |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item host |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
API host to connect to. defaults to 'api.antispam.typepad.com' |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
If verification of the key was unsuccessful C<new()> returns C<undef>. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head2 B<check()> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
$akismet->check(user_ip => ..., comment_content => ..., ...) |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
To be or not to be... C<check> is meant to tell you. Give it enough details about the comment and expect C<'true'>, C<'false'> or C<undef> as a result. C<'true'> means B<spam>, C<'false'> means B<not spam>, C<undef> is returned on errror in submission of the comment. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Acceptable comment characteristics: |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=over 4 |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item user_ip |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
B<Required.> Represents the IP address of the comment submitter. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=item user_agent |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
B<Required.> User agent string from the comment submitter's request. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=item comment_content |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Comment text. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=item referer |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
HTTP C<Referer> header. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item permalink |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Permanent link to the subject of the comment. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=item comment_type |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
May be blank, 'comment', 'trackback', 'pingback', or a made up value like 'registration'. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item comment_author |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Name of submitter. |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
=item comment_author_mail |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Submitter e-mail. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item comment_author_url |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Submitter web page. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=back |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head2 B<spam()> |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
Reports a certain comment as spam. Accepts the same arguments as C<check()>. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
In case of failed submission returns C<undef>, otherwise - a perl-known truth. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 B<ham()> |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
This call is intended for the marking of false positives, things that were incorrectly marked as spam. It takes identical arguments as C<check()> and C<spam()>. |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
In case of failed submission returns C<undef>, otherwise - a perl-known truth. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=head1 Internal Moose methods |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=head2 meta |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=head2 BUILD |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 NOTES |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Although almost all comment characteristics are optional, performance can drop |
248
|
|
|
|
|
|
|
dramatically if you exclude certain elements. So please, supply as much |
249
|
|
|
|
|
|
|
comment detail as possible. |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=head1 SEE ALSO |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=over 4 |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=item * L<Net::Akismet> |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item * http://akismet.com/ |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=item * http://akismet.com/development/api/ |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=back |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=head1 AUTHOR |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
Marcus Ramberg E<lt>mramberg@cpan.orgE<gt> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
Based on L<Net::Akismet> by Nikolay Bachiyski E<lt>nbachiyski@developer.bgE<gt> |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 LICENSE |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=cut |