Tags.pm for the Perl 6 Web project

| 7 Comments | No TrackBacks

I'm participating in the web framework for Perl 6 grant from The Perl Foundation. My first task has been working on a Tags library for (X)HTML generation.

I've got the start of a simple port of Template Declare implemented. It's not perfect, and I'm still working out the API we want, but it's functional, and nice. It's quite a bit nicer than CGI.pm-style html generation.

The philosophy of this library is that templates are code, and we should be able to deal with them as such. If your template is Perl, you can use all of the same tools you use for Perl. No need to learn a new language, and far fewer angle brackets. :)

Here's an example that runs under the current Tags.pm. Keep in mind, there's still a decent amount of API refactoring needed.

use Tags;
say show {
    html {
        head { title { 'Tags Demo' } }
        body {
            outs "hi";
            ul :id<numberlist> {
                outs "A list from one to ten:";
                for 1..10 {
                    li :class<number>, { $_ }
                }
            }
        }
    }
}

No TrackBacks

TrackBack URL: http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/121

7 Comments

impressive :-)

Looks like a system I would love using - great job, and I'm looking forward to future developments with interest!

For single-author sites this is interesting and obviously very powerful. However there is a school of thought that says that templates should not be written in something as powerful as a full programming language. This is especially true where the presentation is created by web designers separately from the programmers that work on the underlying program logic; you don't want your web designers to have to learn Perl6 if they don't need it.

I strongly recommend reading about the philosophy behind the Django template system. I guess I'm not really expecting to convert the Perl web framework at this stage, but as a fan of both Perl and Django I hope you guys are leaving open the possibility that an alternative template engine with the Django philosophy can be used instead.

Yes, Andrew, this library is primarily targeted toward single-author sites. The main intended use of this library is small sites written by a small team, possibly without a dedicated designer. We're also working on a more traditional templating library, and we very much plan to support any template library you would like to use.

I have look at the Django template system. I use it at work regularly. I very much feel that if you could not use a Django-style template engine with the work we're doing, we have failed. :)

I think it's great that Perl6 has advanced to the point where HTML generation is doable, but I wonder if large pages using a syntax which can be parsed as pure Perl6 might be hard to read. The above example, for instance, does not seem simpler or more readable than the html equivalent ... I know html doesn't have a for construct, but I can imagine a generator which can superimpose it while leaving normal stuff pure html:

<html><head>
<title>Tags Demo</title>
<body><ul id='numberlist'>
{for 1..10}
<li class='number'>{=$_}

or something. (I'm not a big fan of cgi.pm's tags-as-sub-names either.) HTML generation might sometimes be easier with a textual DSL parsed by Perl6 (with the option of embedded Perl6 code to run), like the regex engine, syntactically optimized to model a web page, rather than Perl6 itself. Code generators could compile some DSL to Perl6 just as much as html, so one design does not negate the other, but textual DSL's are kind of in vogue at the moment (see "M", etc.)... BTW, writing _textual_ DSL reminds me about that other kind of DSL, using GUI-based modeling: is there (or could there be) some kind of WYSIWYG or something tool for writing web pages "in" Perl6? Thanks...

Are there any difference between Movable type blogs and Joomla ?

Wonderful post... Very informational and educational as usual!h

Leave a comment

About this Entry

This page contains a single entry by Stephen Weeks published on March 21, 2009 6:56 PM.

Parrot Speaks Your Language was the previous entry in this blog.

More Web Grant Updates - Pastebin is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

OpenID accepted here Learn more about OpenID
Powered by Movable Type 4.32-en