Subject: | Providing more info for patcher sub |
Hi Paul,
First of all, Monkey::Patch rocks (especially the stacked/restore
thing). Thanks for writing it.
I'm developing a module Module::Patch which basically groups several
patches together for convenient deployment. Sometimes a single patcher
sub is patching a bunch of subroutines instead of just one (for
example, wrapping all public methods of a class to add logging). The
patcher sub wants to know the original name of the subroutine it
patched, so it can write a proper log message ("Entering Foo::bar
(...) ...", and so on).
I've written a patch for Monkey::Patch (it's currently on my laptop at
home so I have no access to it now), it basically add an options
hashref to patch_*() in the 4th argument. There's an option called
supply_named which if enabled, will cause wrapper() to set the 2nd
argument to $self->name before calling the patcher subroutine. Though
to be honest I don't really like this way of modification (what if the
patcher sub needs more info? more args?)
So I've also forked Monkey::Patch 0.03 (I should've forked the Monkey-
Patch from github, probably will re-fork later), it's called
Monkey::Patch::Context (just uploaded to CPAN). It's incompatible with
Monkey::Patch in that the first argument given to patcher subroutine is
not the original subroutine, but a context hash. The context hash
contains the original subroutine in 'orig_sub' key, but also other
information 'orig_name' and others in the future.
There's also a way to make the context hash patch compatible with
Monkey::Patch, via options.
I'm consulting you on how best to proceed. I'd like to merge my changes
or make Monkey::Patch do what I needed (provide more info to the
patcher sub).
Thanks for reading this.
Regards,
Steven