Hello Monks, does anybody know a CPAN module which could help me solving the following problem? I tried to search CPAN, but the closest I could found was Template, and I don't see how it can help for my application:

Assume I have a piece of code looking like this (just an example - I'm really flexible with regards to the syntax of the HERE document below):

sub foo { $_[0]+$_[1] } my $template=<<END; This is some line. This is a line with some expression: # $foo(3,5) # # foreach my $s qw(this that) { # This is # $s # line # } # This is the end END
I would like to "process" the code so that it evaluates the embedded expressions, resulting in a string
This is some line. This is a line with some expression: 8 This is this line This is that line This is the end
As I said, I do not have to stick to the syntax outline above. Whether the Perl expressions are delimited by '#' or by some other means, I don't care. It is not even necessary that the embedded expressions are full-blown Perl code; even some pseudocode would be OK, as long as it is powerful enough so that I can access my Perl variables, and that I can do looping construct and 'if' statements.

In practice, the surrounding text code will be XHTML, but I would like to be able to use the same concept with other text file formats, such as JSON or RTF.

Hence, I look for something similar to what Java and Ruby programmers find in JSP and RubyOnRails, but with the twist that it should not be restricted to HTML output (the program is not running in the context of a web application; it is a stand-alone application, which just creates these text files).

BTW, for PHP, there exists a solution which comes pretty close to what I'm looking for: It's called Smarty.

-- 
Ronald Fischer <ynnor@mm.st>

In reply to Looking for a "Template Engine" by rovf

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.