Maroš Kollár > DBIx-Class-DeleteAction-1.03 > DBIx::Class::DeleteAction

Download:
DBIx-Class-DeleteAction-1.03.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Module Version: 1.30.0   Source   Latest Release: DBIx-Class-DeleteAction-1.04

NAME ^

DBIx::Class::DeleteAction - Define delete triggers

SYNOPSIS ^

 # Actor DBIC class
 package Your::Schema::Actor;
 use strict;
 use warnings;
 
 use base 'DBIx::Class';

 __PACKAGE__->load_components("DeleteAction","PK","Core");
 
 __PACKAGE__->table("actor");
 __PACKAGE__->add_columns(qw/id name/);
 __PACKAGE__->set_primary_key('id');
 
 __PACKAGE__->has_many(
    'actorroles' => 'MyDB::Schema::ActorRole',
    { 'foreign.actor' => 'self.id' },
    { delete_action => 'delete' }
 );
 
 # Actor Role DBIC class
 package Your::Schema::ActorRole;
 use strict;
 use warnings;
 
 use base 'DBIx::Class';
 
 __PACKAGE__->load_components("DeleteAction","PK","Core");
 
 __PACKAGE__->table("actor_role");
 __PACKAGE__->add_columns(qw/id name actor production/);
 __PACKAGE__->set_primary_key('id');
 
 __PACKAGE__->belongs_to(
    'actor' => 'MyDB::Schema::Actor',
    { 'foreign.id' => 'self.actor' },
    { delete_action => 
        sub {
            my ($self,$params) = @_;
            # Do something special
        } 
    }
 );
 
 __PACKAGE__->belongs_to(
    'production' => 'MyDB::Schema::Production',
    { 'foreign.id' => 'self.production' },
    { delete_action => 'deny' }
 );
 
 # Somewhere else
 $schema->txn_do(sub {
    $actor->delete();    
 });
 # Deletes all related actorroles only if they don't have a production
 # Finally deletes the actor itself
 
 $schema->txn_do(sub {
    $actor_role->delete();    
 });
 # Calls custom subroutine on actor
 # Denies deletion if a production is related

DESCRIPTION ^

With this DBIx::Class component you can specify actions that should be triggered on a row delete. A delete action is specified by adding the 'delete_action' key to the optional attribute HASH reference when specifing a new relation (see DBIx::Class::Relationship).

The following delete actions are supported:

Custom delete handlers

If you set the delete_action to execute a method or a code reference the method will be called with the following parameters:

delete

 $object->delete();
 OR
 $object->delete(HASHREF);

This method overdrives the DBIx::Class::Row delete method. You can add arbitrary data as HASHREF which will be passed to your custom delete handles.

Make sure that you ALWAYS call delete always from within a TRANSACTION block.

If you call delete from within a custom delete handler always pass on the seen parameter.

CAVEATS ^

Note that the delete method in DBIx::Class::ResultSet will not run DeleteAction triggers. See delete_all if you need triggers to run.

Any database-level cascade, restrict or trigger will be performed AFTER a DBIx-Class-DeleteAction based trigger.

Always use transactions, or else you might end up with inconsistent data.

SUPPORT ^

Please report any bugs or feature requests to bug-dbix-class-deleteaction@rt.cpan.org, or through the web interface at http://rt.cpan.org/Public/Bug/Report.html?Queue=DBIx::Class::DeleteAction. I will be notified, and then you'll automatically be notified of progress on your report as I make changes.

AUTHOR ^

    Maroš Kollár
    CPAN ID: MAROS
    maros [at] k-1.com
    L<http://www.revdev.at>

ACKNOWLEDGEMENTS ^

This module was written for Revdev http://www.revdev.at, a nice litte software company I run with Koki and Domm (http://search.cpan.org/~domm/).

COPYRIGHT ^

DBIx::Class::DeleteAction is Copyright (c) 2008 Maroš Kollár - http://www.revdev.at

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.