Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Error location in Filter-Include

by mosh (Scribe)
on Jul 26, 2005 at 15:17 UTC ( [id://478244]=perlquestion: print w/replies, xml ) Need Help??

mosh has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks !

I've got a problem with Filter-Include module.

This module replaces the include line from the original code with the target code, so the result is one big dump code that contains all the inclde files.
The perl interpreter goes line by line on the dump code. Now, suppose I have a syntax error, I would have no idea in what line or file the error took place !!!! since there's just one virtual file.

What are the possibilities ?

Is there any extra mechanism/module that can calculate the location of the detected error ?

TIA,

Mosh

UPDATE
Any other Ideas, Guys ???
It's really annoying me.

Replies are listed 'Best First'.
Re: Error location in Filter-Include
by kwaping (Priest) on Jul 26, 2005 at 16:52 UTC
    Is this hypothetical, or are you experiencing an error that you can't find? I wonder if Carp would help any.
      This is not Hypothetical at all !
      Usually I find the problem, but it takes much time since the framework cannot tell me the exact location of the error.
      The problem is getting worse when someone who dosn't familiar with the code has to debug it.

      I read the 'carp' set of modules. I don't see how it can help to solve this difficulty.

      Any other ideas ?

      Mosh.

Re: Error location in Filter-Include
by broquaint (Abbot) on Jul 27, 2005 at 09:18 UTC
    This is where your requested feature will come in handy:
    use Filter::Include post => sub { $_[1] = "#line $Filter::Include::LINE $_[0]\n$_[1]"; };
    So this will modify the currently filtered code to add the name of the file being included. This means that when you get the syntax error it will also include the filename the error occurred in. This code is untested, btw, so don't be surprised if it doesn't work off the bat.
    HTH

    _________
    broquaint

      Thanks broquaint !

      Although, I'm not sure I understand what you have written. Can you describe in words what's the aim of each element ?

      What's the meaning of the "post =>" ?
      What is the meaning of "sub (" without the subname ?
      What should be in $_[0] and $_1] ?
      What's the meaning of "$Filter::Include::LINE" ?

      Thanks, again,

      Mosh

        Ah, well, that's quite a lot to explain, but I shall take your questions one at a time:
        What's the meaning of the "post =>" ?
        Here the => operator, commonly known as the fat comma is simply "stringifying" (i.e turning the bareword post into a string) its left-hand side argument, which in this case is post. For more information on the fat comma see. perlop. Looking at it from a higher level it is also specifying that the post handler is being provided. For information on Filter::Include's handlers see. the HANDLERS section.
        What is the meaning of "sub (" without the subname ?
        When sub is used without a name it is creating an anonymous sub and so is acting as an anonymous subroutine constuctor. This means that it will create a subroutine and return a reference to that subroutine. It is anonymous by virtue of the fact that it can be only referred to by its reference and not its name, which is orthogonal to the anonymous array ([]) and anonymous hash ({}) constructors. For more information on anonymous subroutines see. perlsub.
        What should be in $_[0] and $_[1] ?
        As documented in the HANDLERS. section of Filter::Include the first argument ($_[0]) will contain the name of the file or module being included and the second argument ($_[1]) will be the code that has just been filtered.
        What's the meaning of "$Filter::Include::LINE" ?
        This was a little more subtle and is not currently documented in Filter::Include, which I apologise for. It holds the current line number as of the last include. This should definitely be documented and perhaps better exposed through the API. Your post definitely gave me pause for thought about how your problem could solved nicely and if it should in fact be part of the module as it certainly looks to be a handy feature. Perhaps, again, it could be implemented as another option to import. Thanks for your input, it is, as always, much appreciated.
        HTH

        _________
        broquaint

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://478244]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 06:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found