Re: A trigger called when following a 'has_a'
[prev]
[thread]
[next]
[Date index for 2004/07/20]
--On Tuesday, July 20, 2004 3:17 PM +0100 Peter Pimley
<ppimley@xxxxxxxxx.xxx> wrote:
> <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)
The has_a() declaration is effectively (and actually, in the current
implementation) a trigger which should insure that what's returned by
$my_file->location is a Location object, which should respond to any method
that's legal for a Location. Unless you want to rearrange the Location
object somehow, you shouldn't need a separate trigger.
Could you let us know what error you're seeing, and perhaps give us a bit
of the code executed before the error?
> 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
That looks like a correct description -- it's actually at the heart of the
current implementation for has_a().
--
Regards,
Charles Bailey < bailey _at_ newman _dot_ upenn _dot_ edu >
Newman Center at the University of Pennsylvania
|
(message missing)
|