in reply to Re: RFC: Acme::ExceptionEater
in thread RFC: Acme::ExceptionEater
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: RFC: Acme::ExceptionEater
by TGI (Parson) on Sep 11, 2007 at 16:55 UTC | |
I was thinking about that yesterday, but I couldn't figure out where to look to get the required info in a reliable fashion. The obvious place to look is in %INC. But that gives you munged names, and only on a per file included basis. Files that define multiple packages would not be handled properly. Based on my investigation of perlguts and perlapi each namespace has a stash associated with it. So if you have a list of all the stashes, you can get their names, and if you have their names, you have all the namespaces you want to add a perverse DESTROY method to. Do you have any idea where to find either a list of active namespaces or stashes?
| [reply] |
by tye (Sage) on Sep 11, 2007 at 17:21 UTC | |
You usually start in %main:: (which is also %::) and look for keys ending in "::" that have a hash entry defined and recurse (skipping over %main::main::, etc). - tye | [reply] [d/l] [select] |
by TGI (Parson) on Sep 11, 2007 at 18:06 UTC | |
I spent a bit more time googling and thinking about this and came up with this code.
The symbol table walking code is lifted from B::Stash. I left the B::Stash's omit list intact and added logic to skip pragmata. I don't understand 100% of what I am doing here--I still need to spend some time working on understanding the symbol tables and how to (ab)use them. I had to put in an ugly little klduge to keep the code from going into an infinite loop when a DESTROY method is not defined for a package. I'm not sure why its needed, but I am sure there's a better way to do it. I've already spent way too much time on this today. Anyhow in the next few days I'll be looking into this a bit deeper. This excuse to dig into the symbol tables is way too much fun.
| [reply] [d/l] |
by tye (Sage) on Sep 11, 2007 at 18:21 UTC | |
by kyle (Abbot) on Sep 11, 2007 at 17:29 UTC | |
I got this with some monkeying around:
It finds both "Foo::OneVar" and "Foo::Empty", and it sees the DESTROY methods of Data::Dumper and main::Regex. It spews warnings like crazy, but I can polish that up later. | [reply] [d/l] [select] |