[CDBI] Trigger - cancel transaction.

Matt S Trout dbix-class at trout.me.uk
Sun Mar 26 15:08:13 BST 2006


Praveen Hombaiah wrote:
> 
> Hi,
>   I'm wanting to check if a user has rights to create an object(Insert 
> it into the db ).   An idea I have is to check it with a before_create 
> trigger.  My question is how can I stop the object from being created 
> from the before_create trigger( without using die in the trigger, which 
> means the users of the class will have to eval{} all methods to the class.
> 
> package App::Person;
> 
> App::Person->table( 'app_person ');
> App::Person->columns(All => qw/id fname lname job_title description 
> status/);
> App::Person->columns(TEMP => qw/userid/);
> 
> OT::Project->add_trigger(before_create  => \&call_before_create);
> 
> sub call_before_create {
> 
>    unless( App::Permissions->allowed( userid, 'add.person' ) ) {
>       # How do I stop the creation of the object,
>       # without die?
> 
>       # die  "Insufficient privelage to perform requested action\n";
>    }
> 
> }
> 
> 1;
> 
> or maybe is there a better idiom?

Throwing an exception is almost certainly the best approach. Have a look at 
Error.pm off CPAN for throw/catch syntax to make it easier for the code using it.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +




More information about the ClassDBI mailing list