DSL::HTML::Compiler - Compile HTML into DSL::HTML templates


This module provides functions that let you take HTML files or strings and convert them into DSL::HTML templates. This is particularily useful if you have a designer build your page layout in HTML and need to convert it to a template before adding logic.


    use strict;
    use warnings;
    use utf8;
    use DSL::HTML::Compiler;

    my $tc = compile_from_file( 'bar', "/path/to/file.html" );

    my $template_code = compile_from_html( 'foo', <<EOT );
            <link href="b.css" rel="stylesheet" type="text/css" />
            <script src="a.js"></script>

            <div id="foo" class="bar baz">
            <div id="foo" class="bar baz">

    # Only necessary if your html contains utf8, or in some cases when no ascii
    # character can be used as a delimiter due to text content.
    binmode STDOUT, ":utf8";
    print $template_code;

This will print the following that can be inserted into a perl module:

    use strict;
    use warnings;
    use utf8;
    use DSL::HTML;

    template foo {
        tag head {
            tag title {
                text q'foo';

            css q'b.css';

            js q'a.js';

        tag div('class' => q'bar baz', 'id' => q'foo') {
            text q' xxx ';

        tag p {
            text q' yyyy ';

            tag div('class' => q'bar baz', 'id' => q'foo') {
                text q' xxx ';


Delimiter for qX...X is chosen via a fall-through (see delimiters)


Delimiter is chosen from this list, the first delimiter not found in the string being quoted is used. If no valid delimiter can be found then an exception is thrown.


This one is unicode

a..z A..Z

If all else fails try a-z and A-Z.


my $perl_code = compile_from_html( $name, $html )

Build perl code from html text.

my $perl_code = compile_from_file( $name, $file )

Build perl code from an html file.


Chad Granum


Copyright (C) 2013 Chad Granum

DSL-HTML is free software; Standard perl license (GPL and Artistic).

DSL-HTML is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details.