[Catalyst] Automatic passing of objects to DBIx::Class
Charlie Garrison
garrison at zeta.org.au
Sun Feb 28 08:41:29 GMT 2010
Good evening,
On 28/02/10 at 8:58 AM +0200, Ido Perlmuter <ido at ido50.net> wrote:
>I've been racking my brain trying to find a way to automatically pass an
>object, for the matter the Catalyst::Request object, to DBIx::Class methods.
>I cannot and will not pass it myself every time I call a method in my
>schema. While I do believe the model and the app should be completely
>separated, further information must flow between the two.
I think you're looking for ACCEPT_CONTEXT or InstancePerContext.
That's how I solved passing values from Catalyst to DBIC.
<http://www.google.com/search?q=Catalyst%20ACCEPT_CONTEXT>
<http://search.cpan.org/perldoc?Catalyst::Component::InstancePerContext>
I seem to recall reading that you should decide what data/values
your DBIC model needs, and then only pass those in
ACCEPT_CONTEXT, rather than passing whole objects like $c->req.
That way when you use a different front-end, you don't have to
mock a $c->req object, you simply pass the values the DBIC
schema requires.
In your example you want the "user ID and the user IP" so grab
those from $c->req during ACCEPT_CONTEXT (or
build_per_context_instance) and pass them to your schema.
Charlie
--
Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>
〠 PO Box 141, Windsor, NSW 2756, Australia
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
http://www.ietf.org/rfc/rfc1855.txt
More information about the Catalyst
mailing list