in reply to Re: changing object's methods at runtime
in thread changing object's methods at runtime
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.$req=Apache::FakeRequest::ViceRaid->new( method::lookup_uri => sub { # ... insert what you want it to do });
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:sub lookup_uri { $_[0]->{method::lookup_uri}->(@_); }
sub lookup_uri { ($_[0]->{method::lookup_uri} || $_[0]->can(SUPER::lookup_uri))->(@ +_); }
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? :)
|
|---|