Hello Masonites! I'm looking for a little advice on some advanced Mason
usage.
Bottom line up front: Is there an easy way to create and compose Request
extensions that just add owned objects?
Detail:
I currently use a custom subclass of HTML::Mason::Request in most of my apps
that extends the request object in some simple ways, but does it kind of
poorly.
For example, I have added a logger() method to the request that returns a
Log::Dispatch instance for consistent logging throughout my app. However,
this owned object currently gets constructed by custom code, and gets its
config info from a separate config file loaded by custom code. Having
learned more about Mason internals, I would like to change this into an
owned object managed through Class::Container, so that Mason can read the
config info from the Apache config and construct the logger itself when it
needs to. Most of the things my subclass does can be boiled down to this
"owned object" type behavior.
The simplest thing I could do instead would be to write a Plugin that would
instantiate the object for each request and stuff it into $m->notes(), but
that's just a hack that doesn't take advantage of Mason's cool "owned
object" architecture.
It looks like what I need to do is:
1. Subclass Log::Dispatch with multiple inheritance so that the new object
isa(Class::Container), writing whatever glue is needed to reshuffle the
constructor args; and
2. Subclass HTML::Mason::Request and teach it to own one of the
Log::Dispatch descendants.
Okay, that's doable, but it doesn't scale very well. I have half a dozen
unrelated owned objects, and I'd like to distribute them separately, but it
looks like that would require a different Request subclass for each owned
object, plus an additional subclass inheriting from *all* of them to
integrate them. That sounds pretty kludgy to me. I can, of course, define
them all in one subclass, but that makes it difficult or impossible to
separate the very generic Log::Dispatch integration from my very specialized
app authentication wrapper.
I would like to be able to tell the Request class "Hey, you own one of
*these* now too" without having to write a special subclass. Is this what
the (experimental) decorates() method is for? I can't wrap my head around
how to use that. And it looks like calling contained_objects() on the
Request class would seriously break stuff. I'm not even clear if it is safe
to call it in a subclass.
Side note: Is this what Class::ClassDecorator does?
If I can find a clean way to do this, I'll be happy to circulate my more
useful extensions (like the Log::Dispatch integration).
Any advice or examples greatly appreciated. Thanks in advance for the help.
-Vince Veselosky
http://www.webquills.net
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users