Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get CGI.pm to output HTML5 instead of XHTML 1.0?

I'm having some trouble getting CGI.pm to output to HTML5 instead of XHTML 1.0 or HTML 4.01. When I try "HTML5" or "HTML 5" as the -dtd argument in start_html() I get a document in HTML 4. I've also tried importing :HTML5, but that doesn't seem to work either. Any advice?

like image 944
CyberSkull Avatar asked May 13 '10 08:05

CyberSkull


3 Answers

Here's a fragment from some code where I 'solved' this problem using brute force.

# $html is accumulator for HTML string
my $html;

# <html> tag and <head> section
my $dtd      = '<!DOCTYPE html>';   # HTML5 DTD
my $title    = "Storage analysis of $HOSTNAME as of $TODAY";
$html    .= start_html(
    -title  => $title,
    -style  => {
        -code  => $css,
    }
);

# KLUDGE: CGI.pm doesn't support HTML5 DTD; replace the one it puts in.
$html    =~  s{<!DOCTYPE.*?>}{$dtd}s;
like image 30
Dan Hale Avatar answered Nov 13 '22 19:11

Dan Hale


  1. The correct doctype for HTML 5 is just "html", not "html5" or "html 5", and does not use a DTD. CGI.pm only supports well-formed DTDs, not arbitrary strings. Since the HTML 5 doctype does not include a well-formed DTD, CGI.pm (as of the current version, 3.49) does not support the HTML 5 doctype.

  2. Using CGI.pm's HTML-generation functions is generally frowned upon these days. Templating systems such as Template::Toolkit or HTML::Template are preferred for their ability to cleanly separate your code's logic from the formatting of its output. They also, incidentally, allow you to specify whatever doctype and code to whatever version of (X)HTML you choose.

like image 158
Dave Sherohman Avatar answered Nov 13 '22 19:11

Dave Sherohman


Here are some Perl5 frameworks that are HTML5 friendly:

Catalyst http://www.catalystframework.org/ Dancer http://perldancer.org/documentation Mojolicious http://mojolicio.us/

I'm leaning toward using Mojolicious for my newest Perl project.

All of these are more relevant for robust HTML5 apps than the CGI module. CGI still has its place and is still developed/supported but it does not address robust HTML5 apps as well as some of the frameworks that are out there.

like image 30
Lance Cleveland Avatar answered Nov 13 '22 19:11

Lance Cleveland