in reply to Re: Hijacking a method
in thread Hijacking a method

Fantastic! That's exactly what I'm looking for! Thanks lostjimmy =)

FWIW I did actually get this code to work, but I'm not sure how safe/portable/full of holes it is:
*Obj::myFunkyLogHandler = \$myFunkyLogHandler; *Obj::doSomething2 = \&Obj::doSomething; *Obj::doSomething = sub { $myFunkyLogHandler->Log("Hello there!"); my $ret_val = Obj::doSomething2( @_ ); $myFunkyLogHandler->Log("Bye for now!"); return $ret_val; };
so I guess I was a little closer to what I wanted than I thought!

Replies are listed 'Best First'.
Re^3: Hijacking a method
by jettero (Monsignor) on Jun 17, 2009 at 17:50 UTC
    I would guess this method is the most portable since you don't need to install anything from CPAN to get it to work and this works on most (if not all) perls. The sub-class and/or cpan methods are certainly cleaner and more readable, but this is definitely portable.

    -Paul

Re^3: Hijacking a method
by lostjimmy (Chaplain) on Jun 17, 2009 at 18:32 UTC

    Like jettero says, your version is very portable, and should be safe for what you are using it for. It is essentially what LexWrap does, minus some additional features and error checking.

    On the other hand, LexWrap is a pure perl module, so there's really no issue with just including it with your script if you're looking for a clean wrapping module to use.