Actions Status

NAME

Text::HyperScript - Let's write html/xml templates as perl code!

SYNOPSIS

use feature qw(say);
use Text::HyperScript qw(h true);

# tag only
say h('hr');          # => '<hr />'
say h(script => q{}); # => '<script></script>'

# tag with content
say h('p', 'hi,');    # => '<p>hi,</p>'
say h('p', ['hi,']);  # => '<p>hi,</p>'

say h('p', 'hi', h('b', ['anonymous']));  # => '<p>hi,<b>anonymous</b></p>'
say h('p', 'foo', ['bar'], 'baz');        # => '<p>foobarbarz</p>'

# tag with attributes
say h('hr', { id => 'foo' });                     # => '<hr id="foo" />'
say h('hr', { id => 'foo', class => 'bar'});      # => '<hr class="bar" id="foo">'
say h('hr', { class => ['foo', 'bar', 'baz'] });  # => '<hr class="bar baz foo">' 

# tag with prefixed attributes
say h('hr', { data => { foo => 'bar' } });              # => '<hr data-foo="bar">'
say h('hr', { data => { foo => [qw(foo bar baz)] } });  # => '<hr data-foo="bar baz foo">'

# tag with value-less attribute
say h('script', { crossorigin => true }, ""); # <script crossorigin></script>

DESCRIPTION

This module is a html/xml tags generator like as hyperscript-ish style.

FEATURES

TAGSETS

This modules includes shorthand modules for writes tag name as subroutine.

Currently Supported:

HTML5: Text::HyperScript::HTML5

MODULE FUNCTIONS

text

This function generates html/xml escaped text.

raw

This function generates raw text without html/xml escape.

This function should be used for display trusted text content.

true / false (constants)

This constants use for value-less attributes.

For examples, if we'd like to use crossorigin attriute on script tag, we're able to use these contants like this:

use feature qw(say);

say h('scirpt', { crossorigin => true }, '')
# => <scritp crossorigin></script>

false constants exists for override value-less attributes. If set false to value-less attribute, that attribute ignored.

h

This function makes html/xml text from perl code.

The first argument is tag name, and after argument could be passed these values as repeatable.

NOTICE:

The all element attributes sorted by ascendant.

This behaviour is intentional for same result of reproducible output.

LICENSE

Copyright (C) OKAMURA Naoki a.k.a nyarla.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

OKAMURA Naoki a.k.a nyarla: nyarla@kalaclista.com