Good stuff for programming geeks
[ start | index | login or register ]
start > Talks > Embedding an XHTML-template language into Perl

Talks/Embedding an XHTML-template language into Perl

Created by tmoertel. Last edited by tmoertel 876 days ago. Viewed 1545 times. #5
[diff] [history] [edit] [rdf]
labels
attachments
pgh-pm-edsls.png (6108)

Title slide from my talk on EDSLs in Perl

I gave this brief talk for the >>Pittsburgh Perl Mongers on 2006-03-08. The talk is about embedding domain-specific languages into Perl. The running example is XHTML construction.

You can download the slides here: pgh-pm-edsls.pdf

Most of the ideas in the talk came from an earlier posting I made to the Perl Monks web site: >>Embedding a mini-language for XML construction into Perl. I would like to thank >>Aristotle, who contributed a nice syntax-simplification idea during the follow-up discussion.

The EDSL

The EDSL looks like this:

html {
    head { 
        title { "My grand document!" }
    };
    body {
        h1 { "Heading" };
        p {
            class_ "first";       # attribute class="first"
            text "This is the first paragraph!";
            style_ "font: bold";  # another attr
        };
        # it's just Perl, so we can mix in other code
        for (2..5) {
            p { "Plus paragraph number $_." }
        }
    };
};

The embedded language renders into XHTML:

<html>
<head>
<title>My grand document!</title>
</head>
<body>
<h1>Heading</h1>
<p class="first" style="font: bold">This is the first paragraph!</p>
<p>Plus paragraph number 2.</p>
<p>Plus paragraph number 3.</p>
<p>Plus paragraph number 4.</p>
<p>Plus paragraph number 5.</p>
</body>
</html>
Please login to post a comment.
community.moertel.com | Copyright © 2003–07 Moertel Consulting