Re: [Catalyst] Automatic passing of objects to DBIx::Class
Good evening, On 28/02/10 at 8:58 AM +0200, Ido Perlmuter i...@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 ♊ garri...@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 ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Automatic passing of objects to DBIx::Class
Thanks, I suppose that would work. Ido. On Sun, Feb 28, 2010 at 10:41 AM, Charlie Garrison garri...@zeta.org.auwrote: Good evening, On 28/02/10 at 8:58 AM +0200, Ido Perlmuter i...@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 ♊ garri...@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 ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Automatic passing of objects to DBIx::Class
On Sat, Feb 27, 2010 at 10:58 PM, Ido Perlmuter i...@ido50.net wrote: Hi everyone. 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. For example, I need to setup an administrative usage log for my app. Whenever a user with proper privileges invokes a schema method that creates, edits or deletes information from the database, I want that action to be automatically recorded in the usage log, with details such as the user ID and the user IP. I'm facing two difficulties: on one hand I believe this should be automatically done by the schema (so recording into the usage log will not be made from the app, but from the schema), but that means I need to pass the context object (or the Request object) to every schema method I invoke; on the other hand, if I let the app handle recording into the usage log, my schema loses power. What if I want to write an API to my program in several programming languages, should they do the same too? So for a while now I've been trying to find a way to automatically pass objects to the schema. Maybe if DBIx::Class was Moose-based I would have already found one using method modifiers. Any thoughts will be appreciated. Thanks, Ido Perlmuter. I would recommend writing a simple trait that gets applied. You can look at this for inspiration: http://cpansearch.perl.org/src/FAYLAND/Catalyst-TraitFor-Model-DBIC-Schema-QueryLog-0.03/lib/Catalyst/TraitFor/Model/DBIC/Schema/QueryLog.pm It's really quite simple, and the usage is great -- you just add a configuration line and everything works. I use custom traits to decorate my schema model with application-specific objects, and have yet to have any significant complaints. -Jay ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Automatic passing of objects to DBIx::Class
Hi everyone. 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. For example, I need to setup an administrative usage log for my app. Whenever a user with proper privileges invokes a schema method that creates, edits or deletes information from the database, I want that action to be automatically recorded in the usage log, with details such as the user ID and the user IP. I'm facing two difficulties: on one hand I believe this should be automatically done by the schema (so recording into the usage log will not be made from the app, but from the schema), but that means I need to pass the context object (or the Request object) to every schema method I invoke; on the other hand, if I let the app handle recording into the usage log, my schema loses power. What if I want to write an API to my program in several programming languages, should they do the same too? So for a while now I've been trying to find a way to automatically pass objects to the schema. Maybe if DBIx::Class was Moose-based I would have already found one using method modifiers. Any thoughts will be appreciated. Thanks, Ido Perlmuter. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Automatic passing of objects to DBIx::Class
I've ran into the same issue, but solved it in a bit of a hackish fashion. I went the route of the schema objects knowing nothing about the outside world, just themselves, and their relations with other schema objects. On top of this sits a separate set of objects that contain all the logic necessary to make things work, using copious amounts of autoload voodoo. These objects can basically be used from any other app, be it Catalyst or some command line tool, and don't really have to know much else. For Catalyst I've got a custom model object that will return the appropriate logic object, whereas in offline tools they're used directly. Sort of solves the problem in a cleaner way if you ask me. Ido Perlmuter wrote: Hi everyone. 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. For example, I need to setup an administrative usage log for my app. Whenever a user with proper privileges invokes a schema method that creates, edits or deletes information from the database, I want that action to be automatically recorded in the usage log, with details such as the user ID and the user IP. I'm facing two difficulties: on one hand I believe this should be automatically done by the schema (so recording into the usage log will not be made from the app, but from the schema), but that means I need to pass the context object (or the Request object) to every schema method I invoke; on the other hand, if I let the app handle recording into the usage log, my schema loses power. What if I want to write an API to my program in several programming languages, should they do the same too? So for a while now I've been trying to find a way to automatically pass objects to the schema. Maybe if DBIx::Class was Moose-based I would have already found one using method modifiers. Any thoughts will be appreciated. Thanks, Ido Perlmuter. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/ -- Ben van Staveren phone: +62 81 70777529 email: benvanstave...@gmail.com ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/