DBIx-SQLEngine

 view release on metacpan or  search on metacpan

SQLEngine/Docs/Comparison.pod  view on Meta::CPAN

=head2 Support

Support for this module is available from the author (evo@cpan.org). (The author is also available for support contracts or consulting engagements.)

=head2 Status

Actively developed and supported by the author. Underlying features being used by other CPAN modules, but not the recently-released object-mapping capability.

=head2 Other

A callback mechanism allows you to specify method names or arbitrary subroutines to be called immediately before or after each record is retrieved, inserted, updated, or deleted. You can add these callbacks to all record classes, to a particular clas...


=head1 SEE ALSO

See L<DBIx::SQLEngine> for an overview of this framework.

=cut

SQLEngine/Record/Hooks.pm  view on Meta::CPAN

  my $sqldb = DBIx::SQLEngine->new( ... );

  $class_name = $sqldb->record_class( $table_name, undef, 'Hooks' );
  
  $sqldb->record_class( $table_name, 'My::Record', 'Hooks' );
  
  package My::Record;
  use DBIx::SQLEngine::Record::Class '-isasubclass', 'Hooks';  
  My::Record->table( $sqldb->table($table_name) );

B<Hooks:> Register subs for callbacks.

  DBIx::SQLEngine::Record::Hooks->install_hooks( 
    post_new    => sub { warn "Record $_[0] created" },
    post_fetch  => sub { warn "Record $_[0] loaded" },
    post_insert => sub { warn "Record $_[0] inserted" },
    post_update => sub { warn "Record $_[0] updated" },
    post_delete => sub { warn "Record $_[0] deleted" },
  );
  
  $class_name->install_hooks( %hook_subs );

SQLEngine/Record/Hooks.pm  view on Meta::CPAN


use strict;
use Carp;

########################################################################

########################################################################

=head1 HOOKS INTERFACE

Many of the methods below are labeled "Inheritable Hook." These methods allow you to register callbacks which are then invoked at specific points in each record's lifecycle. You can add these callbacks to all record classes, to a particular class, or...

These hooks act like the triggers supported by some databases; you can ensure that every time a record is updated in a specific table, certain other actions occur automatically.

To register a callback, call the install_hooks method, and pass it pairs of a hook method name, and a subroutine reference, as follows: I<callee>->install_hooks( I<methodname> => I<coderef>, ... ).

=over 4

=item install_hooks()

  $classname->install_hooks( $hook_name => \&my_sub, ... )
  $record->install_hooks( $hook_name => \&my_sub, ... )

Registers one or more callbacks. Accepts pairs of a hook method name, and a subroutine reference. 

For more about the implementation of the Hook mechanism, see L<Class::MakeMethods::Composite::Inheritable>.

=back

B<Examples:>

Here are a few examples to show the possibilities this provides you with:

=over 4



( run in 0.266 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )