Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Hacking a source filter into the #! line

by dcmertens (Scribe)
on Jul 26, 2014 at 11:12 UTC ( [id://1095157]=note: print w/replies, xml ) Need Help??


in reply to Re: Hacking a source filter into the #! line
in thread Hacking a source filter into the #! line

I want to use a source filter because I think it's romantic that my LyX file could itself be a Perl script. But I disagree with the premise of your question.

Source filters have all kinds of mis-uses, but the string eval approach that you suggest is actually more fragile than writing a source filter. It's not like source filters could trigger segfaults or anything. The code-extraction logic, which is the most fragile part of this whole endeavor, is the same whether working with a source filter or a string-eval script. The difference is that source filters are chained but source filters are not applied to string evals. If my in-LyX code uses source filters (hint: I use PDL::NiceSlice, probably the only syntax-modifying source filter that works properly), a string-eval approach is a far bigger headache that a source filter. I would have to try to scan the code before evaling it, and if I detected a "use PDL::NiceSlice", I would have to apply the string transform code, but only between the "use PDL::NiceSlice" and the "no PDL::NiceSlice", respecting comments and pod cuts. (I've done something similar with App::Prima::REPL.) No thanks. I'll let Perl figure that out for me, by using a source filter on my end.

You don't state why you think source filters are fragile, but the typical problem with source filters is that they try to add syntax extensions to Perl, and thus need to do their own Perl parsing. Since no source filter is smart enough to actually parse Perl, it's very easy for the source filter to fall back on dumb regexes. This introduces all kinds of subtle bugs, which cause so many headaches and lost hours that it's usually better to avoid the syntax-modifying source filter. PDL::NiceSlice has had these kinds of bugs filed and fixed, so I trust its operation and use it frequently. The source filter I propose has no substantial edge cases because the LyX-Code delimiters are unambiguous: the content of LyX-Code sections escape material that might have led to ambiguities.

  • Comment on Re^2: Hacking a source filter into the #! line

Replies are listed 'Best First'.
Re^3: Hacking a source filter into the #! line
by LanX (Saint) on Jul 26, 2014 at 13:09 UTC
    If you don't like eval (o.O?) extract the code into a separate temporary file and execute that one.

    It should also be possible to write filter.pl in a way that a source filter is applied, but that's getting too esoteric now.

    I called it "fragile" cause you need "hacks" (sic) to do it (see thread title) while the straight forward approach seems robust.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-16 22:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found