[OT] Wrapping methods

Joel Bernstein joel at fysh.org
Mon Jul 6 18:24:09 BST 2009

On 6 Jul 2009, at 17:06, Nicholas Clark wrote:
> such that it's invoked to do its work as $object->run(...);
> Is there any not-insanely-hacky way to conjure up a wrapper class
> Generic::Base::ClassWithTimeout
> such that a component could be written as
>   @ISA = 'Generic::Base::ClassWithTimeout';
>   sub run {
>        ... # does stuff
>   }
> called, as ever, as $object->run(...);
> but Generic::Base::ClassWithTimeout has done something funky to wrap  
> &run
> in a routine that does the eval block/alarm/$SIG{ALARM} handler?


> Basically, the fun is that I'd like to do something equivalent to  
> invert the
> order of inheritance, such that the parent's &run seems to be called  
> first,
> and it can "SUPER" delegate to its child.

That's exactly what the augment/inner feature of Moose provides, if  
I've understood you correctly.

Of course you might not be ready to drink the Moose kool-aid and I  
dare say the list will come up with other ways, but this seems like a  
good option.

Part of me says that inheritance is not the correct way to model this,  
at all. Yet I suspect you've got some methods which can hang, and  
where you want to inject from outside the ability to have those  
methods time out, without fiddling with the code of those classes. I  
don't know a good way to do what you asked, without significantly  
expanding the scope of the question or without knowing more about the  
actual problem domain.


More information about the london.pm mailing list