Dave Rolsky > Antispam-Toolkit-0.08 > Antispam::Toolkit::Role::BerkeleyDB

Download:
Antispam-Toolkit-0.08.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.08   Source  

NAME ^

Antispam::Toolkit::Role::BerkeleyDB - A role for classes which store spam check data in a BerkeleyDB file

VERSION ^

version 0.08

SYNOPSIS ^

  package MyDBD;

  use Moose;

  with 'Antispam::Toolkit::BerkeleyDB';

  sub _store_value {
      my $class = shift;
      my $db    = shift;
      my $value = shift;

      ...
  }

DESCRIPTION ^

This role provides most of what's needed in order to store spam-checking data in a BerkeleyDB file. The only method you must implement in your class is the $class->_store_value() method.

Typically, this will be a database containing things like bad ip addresses or usernames.

ATTRIBUTES ^

This role provides the following attributes:

$db->database()

This is a Path::Class::File object representing the path on disk for the BerkeleyDB file. This attribute also accepts a string, which is coerced to a file object.

$db->name()

The name of the database. This can be any non-empty string. It is intended for use in things like logs, so that you know exactly which database matched a particular value.

By default, the name will contain the database file's basename and it's mtime as an ISO8601 datetime, something like "bad-ip.db - 2010-11-16T10:31:03".

$db->_db()

This attribute contains the BerkeleyDB object for the database. It cannot be set in the constructor, and is always lazily built.

REQUIRED METHODS ^

This role requires one method:

METHODS ^

This role provides the following methods:

$db->_build_db()

This will build the BerkeleyDB object for the database.

$db->_build_name()

This creates a default name for the object.

$class->build( ... )

This is a class method that can be used to construct a new BerkeleyDB file from a data source.

It accepts the following arguments:

$class->_extract_data_from_file( $file, $db )

This method takes a data file and adds that data to the BerkeleyDB file. By default, this expects that the file contains one value per line, so it chomps each line and stores that value.

Internally, it calls $class->_store_value() to actually store the value.

$class->_store_value( $db, $value )

This method will be called as a class method. The method is passed a BerkeleyDB object and value to store in the database.

By default, it just stores the literal value. You can replace this method if you want to do something different, like handle wildcard values.

$db->match_value($value)

This method looks up a value to see if it is stored in the database. By default, it expects the value to match a key stored in the database.

ROLES ^

This role does the Antispam::Toolkit::Role::Database role. It provides an implementation of $db->match_value() method, but you can write your own if necessary.

BUGS ^

See Antispam::Toolkit for bug reporting details.

AUTHOR ^

Dave Rolsky <autarch@urth.org>

COPYRIGHT AND LICENSE ^

This software is Copyright (c) 2011 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: