# check for HTML errors
sub cgiapp_postrun {
my ($self, $o) = @_;
# parse the output with HTML::Lint
my $lint = HTML::Lint->new();
$lint->parse($$o);
$lint->eof();
# if there were errors put them into a
# new window
if ($lint->errors) {
my $err_text = "<ul>".
join("", map { "<li>$_</li>" }
map { s/&/&/g;
s/</</g;
s/>/>/g;
s/\\/\\\\/g;
s/"/\\"/g;
$_; }
map { $_->as_string }
$lint->errors).
"</ul>";
my $js = <<END;
<script language="javascript">
var html_lint_window = window.open("", "html_lint_window", "height=300,width=600");
html_lint_window.document.write("<html><head><title>HT ML Errors Detected</title></head><body><h1>HTML Errors Detected</h1>$err_text</body></html>");
html_lint_window.document.close();
html_lint_window.focus();
</script>
END
# insert the js code before the body close,
# if one exists
if ($$o =~ m!</body>!) {
$$o =~ s!</body>!$js\n</body>!;
} else {
$$o.= $js;
}
}
}
Using this code, when one or more HTML errors are detected a new window pops up with the errors in a list. The window is reused on future requests if not closed.
-sam
CGI::Application and HTML::Lint 0 Comments More | Login | Reply /