in reply to Hijacking a method

Probably the 'cleanest' way to do this would be to sub-class the object's class, and a create a method that does the logging and calls the parent's method. Something like this:

package Sub::Object; use base qw(Orig::Obj); sub doSomething { my $self = shift @_; $myFunkyLogMachine->Log("hi!"); my $value = $self->SUPER::doSomething(@_); $myFunkyLogMachine->Log("hi!"); return $value; }

Then you would just use Sub::Object in place of Orig::Obj and you'd get the logging.

Replies are listed 'Best First'.
Re^2: Hijacking a method
by Transient (Hermit) on Jun 17, 2009 at 17:05 UTC
    I was considering doing something like this, but it would require a lot of changes in the legacy code (script that's calling the object) - and I'm lazy =). I was hoping to just add a change to the beginning of the file (explicitly to the symbol table) and have the results, without going in and changing too much code.

      Not a large number of changes... perl -pi -e 's/Orig::Obj/Sub::Object/g' should do it. ;)

      But it looks like there are simpler ways.