in reply to Re^2: Monkey patching all subs with a basic 'starting subname' message
in thread Monkey patching all subs with a basic 'starting subname' message
> I just like how OP is proud of their __dbg() hijacker, so I thought I'd share :)
I feel suitably patted on the head and sent on my way! :)
__dbg was one of the first things I wrote, so I am fond — not necessarily proud — of it. For me, I just like that it doesn't evaluate the entire code block if the debug level is too low (so I can avoid string-interpolation, etc. if I don't need to see it); that the prototype allows it to achieve this without any significantly obtuse syntax (whereas some other languages I've worked with would want all manner of function () or () => cruft); and that it is distinguishable from any other if/print in the code, by naming convention. I also like to set the debug level via an incremental Getopt::Long, and run it on the command line. Because I can.
Because that's all I needed -- a basic if/print that I can leave in place and 'turn off' without worrying about it.
But most of all, I like that I devised both the requirement and the implementation myself. Because it meant I knew enough to commence breaking everything I saw!
That I used it as part of further attempts to inspect the code I was working on is, of course, an overstretching of its original goals, but all I wanted to do was print the subroutines in the order they were run, without irretrievably changing the original files, so I took my hammer and applied it to this nailish-looking thing.
I haven't tried either Devel::Trace::Subs or Devel::Examine::Subs but, from what I have read, I don't know if I like that it modifies the files (although I do appreciate that you can revert it). I really didn't want to change the source files, if I could help it — they aren't mine, and it wasn't my box to play with. Thanks for pointing these out, though, and I may look to evaluate them more thoroughly in the future.
PS: I tried NYTProf very quickly, in response to two recommendations, once I got back to my lab environment. I'm sure it's wonderful but I'm nowhere near needing it yet. nytprofhtml is very pretty and nytprofcalls is very thorough but, if I'd started out with either in my toolchain, I feel I'd still be there now, wondering in what order the subroutines were run in a one-off process I was looking at...
|
|---|