LanX has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to realize a Lisp-like macro mechanism in Perl to get a general and reliable extension mechanism.
I successfully hacked B::Deparse such that function calls to macros are replaced with the string returned.
This works fine when translating the body of single functions with B::Deparse::coderef2text the resulting code is evaluated afterwards to replace the body.
Now I'm looking for ideas how to this for complete files.
My current approach is to use a codefilter to wrap the whole file with
macroexpand { ... oldfile ... }
But it gets tricky when handling __DATA__ and __END__ and anyway the idea was to get rid of codefilters
So does anybody know of a way to change the op-tree just after compilation?
I'm pondering to modify B::Deparse::compile for this purpose and to call it within CHECK { ... } or UNITCHECK {...}
An other approach would be to reset the implicit DATA filehandle to reread the code just after compilation phase.
Any brain storming idea is welcome.
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Implicetely deparse, change and replace perlcode in file
by ikegami (Patriarch) on Jun 20, 2011 at 18:06 UTC | |
by LanX (Saint) on Jun 20, 2011 at 18:36 UTC | |
by ikegami (Patriarch) on Jun 20, 2011 at 18:40 UTC | |
|
Re: Implicetely deparse, change and replace perlcode in file
by Anonymous Monk on Jan 18, 2012 at 14:31 UTC | |
by LanX (Saint) on Jan 18, 2012 at 22:40 UTC |