[Dbix-class] on_field_change DBIC hooks

Pedro Melo melo at simplicidade.org
Tue Jul 31 21:42:46 GMT 2007


Hi,

On Jul 31, 2007, at 6:51 PM, Jason Kohles wrote:
> On Jul 29, 2007, at 4:36 AM, Pedro Melo wrote:
>> I implementing a "on_field_change" hook. External classes can hook  
>> the DBIC model to observe (usually) status changes and start some  
>> business logic processes. The reason I choose this approach is  
>> that it creates a loosely coupled system, where I can add other  
>> components later without going back and modifying old code.
>>
>> From my first look through the code, I think the set_column() is  
>> the proper place to do this. But we could set_column() and then  
>> not update().
>>
>> So update() and look at the dirty columns is probably safer.
>>
>> If I want to trigger on insert also, I also have to watch for  
>> insert().
>>
>> Another option is to create an InflateColumn::Trigger and use  
>> that, but it might not be what people expect.
>>
>> Before I start coding, has anybody done this before? Suggestions?
>>
>
> Did you look at DBIx::Class::CDBICompat::Triggers?

Yes, and I implemented a DBIx::Class::Observable using  
Class::Observable to hook field-level changes using code very similar  
to the store_column() in DBIC::CDBICompat::Triggers.

If anybody wants I can posted it somewhere. I don't think is ready  
because Class::Observable will change the interface soon, and I need  
to check if I'll have to update my code.

Best regards,
-- 
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo at simplicidade.org
Use XMPP!





More information about the Dbix-class mailing list