in reply to Module Ideas - Tie::HTMLencode and Tie::UrlEncode

I ain't sure how useful it would be. The point of it would be to print something easily in a HTMl-escaped format (I think you mean escaped, not so much encoded). The problem is that tie-ing means whenever you access that variable, you get the HTML-escaped version. So, for example, this:

$input =~ s/\<script\>/<script type='text/javascript'>/;

might not work as you expect.

You might prefer to use overload to overload the string operator. (NB: this is fairly new and tricky - I've had core dumps.)

dave hj~

Replies are listed 'Best First'.
Re: Re: Module Ideas - Tie::HTMLencode and Tie::UrlEncode
by rrwo (Friar) on Feb 22, 2002 at 02:42 UTC

    Well, one can use an OOP-interface, like so:

    my $thing = "<htmlishness>"; # $thing is tied my $obj = tied($thing); $obj->raw() # or some such accessor

    It's an experimental idea, so you can make sure you don't emit any un-encoded variables. Kind of like automatic taint-checking and encoding.

    I figured "what the heck" and uploaded a quick test to CPAN as Tie::HTML::Entities. Needs work, I'm sure.