Thank you both for your answers! Michael Peters wrote: > On 11/13/2009 08:26 AM, Tobias Nissen wrote: >> For the data to be escaped before feeding it to H::T, I'd have to >> add a lot of code, therefore I'd like to avoid this approach. Is >> there any way I can tell H::T to escape Unicode data I feed to it >> with param()? > > You could create a function if you were using HTML::Template::Expr or > you could subclass HTML::Template and change param to first filter > the unicode chars for you. Then pass it off to the base class to do > the rest. Would be an extremely simple subclass.
Indeed... package MyHT; use base 'HTML::Template'; sub param { return SUPER::param(escape(@_)) } sub escape { ... escape magic ... } 1; Or something like that. >> If not, then the next best thing would be to create a patched >> version of H::T for my purposes with a method like param_escape() >> or sth like that, right? > > No, please don't do that. Don't run with a patched version unless > absolutely necessary. Instead go with a subclass. You're right, that's the better approach. And at first it seemed like the right approach for my problem, because I didn't want to walk through complex data structures to escape characters. I thought it would be enough to call a simple escaping function[0] for each value (in (key, value)) param() gets passed. But it turned out to be insufficient, since I was already passing data structures consisting of arrays /and/ hashes. Hence I had to walk through the whole shebang... At that moment a wrapper would just have meant more code, so now I'm just calling $ht_params = escape_unicode_for_rtf($ht_params) if $format eq 'rtf'; before passing the parameters to param(). If there were other formats (and not just RTF) where unicode sequences were to escape, then I'd use a wrapper to enhance code readability, I think. [0] i.e. one that takes every argument and escapes unicode sequences in it. This would work for arrays, hashes and scalars. But that's it then.
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________ Html-template-users mailing list Html-template-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/html-template-users