in reply to [RFC: Module proposal] Tracing sneaky EXPORTs using wrappers
This seems like a good idea. I'd like to know a little more though:
A synopsis and a brief summary of the implementation would really help.
lodin
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: [RFC: Module proposal] Tracing sneaky EXPORTs using wrappers
by krazyk (Beadle) on Apr 11, 2008 at 18:21 UTC | |
Some more background: Initially, I only wanted to know where to go to find the source of hundreds of imported subs in code that I was looking at. Then, I realized that if I could automatically wrap all imported subs with warnings on entry/exit, I could get a nice trace in Apache error logs. Currently, the technique is to look at all packages that are explicitly 'use'd or 'require'd by the caller (these are found by examining the caller's source code), then find all symbols that each of those packages export (this is done by looking at the contents of @EXPORT and @EXPORT_OK in each of these packages' symbol tables, so it's not compatible with non-Exporter.pm exporters). For each such symbol that is a sub, exploit Hook::LexWrap to wrap the sub (the one already imported into the caller's package) with "tracing code" as implied in the SYNOPSIS above (e.g. default or custom tracing subs). Your question about handling non-Exporter.pm exporters is a good one. I hadn't considered that in my focused mindset. I plan on adding that support. It will be a matter of looking at the caller's symbol table instead of the caller's source (which is almost certainly a better approach anyhow). So, in summary:
| [reply] [d/l] |
by lodin (Hermit) on Apr 12, 2008 at 01:09 UTC | |
The name The interface The implementation lodin | [reply] [d/l] [select] |
by krazyk (Beadle) on Apr 16, 2008 at 05:36 UTC | |
You're right about the edge cases -- there are some tough ones. I believe that most of the ones I've thought of are within reach. For instance, one interesting problem is identifying which of all the use()d modules contributes symbol S to package P (or if S just came from P itself). I believe I could create a private, empty package in which a candidate module could be use()d, then check the resulting symbol table of the dummy package for symbols. The resulting set of symbols would represent those exported by the module's import(). However, symbols not found this way might still have come from those modules (e.g. the package in question could require() a module M, then call M::import_deceptively(), which may do what import() conventionally does)! The probability of false negatives would be very low, but I can't think of a general way to positively conclude that a symbol has not been imported. I have a new appreciation for Exporter.pm, much maligned as it has been at times. As it is standard for Perl, placing dependence on it as a precondition for my module's efficacy seems reasonable. Here are the updated goals for Devel::WrapImportedSubs: Thanks for help with advice on the design! | [reply] |