samtregar has asked for the wisdom of the Perl Monks concerning the following question:
&$code; # call the wrapped sub if (CODE DIED) { # do something about that and let the die() happen } else { # do something else }
Now, the obvious way to do that is to wrap the call in an eval {} and check $@:
eval { &$code; }; # call the wrapped sub if ($@) { # do something about that and let the die() happen } else { # do something else }
The problem with that is that I don't want to mess up the die() string that's already there. If I catch it with eval{} then I have to re-throw with die() to let the die() happen. But then the die() will refer to my module instead of the actual source of the die() when it's printed.
I'm getting a tickle somewhere in my memory banks that I can could use an object with a DESTROY method somehow... But I'm just not putting 2 and 2 together here.
Devel::DProf uses SAVE_DESTRUCTOR_X() to handle this problem, which is also tickling my memory, but nothing specific is popping out.
Anyone want to step up to the blackboard and show me how it's done?
-sam
PS: I bet a lot of you are wondering why I would write another profiler when Devel::DProf is hahn rockin'. Well, unfortunately Devel::DProf does nothing but seg-fault on my application and I absolutely need a profiler. I spent a few days trying to fix Devel::DProf and I'm just not up to it. Neither, apparently, is anyone else on p5p and Ilya won't have time to look at it until the fall... So, here I am. Read the RATIONALE section in my POD for the full scoop.
PPS: The links to my code above are to the CVS version. It's not done yet so don't bother giving it a code review. When I release my first version I'll be happy to hear all about what a dumbass I am!
|
|---|