views:

290

answers:

2

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?

A: 

Patch the module to add support for HTML5 … or just output a Doctype manually, then use it as normal. If it is valid XHTML 1.0 or HTML 4.01 then it is valid HTML 5.

David Dorward
Impressive, up to four people thinking this is worth voting down … but not yet any willing to say why.
David Dorward
yeah, that's not cool
Galen
I think people are voting down because "patching" a CPAN module is generally a bad idea. Patching is likely bad advice. Inheritance or at least a monkey patch sound better.
codeholic
@codeholic First you write the patch, then you send the patch to the author ;)
hobbs
@hobbs ...and finally you wait for ages.
codeholic
If nobody patches it, where will version 3.50 come from?
Dave Sherohman
It's not that patching is a bad idea, but that using CGI.pm to create HTML is a bad idea. That makes patching CGI.pm to make HTML 5 a bad idea.
brian d foy
That's not really a helpful suggestion, I'm not in the mood to write a module, I just want to upgrade some old scripts.
CyberSkull
You're changing markup language to one which is in draft status because of your mood?!
David Dorward
"Patch the module" generally isn't a useful answer all by itself, especially when it's said so matter-of-factly, as though it's something everyone does all the time. Now that I've looked in CGI.pm, it appears that it's *intended* to be edited locally to adjust various global defaults; this answer could have mentioned that. It also could have given some guidance about which of the more than 7600 lines of code would be a good place to start making changes.
Rob Kennedy
The point was that CGI.pm doesn't do HTML 5, so you'll have to add support for it if you want it to.
David Dorward
+14  A: 
  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.

Dave Sherohman
Thanks. I've implemented a new version in using Template::Toolkit. Do you have any recommendations for HTTP handling modules?
CyberSkull
Personally, I've never had to do any low-level HTTP stuff myself beyond sending a Content-Type and some cookies, which is simple enough that you can get away with having CGI::Cookie generate the cookies, then just using `print` to send it all. If you post another question explaining exactly what kind of HTTP handling you want to do, I'm sure you'll get some good suggestions, though.
Dave Sherohman