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:

sub foo : ondemand { }

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?

Liz


In reply to Filepointer of source file inside source filter by liz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.