The relevant code in
HTML::Element->starttag is this:
if ( scalar $self->content_list == 0 && $self->_empty_element_map-
+>{ $self->tag } ) {
return $tag . " />";
}
else {
return $tag . ">";
}
Since hr, br, and img never have children, the first condition is always true. So we'll have to tweak the second one to get the output you want.
Here's a quick hack that works:
#!/usr/local/bin/perl
use strict;
use warnings;
use HTML::TreeBuilder;
my $h = HTML::Element->new_from_lol(
['html',
['hr'],
['br'],
['img', {src => 'pic.jpg'}],
],
);
{
# suppress xhtml /> on these tags:
my @noslash = qw/ hr br img /;
# by temporarily pretending the can have content:
local @HTML::Tagset::emptyElement{ @noslash } = 0;
# and have optional end tags:
local @HTML::Tagset::optionalEndTag{ @noslash } = (1) x @noslash;
print $h->as_HTML;
}
__END__
<html><hr><br><img src="pic.jpg"></html>