Ah yes. I had never made a source filter before, so I tried my fingers at a little hack. It has some obvious defects, but it works on the little example. It also uses Data::Lazy. Note how laziness of evaluation plays tricks with us here in the last example. Use only if you know what you are doing. Here is the simple module:
package LazyFilt; use 5.8.0; use warnings; use strict; use Data::Lazy; use Filter::Util::Call; our $state = 0; sub import { filter_add([]); } sub filter { my $status = filter_read(); return $status unless $status > 0; my $result = ""; my @stmts = split /;/; foreach my $stmt (@stmts) { my @lazyass = split /=\[l\]/,$stmt; if (@lazyass == 1) { $result .= $stmt . ";"; next } die "We don't support this (@lazyass)!" if (@lazyass > 2); $result .= "tie $lazyass[0], 'Data::Lazy', sub { $lazyass[1] };"; } $result .= "\n"; $_ = $result; return $status; } 1;
And a small example that uses it:
use LazyFilt; use strict; use warnings; sub calc { my ($p1,$p2,$p3) = @_; print "Here is where really slow stuff happens\n"; my $sum = $p1 + $p2; } my $result =[l] calc(30,20,"FooBar"); my $result2 =[l] calc($result,20,"YoYo"); print "Just about now I need to show the first result: $result\n"; my $result3 = $result + $result2; print "And now I need the whole result: $result3 \n"; print "After this it is free to poke around: $result2\n"; my $a = 10; my $result4 =[l] 2+$a; $a = 14; print "Result? $result4\n";
If anyone actually fancies this I could even clean it up properly.

In reply to Re: Re: Re: What could I do with just Perl? by dref
in thread What could I do with just Perl? by Cody Pendant

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.