NAME

HTML::Builder - A declarative approach to HTML generation

VERSION

This document describes 0.001 of HTML::Builder - released February 14, 2012 as part of HTML-Builder.

SYNOPSIS

use HTML::Builder ':minimal';

# $html is: <div id="main"><p>Something, huh?</p></div>
my $html = div { id gets 'main'; p { 'Something, huh?' } };

DESCRIPTION

A quick and dirty set of helper functions to make generating small bits of HTML a little less tedious.

FUNCTIONS

our_tags

A unique, sorted list of the HTML tags we know about (and handle).

tag($tag_name, $code_ref)

The actual function responsible for handling the tagging. All of the helper functions pass off to tag() (e.g. div() is sub div(&) { unshift 'div'; goto \&tag }).

USAGE

Each supported HTML tag takes a coderef, executes it, and returns the output the coderef writes to STDOUT with the return value appended.

That is:

div { say h1 { 'Hi there! }; p { "Nice day, isn't it?" } }

Generates:

<div><h1>Hi there!</h1><p>Nice day, isn't it?</p></div>

Element attributes are handled by specifying them with gets. e.g.:

div { id gets 'main'; 'Hi!' }

Generates:

<div id="main">Hi!</div>

gets may be specified multiple times, for multiple attributes.

EXPORTED FUNCTIONS

Each tag we handle is capable of being exported, and called with a coderef. This coderef is executed, and the return is wrapped in the tag. Attributes on the tag can be set from within the coderef by using gets, a la id gets 'foo'.

Export Groups

all

Everything.

Well, what @CGI::EXPORT_TAGS{qw{ :html2 :html3 :html4 }} thinks is everything, at any rate.

This isn't, perhaps, optimal, but I haven't run into any issues with it yet. That being said, I'm open to changing our tags list, and where it's generated from.

minimal

A basic set of the most commonly used tags:

h1..h4 div p img script br ul ol li style a

moose_safe

Everything, except tags that would conflict with Moose sugar (currently meta).

ACKNOWLEDGMENTS

This package was inspired by Template::Declare::Tags... In particular, our gets::AUTOLOAD is pretty much a straight-up copy of Template::Declare::Tags' is::AUTOLOAD, with some modifications. We also pass off to HTML::Tiny, and allow it to do the work of actually generating the output. Thanks! :)

SEE ALSO

Please see those modules/websites for more information related to this module.

SOURCE

The development version is on github at http://github.com/RsrchBoy/html-builder and may be cloned from git://github.com/RsrchBoy/html-builder.git

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/RsrchBoy/html-builder/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Chris Weyl <cweyl@alumni.drew.edu>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Chris Weyl.

This is free software, licensed under:

The GNU Lesser General Public License, Version 2.1, February 1999

1 POD Error

The following errors were encountered while parsing the POD:

Around line 222:

Nested L<> are illegal. Pretending inner one is X<...> so can continue looking for other errors.

Nested L<> are illegal. Pretending inner one is X<...> so can continue looking for other errors.