HTML-HTML5-Builder
view release on metacpan or search on metacpan
lib/HTML/HTML5/Builder.pm view on Meta::CPAN
package HTML::HTML5::Builder;
use 5.010;
use base qw[Exporter];
use common::sense;
use constant { FALSE => 0, TRUE => 1 };
use constant XHTML_NS => 'http://www.w3.org/1999/xhtml';
use overload;
use utf8;
use warnings::register;
BEGIN {
$HTML::HTML5::Builder::AUTHORITY = 'cpan:TOBYINK';
}
BEGIN {
$HTML::HTML5::Builder::VERSION = '0.004';
}
use Carp 0 qw();
use HTML::HTML5::Builder::Document;
use HTML::HTML5::Entities 0.001 qw();
use Scalar::Util 0 qw(blessed);
use XML::LibXML 1.60 qw();
my (@elements, @uc_elements, @conforming);
our (@EXPORT_OK, @EXPORT, %EXPORT_TAGS);
BEGIN
{
@elements = qw{
a abbr acronym address applet area article aside audio b base
basefont bb bdo bgsound big blink blockquote body br button canvas
caption center cite code col colgroup command datagrid datalist
dd del details dfn dialog dir div dl dt em embed fieldset figure
figcaption font footer form frame frameset h1 h2 h3 h4 h5 h6
head header hgroup hr html i iframe img input ins isindex kbd
keygen label legend li link listing map mark marquee menu meta
meter nav nobr noembed noframes noscript object ol optgroup
option output p param plaintext pre progress q rp rt ruby s
samp script select section small source spacer span strike
strong style sub sup summary table tbody td textarea tfoot th
thead time title tr track tt u ul var video wbr xmp
};
@uc_elements = qw{Q Sub Time Map Meta Link S};
@conforming = qw{
a abbr address area article aside audio b base bb bdo blockquote
body br button canvas caption cite code col colgroup command
datagrid datalist dd del details dfn dialog div dl dt em embed
fieldset figure footer form h1 h2 h3 h4 h5 h6 head header hr html
i iframe img input ins kbd label legend li mark menu
meter nav noscript object ol optgroup option output p param
pre progress rp rt ruby samp script section select small source
span strong style sup table tbody td textarea tfoot th thead
title tr ul var video
};
my @cool_stuff = qw{COMMENT CHUNK XML_CHUNK RAW_CHUNK ELEMENT TEXT};
my @boilerplate = qw{JQUERY CREATIVE_COMMONS OPENGRAPH};
@EXPORT_OK = (@elements, @cool_stuff, @uc_elements, @boilerplate);
@EXPORT = ();
%EXPORT_TAGS = (
all => \@EXPORT_OK,
standard => [@conforming, @cool_stuff, qw{Q Sub Time Map Meta Link}],
default => \@EXPORT,
metadata => [qw(head title base Link Meta style)],
sections => [qw(body div section nav article aside h1 h2 h3 h4 h5 h6 header footer address)],
grouping => [qw(p hr br pre dialog blockquote ol ul li dl dt dd)],
text => [qw(a cite em strong small mark dfn abbr progress
meter code var samp kbd sup span i b bdo ruby rt rp Q Sub Time)],
embedded => [qw(figure img iframe embed object param video audio source
canvas area Map)],
tabular => [qw(table thead tbody tfoot th td colgroup col caption)],
form => [qw(form fieldset label input button select datalist
optgroup option textarea output)],
);
}
sub new
{
my ($class, %options) = @_;
bless \%options, $class;
}
sub ELEMENT
{
shift if blessed($_[0]) && $_[0]->isa(__PACKAGE__);
my ($el, @params) = @_;
if (warnings::enabled())
{
Carp::carp("Non-standard HTML element <$el>")
unless grep { lc $el eq $_ } @elements;
}
my $EL = XML::LibXML::Element->new($el);
$EL->setNamespace(XHTML_NS, undef, TRUE);
if ($el eq 'time' and blessed($params[0]) and $params[0]->isa('DateTime'))
{
my $dt = shift @params;
my $string = $dt->strftime('%FT%T');
if ($dt->time_zone->is_utc)
{
$string .= 'Z';
}
elsif (!$dt->time_zone->is_floating)
{
my $zone = $dt->strftime('%z');
$zone =~ s/^(.\d{2})(\d{2})$/$1:$2/;
$string .= $zone;
( run in 2.253 seconds using v1.01-cache-2.11-cpan-d7f47b0818f )