in reply to Just before subroutine returns
The one category shown is basically installing a wrapper with the same name, and execute code before the original sub is entered and after it is exited. This is very stable and easy to achieve without changing the monitored sub, but comes with the drawback that information about internal state- i.e. lexical vars - is lost.
The other category shown is adding a lexical inside the sub, which holds an object. At the moment the sub (or generally the scope) is left , lexicals without reference count will be destructed and the DESTROY method will be called. This method can trigger a call back which can display the internal state in its closure.
But I'm not sure that you can know achieve info where - i.e. at which return - the sub is left.
A third - yet not demonstrated - category is to use the debugger. There you can define watch and trace expressions for subs which will trigger at different points. But this approach comes with dramatically reduced execution speed and won't be appropriate inside a long running process, like e.g. a web application.
So the appropriate answer depends on the exact nature of the information you (or someone else digging up this thread) wants to gather. :)
HTH
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Just before subroutine returns (depends)
by Anonymous Monk on Aug 29, 2017 at 16:11 UTC | |
by GrandFather (Saint) on Aug 29, 2017 at 21:03 UTC | |
by LanX (Saint) on Aug 29, 2017 at 16:17 UTC | |
by iguanodon (Priest) on Aug 29, 2017 at 17:22 UTC |