HTML-Native
view release on metacpan or search on metacpan
lib/HTML/Native/Document.pm view on Meta::CPAN
my $doc = HTML::Native::Document::XHTML10::Strict->new ( "Home" );
my $body = $doc->body;
push @$body, (
[ h1 => "Welcome" ],
"Hello world!"
);
print $doc;
# prints:
# <?xml version="1.0" encoding="UTF-8"?>
# <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
# "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
# < html xmlns="http://www.w3.org/1999/xhtml">
# <head><title>Home</title></head>
# <body><h1>Welcome</h1>Hello world!</body>
# </html>
=head1 DESCRIPTION
L<HTML::Native::Document> provides several predefined HTML document
types:
=over 4
=item HTML::Native::Document::XHTML10::Strict - XHTML 1.0 Strict
=item HTML::Native::Document::XHTML10::Transitional - XHTML 1.0 Transitional
=item HTML::Native::Document::XHTML10::Frameset - XHTML 1.0 Frameset
=item HTML::Native::Document::XHTML11 - XHTML 1.1
=item HTML::Native::Document::HTML401::Strict - HTML 4.01 Strict
=item HTML::Native::Document::HTML401::Transitional - HTML 4.01 Transitional
=item HTML::Native::Document::HTML401::Frameset - HTML 4.01 Frameset
=back
These can be used as the root element for an L<HTML::Native> document
lib/HTML/Native/Document.pm view on Meta::CPAN
use warnings;
sub new {
my $old = shift;
my $class = ref $old || $old;
my $title = shift || "";
my $self = $class->next::method ( $title,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
"<!DOCTYPE html PUBLIC ".
"\"-//W3C//DTD XHTML 1.0 Strict//EN\" ".
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" );
$self->{xmlns} = "http://www.w3.org/1999/xhtml";
return $self;
}
package HTML::Native::Document::XHTML10::Transitional;
use base qw ( HTML::Native::Document );
use mro "c3";
use strict;
use warnings;
sub new {
my $old = shift;
my $class = ref $old || $old;
my $title = shift || "";
my $self = $class->next::method ( $title,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
"<!DOCTYPE html PUBLIC ".
"\"-//W3C//DTD XHTML 1.0 Transitional//EN\" ".
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" );
$self->{xmlns} = "http://www.w3.org/1999/xhtml";
return $self;
}
package HTML::Native::Document::XHTML10::Frameset;
use base qw ( HTML::Native::Document );
use mro "c3";
use strict;
use warnings;
sub new {
my $old = shift;
my $class = ref $old || $old;
my $title = shift || "";
my $self = $class->next::method ( $title,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
"<!DOCTYPE html PUBLIC ".
"\"-//W3C//DTD XHTML 1.0 Frameset//EN\" ".
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n" );
$self->{xmlns} = "http://www.w3.org/1999/xhtml";
return $self;
}
package HTML::Native::Document::XHTML11;
use base qw ( HTML::Native::Document );
use mro "c3";
use strict;
use warnings;
sub new {
my $old = shift;
my $class = ref $old || $old;
my $title = shift || "";
my $self = $class->next::method ( $title,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
"<!DOCTYPE html PUBLIC ".
"\"-//W3C//DTD XHTML 1.1//EN\" ".
"\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" );
$self->{xmlns} = "http://www.w3.org/1999/xhtml";
return $self;
}
package HTML::Native::Document::HTML401::Strict;
use base qw ( HTML::Native::Document );
use mro "c3";
use strict;
lib/HTML/Native/JavaScript.pm view on Meta::CPAN
# <script type="text/javascript">//<![CDATA[
# document.write("<b>Hello World</b>");
# //]]></script>
=head1 DESCRIPTION
An L<HTML::Native::JavaScript> object represents a piece of JavaScript
code, either external or inline. It generates the C<< <script> >>
tag, and will wrap inline JavaScript code inside C<< //<![CDATA[ >>
and C<< //]]> >> markers to ensure correct interpretation by both HTML
and XHTML parsers.
=head1 METHODS
=cut
use HTML::Native qw ( is_html_attributes );
use HTML::Native::Literal;
use base qw ( HTML::Native );
use mro "c3";
use strict;
t/examples.t view on Meta::CPAN
HTML::Native::Comment->new ( "This is an error" ),
[ h1 => "Oh dear" ],
[ img => { src => "error.png" } ],
"Something went wrong",
],
HTML::Native::Literal->new ( "<hr />" ),
HTML::Native::JavaScript->new ( "\$(function() { alert ( \"boo!\" ); });" ),
);
is ( $html."\n", <<'EOF' );
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Testing</title><script src="script.js" type="text/javascript"></script></head>
<body><div class="error"><!-- This is an error --><h1>Oh dear</h1><img src="error.png" />Something went wrong</div><hr /><script type="text/javascript">//<![CDATA[
$(function() { alert ( "boo!" ); });
//]]></script></body>
</html>
EOF
}
{
( run in 1.428 second using v1.01-cache-2.11-cpan-49f99fa48dc )