NAME
DBICx::Hooks::Registry - Manage the DBICx::Hooks registry of callbacks
VERSION
version 0.002
SYNOPSIS
use DBICx::Hooks::Registry;
dbic_hooks_register('My::Schema::Result::MySource', 'create', sub {
my ($row) = @_;
print "A new row was created, id is ", $row->id, "\n";
});
dbic_hooks_register('My::Schema::Result::MySource', 'update', sub {
my ($row) = @_;
print "The row with id is ", $row->id, " was updated\n";
});
DESCRIPTION
To register a callback with a specific Source/Action pair, you use this registry functions.
FUNCTIONS
dbic_hooks_register
dbic_hooks_register('Source', 'Action', sub { my $row = shift; ... });
dbic_hooks_register($row_obj, 'Action', sub { my $row = shift; ... });
dbic_hooks_register($rs_obj, 'Action', sub { my $row = shift; ... });
The dbic_hooks_register
function takes a pair Source
/Action
and a callback. The callback will be called after the specified Action
is performed on Source
.
The following Action
's are supported: create
, update
and delete
.
The create
action will be called after a new row is created on Source
.
The update
action is called when the update() method is called on a DBIx::Class::Row object. Note that if all the fields are updated to the same values as the current ones, no UPDATE
SQL command is actually sent to the database server, but the callback will be called anyway.
The delete
action is called after the row is deleted.
All the callbacks receive a single parameter, the DBIx::Class::Row object that was created or modified.
dbic_hooks_for
@list_of_cbs = dbic_hooks_for('Source', 'Action');
@list_of_cbs = dbic_hooks_for($row_obj, 'Action');
@list_of_cbs = dbic_hooks_for($rs_obj, 'Action');
Returns in list context a possibly empty list of callbacks for a pair Source
/Action
. In scalar context returns the number of elements in the list.
AUTHOR
Pedro Melo <melo@simplicidade.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2011 by Pedro Melo.
This is free software, licensed under:
The Artistic License 2.0