Perl Monk, Perl Meditation | |
PerlMonks |
How to instrument a "fake" subroutine?by samtregar (Abbot) |
on May 22, 2002 at 18:44 UTC ( [id://168546]=perlquestion: print w/replies, xml ) | Need Help?? |
samtregar has asked for the wisdom of the Perl Monks concerning the following question:
While working on Devel::Profiler I've stumbled into a dark pit. Basically, Devel::Profiler works by instrumenting every sub it can find by walking symbol tables. When it finds a sub it wraps it in a profiling routine and installs it in the sub's slot in the symbol table. This is generally working fine. The problem occurs when that subroutine isn't a real subroutine, but a fake produced by exporting a symbol that doesn't exist. This exported sub will then call AUTOLOAD when it's called. Fcntl, for example, uses this pattern.
Here's a bit of code that shows a simplified version of what I'm doing. CAUTION: this code loops infinitely printing "LOCK_EX called" - it might lock up your machine if you're not quick with Ctrl-C.
Now, what I'd expected was that this code would print "LOCK_EX called" just once and then call Fcntl::AUTOLOAD as usual. Can anyone think of a way to get that behavior? Or perhaps I just need to understand why this method isn't working. Can anyone explain why a calling code-ref to a "fake" sub causes this recursion? Alternately, can anyone propose a way to detect "fake" subroutines so I could skip them for now? B:: solutions are acceptable.
Thanks!
Back to
Seekers of Perl Wisdom
|
|