NAME
HTML::String::Overload - Use constant overloading with HTML::String
SYNOPSIS
use HTML::String::Overload;
my $html = '<h1>'; # marked as HTML
no HTML::String::Overload;
my $text = '<h1>'; # not touched
my $html = do {
use HTML::String::Overload;
'<h1>'; # marked as HTML
};
my $text = '<h1>'; # not touched
DESCRIPTION
This module installs a constant overload for strings - see "Overloading constants" in overload in overload.pm's docs for how that works.
On import, we both set up the overload, and use B::Hooks::EndOfScope to register a callback that will remove it again at the end of the block; you can remove it earlier by unimporting the module using no
.
CAVEATS
Due to a perl bug (https://rt.perl.org/rt3/Ticket/Display.html?id=49594), you can't use backslash escapes in a string to be marked as HTML, so
use HTML::String::Overload;
my $html = "<h1>\n<div>foo</div>\n</h1>";
will not be marked as HTML - instead you need to write
my $html = '<h1>'."\n".'<div>foo</div>'."\n".'</h1>';
which is annoying, so consider just using HTML::String and doing
my $html = html("<h1>\n<div>foo</div>\n</h1>");
in that case.
The import method we provide does actually take extra options for constructing your HTML::String::Value objects but I'm not yet convinced that's a correct public API, so use that feature at your own risk (the only example of this is in HTML::String::TT::Directive, which is definitely not user serviceable).
AUTHORS
See HTML::String for authors.
COPYRIGHT AND LICENSE
See HTML::String for the copyright and license.