/usr/share/perl5/Net/Akismet.pm is in libnet-akismet-perl 0.05-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | package Net::Akismet;
=head1 NAME
Net::Akismet - Perl interface to Akismet - comment and trackback spam fighter
=cut
use 5.006;
use warnings;
use strict;
use integer;
use LWP::UserAgent;
use HTTP::Request::Common;
our $VERSION = '0.05';
my $UA_SUFFIX = "Perl-Net-Akismet/$VERSION";
=head1 SYNOPSIS
my $akismet = Net::Akismet->new(
KEY => 'secret-baba-API-key',
URL => 'http://example.blog.net/',
) or die('Key verification failure!');
my $verdict = $akismet->check(
USER_IP => '10.10.10.11',
COMMENT_USER_AGENT => 'Mozilla/5.0',
COMMENT_CONTENT => 'Run, Lola, Run, the spam will catch you!',
COMMENT_AUTHOR => 'dosser',
COMMENT_AUTHOR_EMAIL => 'dosser@subway.de',
REFERRER => 'http://lola.home/',
) or die('Is the server here?');
if ('true' eq $verdict) {
print "I found spam. I am a spam-founder!\n";
}
=head1 METHODS
=over 8
=item B<new()>
Net::Akismet->new(PARAM => ...);
Acceptable parameters:
=over 4
=item KEY
The API key being verified for use with the API.
=item URL
The front page or home URL of the instance making the request. For a blog or wiki this would be the front page.
=item USER_AGENT
If supplied the value is prepended to this module's identification string to become something like:
your-killer-app/0.042 Perl-Net-Akismet/0.01 libwww-perl/5.8
Otherwise just Akismet Perl's user agent string will be sent.
=item SERVICE_HOST
If supplied, the host of the service API. The default is rest.akismet.com
=item SERVICE_VERSION
If supplied, the API version. The default is 1.1
=back
If verification of the key was unsuccessful C<new()> returns C<undef>.
=cut
sub new {
my $that = shift;
my $class = ref $that || $that;
my %params = @_;
my $self = \%params;
$self->{ua} = LWP::UserAgent->new() or return undef;
my $key = $self->{KEY} or return undef;
my $url = $self->{URL} or return undef;
# NOTE: trailing space leaves LWP::UserAgent agent string in place
my $agent = "$UA_SUFFIX ";
$agent = "$params{USER_AGENT} $agent" if $params{USER_AGENT};
$self->{ua}->agent($agent);
$self->{SERVICE_HOST} = $params{SERVICE_HOST} || 'rest.akismet.com';
$self->{SERVICE_VERSION} = $params{SERVICE_VERSION} || '1.1';
bless $self, $class;
return $self->_verify_key()? $self : undef;
}
sub _verify_key {
my $self = shift;
my $response = $self->{ua}->request(
POST "http://$self->{SERVICE_HOST}/$self->{SERVICE_VERSION}/verify-key",
[
key => $self->{KEY},
blog => $self->{URL},
]
);
($response && $response->is_success() && 'valid' eq $response->content()) or return undef;
return 1;
}
=item B<check()>
$akismet->check(USER_IP => ..., COMMENT_CONTENT => ..., ...)
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.
Acceptable comment characteristics:
=over 4
=item USER_IP
B<Required.> Represents the IP address of the comment submitter.
=item COMMENT_USER_AGENT
B<Required.> User agent string from the comment submitter's request.
=item COMMENT_CONTENT
Comment text.
=item REFERRER
HTTP C<Referer> header.
=item PERMALINK
Permanent link to the subject of the comment.
=item COMMENT_TYPE
May be blank, 'comment', 'trackback', 'pingback', or a made up value like 'registration'.
=item COMMENT_AUTHOR
Name of submitter.
=item COMMENT_AUTHOR_EMAIL
Submitter e-mail.
=item COMMENT_AUTHOR_URL
Submitter web page.
=back
=cut
sub check {
my $self = shift;
$self->_submit('comment-check', {@_}) or return undef;
('true' eq $self->{response} || 'false' eq $self->{response}) or return undef;
return $self->{response};
}
=item B<spam()>
Reports a certain comment as spam. Accepts the same arguments as C<check()>.
In case of failed submission returns C<undef>, otherwise - a perl-known truth.
=cut
sub spam {
my $self = shift;
return $self->_submit('submit-spam', {@_});
}
=item B<ham()>
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()>.
In case of failed submission returns C<undef>, otherwise - a perl-known truth.
=cut
sub ham {
my $self = shift;
return $self->_submit('submit-ham', {@_});
}
sub _submit {
my $self = shift;
my $action = shift || 'comment-check';
my $comment = shift;
$comment->{USER_IP} && $comment->{COMMENT_USER_AGENT} || return undef;
# accomodate common misspelling
$comment->{REFERRER} = $comment->{REFERER} if !$comment->{REFERRER} && $comment->{REFERER};
my $response = $self->{ua}->request(
POST "http://$self->{KEY}.$self->{SERVICE_HOST}/$self->{SERVICE_VERSION}/$action",
[
blog => $self->{URL},
user_ip => $comment->{USER_IP},
user_agent => $comment->{COMMENT_USER_AGENT},
referrer => $comment->{REFERRER},
permalink => $comment->{PERMALINK},
comment_type => $comment->{COMMENT_TYPE},
comment_author => $comment->{COMMENT_AUTHOR},
comment_author_email => $comment->{COMMENT_AUTHOR_EMAIL},
comment_author_url => $comment->{COMMENT_AUTHOR_URL},
comment_content => $comment->{COMMENT_CONTENT},
]
);
($response && $response->is_success()) or return undef;
$self->{response} = $response->content();
return 1;
}
1;
=back
=head1 NOTES
Although almost all comment characteristics are optional, performance can drop dramatically if you exclude certain elements. So please, supply as much comment detail as possible.
=head1 SEE ALSO
=over 4
=item * http://akismet.com/
=item * http://akismet.com/development/api/
=back
=head1 AUTHOR
Nikolay Bachiyski E<lt>nb@nikolay.bgE<gt>
=head2 Help, modifications and bugfixes from:
=over 4
=item * Peter Pentchev
=item * John Belmonte
=back
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2006, 2007, 2008 by Nikolay Bachiyski
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
$Id: Akismet.pm 38 2008-06-05 17:15:12Z humperdink $
=cut
|