I am trying to Mason-interpret a dynamically generated script, while keeping all of the Mason variables in tact.

First the easy part. I can configure my server such that a script tag with a source like "/somepath/foo.mjs" will be processed through the normal HTML::Mason::ApacheHandler code and resolve Mason stuff properly. For instance:

"... some script stuff... % print STDERR "Mason is working!\n"; % print STDERR Dumper($m->session); ...more script stuff..."

I get the proper results. Nothing special going on.

The hard part is when my script tag has a source of "/somepath/foo.dynjs". In this case, we have an Apache handler that dynamically generates the output as a Perl string using various mechanisms. Then it serves that back to the client in the usual way. However, if I happen to have a bit of Mason in that output, I cannot seem to figure out how to have Mason interpret it WITH the session in tact, before I send it back.

That is to say, I can take that string and send it through a HTML::Mason::Interp before I serve it to the client. But because that is the "stand-alone" usage, as far as I can tell, the  $m->session part is lost. And, because "/somepath/foo.dynjs" does not actually exist as a file, trying to send the $r through the prepare_request call will error out.

This has to be possible. I'm so close. Please help!

Thanks
jason.


In reply to Mason Interp Perl string by SleepyJay

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.