- or download this
# html {
# head { title { text "Title" } };
...
# p { class_ "warning"; text "paragraph" }
# };
# }
- or download this
# doc {
# my_elem {
# # children go here
# };
# };
- or download this
# my_elem {
# text "some text";
# my_attr_ "value";
# };
- or download this
our $__frag; # points to fragment under active construction
...
sub text($) {
push @{$__frag->[2]}, @_;
}
- or download this
sub define_vocabulary {
my ($elems, $attrs) = @_;
eval "sub $_(&) { _elem('$_',\@_) }" for @$elems;
eval "sub ${_}_(\$) { _attr('$_',\@_) }" for @$attrs;
}
- or download this
BEGIN {
define_vocabulary(
...
[qw( src href class style )]
);
}
- or download this
my $my_doc = doc {
html {
...
# ]
# ]
# ]
- or download this
use XML::Writer;
...
$render_fn->($doc);
$writer->end();
}
- or download this
render_via_xml_writer( $my_doc, DATA_MODE => 1, UNSAFE => 1 );
# <html>
...
# <p class="warning">paragraph</p>
# </body>
# </html>
- or download this
sub render_doc(&) {
my $docfn = shift;
...
UNSAFE => 1
);
}
- or download this
render_doc {
html {
...
# <p>Plus paragraph number 5.</p>
# </body>
# </html>