You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by David Nicol <da...@gmail.com> on 2005/04/20 18:52:22 UTC

how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)

the following snippet allows stating things like 

      use Entitize;
      ...
      print qq{<input name="data" value="$Entitize{$old_data}">\n};
      ... 
      print qq{The full text of the block is <pre>$Entitize{$block}</pre>\n};

directly, rather that using the generating functions of CGI.pm, or making
intermediate variables to hold the results of encode_entities calls. (nothing
against them, but here's Another Way To Do It)

cat > lib/Entitize.pm <<EOF
     package Entitize;
     use HTML::Entities;
     use Tie::Function;
     tie my %Entitize, 'Tie::Function' => \&encode_entities;
     sub import{ *{caller().'::Entitize'} = \%Entitize };
     1;
EOF

These three lines are too small to bother wrapping up in Entitize.pm
and publishing to CPAN, in my opinion.  You want it, it will copy and
paste into your cygwin bash or xterm.  Opinions are subject to change.


-- 
David L Nicol
"Oh, shit." -- Jane Fonda

Re: how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)

Posted by Ken Williams <ke...@mathforum.org>.
On Apr 21, 2005, at 12:10 PM, David Nicol wrote:

> $ perl -wc -e 'use strict; the deer and antelope play ; print 1'
> -e syntax OK
>


% perl -wc -Mstrict -e 'The deer and antelope play until tiger comes; \
                         chomp, kill, die time'
-e syntax OK


Re: how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)

Posted by David Nicol <da...@gmail.com>.
On 4/21/05, Ken Williams <ke...@mathforum.org> wrote:
 
> True, but it's not too small to submit as a patch for HTML::Entities.
> 
>   -Ken

or even a doc-patch for HTML::Entities.  I think my political goal here is
fame points through getting Tie::Function into wider use.

HTML::Entities is widely deployed and if it was to start exporting %Entitize
that would break most of my code that uses it -- I am probably alone in that 
though.

-- 
David L Nicol
$ perl -wc -e 'use strict; the deer and antelope play ; print 1'
-e syntax OK

Re: how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)

Posted by Ken Williams <ke...@mathforum.org>.
On Apr 20, 2005, at 11:52 AM, David Nicol wrote:

> These three lines are too small to bother wrapping up in Entitize.pm
> and publishing to CPAN, in my opinion.

True, but it's not too small to submit as a patch for HTML::Entities.

  -Ken