package HTML::String::Overload;
use strictures 1;
use HTML::String::Value;
use B::Hooks::EndOfScope;
use overload ();
sub import {
my ($class, @opts) = @_;
overload::constant q => sub {
HTML::String::Value->new($_[1], @opts);
};
on_scope_end { __PACKAGE__->unimport };
}
sub unimport {
overload::remove_constant('q');
}
1;
__END__
=head1 NAME
HTML::String::Overload - Use constant overloading with L
=head1 SYNOPSIS
use HTML::String::Overload;
my $html = ''; # marked as HTML
no HTML::String::Overload;
my $text = ''; # not touched
my $html = do {
use HTML::String::Overload;
''; # marked as HTML
};
my $text = ''; # not touched
=head1 DESCRIPTION
This module installs a constant overload for strings - see
L in overload.pm's docs for how that works.
On import, we both set up the overload, and use L 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 C.
=head1 CAVEATS
Due to a perl bug (L),
you can't use backslash escapes in a string to be marked as HTML, so
use HTML::String::Overload;
my $html = "\n
foo
\n
";
will not be marked as HTML - instead you need to write
my $html = ''."\n".'
foo
'."\n".'';
which is annoying, so consider just using L and doing
my $html = html("\n
foo
\n");
in that case.
The import method we provide does actually take extra options for constructing
your L 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 L, which is definitely not user serviceable).
=head1 AUTHORS
See L for authors.
=head1 COPYRIGHT AND LICENSE
See L for the copyright and license.
=cut