NAME

Mail::Decency::Helper::Database

DESCRIPTION

Base class for all databases

SYNPOSIS

Create a new datbaase like this:

Mail::Decency::Helper::Database->create( MongoDB => $config_ref );

CLASS ATTRIBUTES

type : Str

The type of the database (DBD, MongoDB)

logger : CodeRef

Log-Handler method

locker : IPC::Semaphore

locker_pid : Int

PID of process creating the semaphore

METHODS

create $type, $args_ref

Returns a new instance of the create database object

my $database = Mail::Decency::Helper::Database->create( DBD => $args_ref );
  • $type

    Either DBD or MongoDB for now

  • $args_ref

    HashRef of constrauctions variabels for the module's new-method

DEMOLISH

Remove locker

get $schema, $table, $search_ref

Searches and returns single entry from database

See parse_data method for return contexts.

  • $schema

    The schema/context/prefix of the lookup.. eg "throttle" for throttle tables

  • $table

    The table/suffix of the lookup .. eg "sender_domain" for the "throttle_sender_domain" table

  • $search_ref

    HashRef of search attributes. Can be flat or nested

    $search_ref = { attribute => "value" }; # simple equals
    $search_ref = { attribute => { ">" => 123 } }; # complex "greater then"

set $schema, $table, $search_ref, $data_ref

Writes to database. Could affect multiple entries.

  • $schema, $table, $search_ref

    Set get method

  • $data_ref

    HashRef or scalar of the data to be saved. If scalar, it is will be converted into { data => "scalar" }

search $schema, $table, $search_ref

Returns a list of search results (in opposite to the get method). In scalar contexts it returns an ArrayRef instead

  • $schema, $table, $search_ref

    Set get method

update_data

Transforms flat (scalar) values into { data => $value } hashrefs

parse_data $data_ref

Transforms hashref values in an array context from { value => $value } to ( $value )

In array-context, it will return the content of the "data" field, if any

Can be modified in derived modules.

update_query $query_ref

Update method for search query. Can be overwritten/extended in derived modules.

do_lock

Locks via flock file

do_unlock

Unlocks the flock

read_lock

Do read lock

read_unlock

Do unlock read

write_lock

Do read lock

write_unlock

Do unlock read

usr_lock

Custom locker

usr_lock

Custom locker

AUTHOR

Ulrich Kautz <uk@fortrabbit.de>

COPYRIGHT

Copyright (c) 2010 the "AUTHOR" as listed above

LICENCSE

This library is free software and may be distributed under the same terms as perl itself.