> because it is quite slow and because of inherent namespace pollution

you mention two very important problems I wanted to name in my talk

You are already using one basic tool to achieve this: blocks.

performance

All your html/xml elements take a code-block as *{$_} = sub(&) { _elem($name, @_) }; and should per default memorize the result and return the pre-calculated result.

Of course one would need exception for cases where dynamic elements have to be interpolated, like in loops, either by explicitly deactivating memoization or by parsing the block for closed over variables.

namespace

1. The most obvious solution is to use a package , something like

render { package HTML::DSL; HTML { HEAD { TITLE { "foo bar"}; }; ... }

2. Of course it would be syntactically "sweeter" if the package was automatically included.

The way to go is to use B::Deparse 's coderef2text to get the source and to re-eval it with an included package declaration in the first line.

Actually it's a bit more complicated, because you might have closed over variables inside the block which would loose their binding after evaluation.

That's why you need to inspect to take care for this, I already wrote code for this in my Macro module (github only).

This is actually the way how many (most) DSL's are constructed in Ruby, they "re-eval" the code (instance_eval or instance_exec) from inside a block.

And since they ran into the same problem with lost bindings of closure vars, a module called Docile was created to reestablish the bindings ...

... or in their own words "the hard part", where most folks making a DSL in Ruby throw up their hands

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!


In reply to Re^4: Which internal DSL are there in Perl? (Domain Specific Languages - Part 1) by LanX
in thread Which internal DSL are there in Perl? (Domain Specific Languages - Part 1) by LanX

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.