Re: A trigger called when following a 'has_a'

[prev] [thread] [next] [Date index for 2004/07/20]

From: Peter Pimley
Subject: Re: A trigger called when following a 'has_a'
Date: 14:17 on 20 Jul 2004
<noob weeks="2">

Hello all, I have a question about triggers.

I have two classes, File and Location, both corresponding to a table in 
my database.  File 'has_a' Location, performed by the following in 
package File.
  __PACKAGE__->columns(qw/id location some other columns/)
  __PACKAGE__->has_a(location => 'Location')


What I need is a trigger that is called on the Location object as soon 
as you get it back from something like $my_file->location.  
Specificially, I want to have it so that if I did  
$my_file->location->do_stuff, then the trigger gets called -before- the 
call to do_stuff.  (In this example, do_stuff is not a column accessor, 
it's just a regular method)

Looking at the documentation at 
http://search.cpan.org/~tmtm/Class-DBI-0.96/lib/Class/DBI.pm#TRIGGERS, I 
got the impression that I should use an "after_set_...." trigger, but I 
can't seem to get this to work.  Perhaps I have misunderstood what the 
documentation meant.

I've also tried using a 'select' trigger.  This gets triggered whenever 
I make a call to a column accessor method on the Location object, but 
not if I just do $my_file->location->do_stuff

Can anybody help me with this?  I guess it's one of the following.


1) I've made a typo
2) Class::DBI doesn't have such a trigger
3) I've discovered a bug


Thanks in advance
Peter Pimley

(message missing)

Re: A trigger called when following a 'has_a'
Peter Pimley 14:17 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 14:42 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Peter Pimley 14:53 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 15:22 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 15:30 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Peter Pimley 15:37 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Charles Bailey 15:47 on 20 Jul 2004

Re: A trigger called when following a 'has_a'
Peter Pimley 10:32 on 21 Jul 2004

A trigger called when following a 'has_a' (again)
Peter Pimley 13:41 on 22 Jul 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52