NAME

Aniki::Handler - Database handler manager

SYNOPSIS

# define custom database handler class
pakcage MyApp::DB::Handler {
    use Mouse;
    extends qw/Aniki::Handler/;

    has '+connect_info' => (
        is => 'rw',
    );

    has servers => (
        is  => 'ro',
        isa => 'ArrayRef[Str]',
    );

    sub _choice { @_[int rand scalar @_] }

    around connect => sub {
        my $self = shift;
        my ($dsn, $user, $pass, $attr) = @{ $self->connect_info };
        $attr->{host} = _choice(@{ $self->servers });
        $self->connect_info([$dsn, $user, $pass, $attr]);
        return DBIx::Handler->new($dsn, $user, $pass, $attr, {
            on_connect_do    => $self->on_connect_do,
            on_disconnect_do => $self->on_disconnect_do,
        });
    };
};

# and use it
package MyApp::DB {
    use Mouse;
    extends qw/Aniki::Handler/;

    __PACKAGE__->setup(
        handler => 'MyApp::DB::Handler',
    );
}

1;

DESCRIPTION

This is database handler manager.

METHODS

CLASS METHODS

new(%args) : Aniki::Handler

Create instance of Aniki::Handler.

Arguments

connect_info : ArrayRef

Auguments for DBI's connect method.

on_connect_do : CodeRef|ArrayRef[Str]|Str =item on_disconnect_do : CodeRef|ArrayRef[Str]|Str

Execute SQL or CodeRef when connected/disconnected.

INSTANCE METHODS

connect() : DBIx::Handler

Create instance of DBIx::Handler. You can override it in your custom handler class.

ACCESSORS

connect_info : ArrayRef
on_connect_do : CodeRef|ArrayRef[Str]|Str
on_disconnect_do : CodeRef|ArrayRef[Str]|Str
trace_query : Bool
trace_ignore_if : CodeRef
dbh : DBI::db
handler : DBIx::Handler
txn_manager : DBIx::TransactionManager