rockyb has asked for the wisdom of the Perl Monks concerning the following question:
I noticed the following problem in using the perl debugger, Devel::Trepan, with code that uses the SelfLoader perl module.
SelfLoader uses eval() to install subroutines at run time. The perl debugger would like to have access to the text of the eval string. With this, when one is debugging into one of those procedures the debugger can show you were you are. The two things that defeat this in SelfLoader is the use of lexically-scoped (or my) hash %Cache of such added text which it deletes just before running the code.
The general outline of the SelfLoader is:
package SelfLoader; ... my %Cache; # private cache for all SelfLoader's client packages ... AUTOLOAD { our $AUTOLOAD; # $AUTOLOAD is fully-qualified function name, e.g. MyPackage::fn ... # set $Cache{$AUTOLOAD} to file text from __DATA__ to __END__ ... delete $Cache{$AUTOLOAD}; goto &$AUTOLOAD; }
So basically, when debugging I'd like to rewrite the above to change my %Cache to our %Cache and remove the delete $Cache{$AUTOLOAD};
Alternatively, the routine that updates %Cache is called SelfLoader::_add_to_cache() so that could be augmented to save to another hash somewhere. But the problem here is that it still needs to update the lexically-scoped %Cached hash.
The two techniques that come to mind are monkey-patching and the Decorator pattern. Alas, because of the specifics of how SelfLoader works which I won't go into here (and am not totally positive I understand), I don't see how to do either.
Thoughts on how to address? Thanks.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modifying SelfLoader to save eval() text
by rockyb (Scribe) on Jun 08, 2013 at 11:00 UTC | |
by rockyb (Scribe) on Jun 09, 2013 at 06:16 UTC |