[Petal] control over encoding

Benjamin Tucker ben at greenriver.org
Thu Jul 27 07:37:02 BST 2006


Hi all,

I'm new to Petal and the list, so I apologize if this is something  
that's been discussed before.  I spent the better part of today  
integrating Petal into a mod_perl-based CMS.  All went very well with  
one exception.  There are a number of methods I had wanted to expose  
to the templates which return HTML.  Of course Petal helpfully  
encodes them.  I know that it provides the 'structure' keyword to  
turn this off, but I didn't want template authors to be forced to  
think about it, and rather wanted control from the data side of when  
escaping should not occur.

So my solution was I changed all the exposed methods that returned  
HTML to return the string as a scalar ref.  next I changed  
Petal::Hash::Var::process to not dereference scalar refs.  then I  
added to Petal::Hash::get_encoded logic not to not encode if $res is  
a scalar reference, and then dereferences $res.  (see attached patches).

Will this break anything?  is Petal::Hash::Var::process ever accessed  
without going through Petal::Hash::get_encoded?  Does anyone have a  
suggestion of a better solution.

Thanks!
Ben

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Hash.pm.diff
Type: application/octet-stream
Size: 602 bytes
Desc: not available
Url : https://lists.webarch.co.uk/pipermail/petal/attachments/20060727/1f31ed12/Hash.pm.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Var.pm.diff
Type: application/octet-stream
Size: 357 bytes
Desc: not available
Url : https://lists.webarch.co.uk/pipermail/petal/attachments/20060727/1f31ed12/Var.pm.obj


More information about the Petal mailing list