|Syntactic Confectionery Delight|
Filepointer of source file inside source filterby liz (Monsignor)
|on Oct 05, 2003 at 09:25 UTC||Need Help??|
liz has asked for the
wisdom of the Perl Monks concerning the following question:
Executive summary: find out the original file pointer position of a line being filtered in a source filter
One of my projects is load.pm which allow ondemand loading of subroutines, much like AutoLoader.pm. But with the advantage that it doesn't need to autosplit source files first, which means development is much easier (you don't need to install before you can test). This is achieved by recording the seek() location of the start of the subroutine and the number of bytes of source code. Whenever a routine needs to be loaded, the original source-file is opened, seek(ed) to the correct position and then read for the number of bytes. This is then evalled with the right stuff around it.
However, what I dislike about AutoLoader c.s modules, is that the source of the subroutines that need to be loaded, is located after __END__ in the source code. This has the following disadvantages in my opinion:
So I would like to implement a module that would allow a subroutine attribute to indicate whether the subroutine should be loaded on demand or not. Something like:
The way I would like to implement this, is with a source filter (for now anyway). And I think I got it all figured out, except for one bit. How to record the file pointer's position in the source file where the subroutine in question starts. I need to have this to allow that part of the source code to be evalled when needed.
I realize that this is basically impossible with stacked source filters, but I think I can make a case that my source filter must to be first one to be activated.
One yucky way to do this, would be to read the original source file for the N lines until where the use load is located (because I can know the line number from the call stak, but I would need the byte offest).
Other suggestions, anyone?