DBICx::Hooks::Registry - Manage the DBICx::Hooks registry of callbacks
version 0.003
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"; });
To register a callback with a specific Source/Action pair, you use this registry functions.
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.
dbic_hooks_register
Source
Action
The following Action's are supported: create, update and delete.
create
update
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.
UPDATE
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.
@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.
Pedro Melo <melo@simplicidade.org>
This software is Copyright (c) 2011 by Pedro Melo.
This is free software, licensed under:
The Artistic License 2.0
To install DBICx::Hooks, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBICx::Hooks
CPAN shell
perl -MCPAN -e shell install DBICx::Hooks
For more information on module installation, please visit the detailed CPAN module installation guide.