good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Just create a subclass, that's what I'd do too. As for the custom method: provide an extra field in the original object (that is indeed the most dangerous aspect of it), and assign the sub ref to it. The method itself, as per robartes, needn't do anything other than fetching that sub ref and calling it.
Now, looking at the source of Apache::FakeRequest, it looks like it is a blessed hash ref, with your named parameters as hash items. So you can just call new() with this additional named parameter, to have it inserted. That was easy. n.b. "method::lookup_uri" is still a bareword as far as Perl is concerned. I just used an outstanding value to reduce the risk of field name clashes. The source for the subclass can be pretty much as in robartes note. You just need to fill in the method call, which could look something like this: and now you have quite a generic subclass, all objects having their own custom method. You could generalize it, adding more methods, and calling SUPER::method if the necessary sub ref is missing. For example:
p.s. Caveat: I haven't tested this, as I don't have a mod_perl installation handy. Heh. Update: I have. It seems to work well. Who needs mod_perl for this kind of test, anyway? :) In reply to Re: Re: changing object's methods at runtime
by bart
|
|