[Catalyst] Automatic passing of objects to DBIx::Class
Ben van Staveren
benvanstaveren at gmail.com
Sun Feb 28 07:21:16 GMT 2010
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 at 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.u=
k/
> Dev site: http://dev.catalyst.perl.org/
> =
-- =
Ben van Staveren
phone: +62 81 70777529
email: benvanstaveren at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100228/4a1f3=
447/attachment.htm
More information about the Catalyst
mailing list