Michael Peters
and 1 contributors

NAME

Net::Mollom - interface with Mollom web API

SYNOPSIS

Communicate with the Mollom web API (http://mollom.com/) via XML-RPC to determine whether user input is Spam, Ham, flame or obscene.

    my $mollom = Net::Mollom->new(
        public_key  => 'a2476604ffba00c907478c8f40b83b03',
        private_key => '42d5448f124966e27db079c8fa92de0f',
    );

    my @server_list = $mollom->server_list();

    my $check = $mollom->check_content(
        post_title => $title,
        post_body  => $text,
    );
    if ($check->is_spam) {
        warn "someone's trying to sell us v1@grA!";
    } elsif ($check->is_unsure) {

        # show them a CAPTCHA to see if they are really human
        my $captcha_url = $mollom->get_image_captcha();
    } elsif ($check->quality < .5) {
        warn "someone's trying to flame us!";
    }

If you have any questions about how any of the methods work, please consult the Mollom API documentation - http://mollom.com/api.

CONSTRUCTORS

new

This creates a new NET::Mollom object for communication. It takes the following named arguments:

  • public_key (required)

    This is your Mollom API public key.

  • private_key (required)

    This is your Mollom API private key.

  • attempt_limit

    This is the number of times Net::Mollom will try to refresh the server list before giving up. Defaults to 1.

  • warnings

    This boolean turns on warnings. You will get warnings for the following situations:

    • A Mollom server is busy and we need to try a different one.

    • We have exhausted the list of servers to try and we need to get a new list.

OBJECT METHODS

verify_key

Check to make sure that Mollom recognizes your public and private keys. Returns true if successful, false otherwise. This is not necessary to use in your application, but can be used when doing initial development or testing.

    if( $mollom->verify_key ) {
        # go a head and do stuff
    } else {
        # doh! you screwed up somewhere
    }

check_content

Check some content for spamminess and quality. Takes the following optional named arguments:

  • post_title

  • post_body

  • author_name

  • author_url

  • author_mail

  • author_openid

  • author_ip

  • author_id

Returns a Net::Mollom::ContentCheck object.

    my $check = $mollom->check_content(
        post_title  => $title,
        post_body   => $body,
        author_name => 'Michael Peters',
        author_mail => 'mpeters@p3.com',
        author_id   => 12345,
    );

session_id

This is the Mollom assigned session id. If you've made a call to check_content() it will be set by Mollom and you must pass it later to any calls you make to send_feedback(), get_image_captcha(), get_audio_captcha() or check_captcha(). If you use the same Mollom object that made the check_content() call then you don't need to do anything since it will remember that for you. But in most web applications the next request by a user will not be served by the next process or even the next server, so there's no guarantee. You need to store and remember this mollom session_id on your own.

send_feedback

Send feedback to Mollom about their rating of your content. Take sthe following optional named parameters:

  • feedback

    A string value of either spam, profanity, low-quality, or unwanted.

  • session_id

    The id of the session where the content was checed (by a call to check_content).

    $mollom->send_feedback

get_image_captcha

Returns the URL of an image CAPTCHA. This should only be called if the last message checked was marked is_unsure. Not for is_spam or is_ham. It takes the following optional parameters:

  • author_ip

    The IP address of the content author

  • session_id

    The Mollom session_id. Normally you don't need to worry about this since Net::Mollom will take care of it for you.

get_audio_captcha

Returns the URL of an audio CAPTCHA (mp3 file). This should only be called if the last message checked was marked is_unsure. Not for is_spam or is_ham. It takes the following optional parameters:

  • author_ip

    The IP address of the content author

  • session_id

    The Mollom session_id. Normally you don't need to worry about this since Net::Mollom will take care of it for you.

check_captcha

Check that what the user entered matches the last CAPTCHA that Mollom sent as part of this session. Takes the following named arguments:

  • solution

    The user's answer to the CAPTCHA

  • session_id

    The id of the Mollom session.

Returns true if correct, false otherwise.

server_list

This method will ask Mollom what servers to use. The list of servers is saved in the Net::Mollom package and reused on subsequent calls to the API. Normally you won't need to call this method on it's own since it will be called for you when you use another part of the API.

    my @servers = $mollom->server_list();

    # or if you've saved the list in a more permanent data store
    $mollom->server_list(@servers);

get_statistics

This method gets your Mollom usage statistics. It takes the following required named parameters:

  • type

    Must be one of total_days, total_accepted, total_rejected, yesterday_accepted, yesterday_rejected, today_accepted, today_rejected.

Will return the count for the specific statistic type you requested.

EXCEPTIONS

Any object method can throw a Net::Mollom::Exception object (using Exception::Class underneath).

The following exceptions are possible:

Net::Mollom::ServerListException

This happens when we've exhausted the list available servers and we've reached our attempt_limit for getting more.

Net::Mollom::APIException

There was some kind of problem communicating with the Mollom service. This is not a network error, but somehow we're not talking to it in a language it can understand (maybe an API change or bug in Net::Mollom, etc).

Net::Mollom::CommunicationException

There was some kind of problem communicating with the Mollom service. This could be a network error or an XML::RPC error.

AUTHOR

Michael Peters, <mpeters at plusthree.com>

BUGS

Please report any bugs or feature requests to bug-net-mollom at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Mollom. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Net::Mollom

You can also look for information at:

ACKNOWLEDGEMENTS

COPYRIGHT & LICENSE

Copyright 2009 Michael Peters, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.