[OT] Wrapping methods

David Cantrell david at cantrell.org.uk
Mon Jul 6 17:21:26 BST 2009

On Mon, Jul 06, 2009 at 05:06:03PM +0100, Nicholas Clark wrote:

> 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.

You can't use inheritance for this.  You need to detect whenever a class
is loaded - perhaps by doing some Voodoo in @INC or %INC.  Then to
figure out which classes inherit from your class, use Class::CanBeA, and
then Hook::LexWrap or something similar to wrap its run() method.

It sounds like this would be terribly fragile though.  eg, if run() is
AUTOLOADed or otherwise defined at runtime.

David Cantrell | London Perl Mongers Deputy Chief Heretic

Hail Caesar!  Those about to vi ^[ you!

More information about the london.pm mailing list