Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Comment on

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

If you prefix eval strings with

'delete $INC{"Foo"}; use Foo;'
in your filter, then your filter will be re-loaded when the string is eval'd.

However, when I tried this -- using Filter::Simple as I thought that I could use it's separation of code and strings to my advantage -- it gets very confusing about what stage you are at. Everytime I thought I was close to having something work, another gotcha popped up.

So, I thought I pass the basic idea along and see if it give you better inspiration than I. :)

Update: dws pointed out that the above code wasn't responsible for my percieved partial success. The use Foo; will happen before the delete $INC{'Foo'}. The delete $INC{'Foo'} needs to delete $INC{''} anyway.

The thing fooled me was a redundant piece of test code in the external file....D'oh.

Anyway, having re-examined it, I did get a little closer, but still way short of anything that could be called successful.

The filter

package Filter::Test; use Filter::Simple; FILTER_ONLY code => sub { # print'C: ', $_; s[eval\s*($Filter::Simple::placeholder)]['<<<<<1>>>>>' eval '< +<<<<2>>>>>' . $1 ]; # print'C: ', $_; $_; }, quotelike => sub { # print 'Q: ', $_; $_ = uc $_; s['<<<<<1>>>>>'][delete \$INC{'Filter/'};]; s['<<<<<2>>>>>']["BEGIN{ require Filter::Test; Filter::Test::i +mport}"]; # print 'Q: ', $_; $_; }, ; print 'Filter::Test loaded';

The test program

#! perl -slw use strict; use Filter::Test; print 'Hello World from ', __PACKAGE__; eval "print 'Just another perl hacker'"; #require 'My/';

The external program

package My::filtertest; print 'Hello World'; eval "print 'Just another perl hacker';"; 1;

The output

P:\test>296091 Filter::Test loaded HELLO WORLD FROM main P:\test>296091 Filter::Test loaded HELLO WORLD FROM main Filter::Test loaded Use of uninitialized value in concatenation (.) or string at d:/Perl/l +ib/Filter/ line 156. Use of uninitialized value in concatenation (.) or string at d:/Perl/l +ib/Filter/ line 156. String found where operator expected at (eval 5) line 1, near "PRINT ' +JUST ANOTHER PERL HACKER'" (Do you need to predeclare PRINT?) P:\test>

As you can see, the Filter is being loaded twice, and the text within the evald string has bee uppercased (too much of it, but that's a detail :).

I did have the require half working at one point, by using eval 'use Filter::Test;' do{ local *ARGV = 'file'; <> }; , but it starts getting very complicated when you start trying to filter an eval'd require file that contains evals that contains requires....

Recurse; See Recurse; 8^o.

I can't wrap my brain around it any longer, but maybe it will inspire you, or convince you to try a different route, which might be an equally valid assist :)

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.

In reply to Re: Source filters in eval/require by BrowserUk
in thread Source filters in eval/require by liz

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (14)
    As of 2014-10-01 13:10 GMT
    Find Nodes?
      Voting Booth?

      What is your favourite meta-syntactic variable name?

      Results (19 votes), past polls