Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I'm rewriting Querylet, and in the process, I want to add better error messages. The problem is that Querylet is a source filter which translates (for example):

use Querylet; database: dbi:SQLite:dbname=foo.sqlite

into

use strict; use DBI; my $dbh = DBI->connect('dbi:SQLite:dbname=foo.sqlite');

This works very well, but if there is a runtime error, say an error in ->connect(), Perl will claim an error in line 4 of the resulting code instead of line 3 of the original code.

What I want to do is add appropriate #line nnn comments (see perlsyn) that match up the line numbers in the generated code back to the line numbers in the original code:

use strict; use DBI; #line 3 "test.querylet" my $dbh = DBI->connect('dbi:SQLite:dbname=foo.sqlite');

The only, minor snag in this scheme is that I haven't found a way to get at the current offset in the input stream to find out at which offset the current Querylet section starts.

So my question boils down to these alternatives, or a better approach that I completely missed:

  • How do I coax Filter::Simple (or Filter::Util::Call) into giving up the current position of their input stream?
  • Can I add this functionality though a hook added to @INC instead?
  • Is there another approach that I can use instead?

I don't care much for the fragility of the approach, as Querylet likely is the only source filter in action.

Update: As I realize just after reviewing and posting, the offset only needs to work for the first use Querylet; statement, as Querylet transforms the complete rest of the program, passing through everything it does not recognize. I keep track of the line numbers there myself, but I lack the initial offset where the source filter starts.


In reply to "Current position" of source filter input relative to original input by Corion

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2022-10-06 10:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (26 votes). Check out past polls.

    Notices?