[Petal] Re: CPAN daily update

Jean-Michel Hiver jhiver at mkdoc.com
Tue Jan 13 20:17:50 GMT 2004


Yuval Kogman wrote:

>On Tue, Jan 13, 2004 at 10:03:27AM +0000, Jean-Michel Hiver wrote:
>
>  
>
>>At the moment the way it's set is that if either your $Petal::INPUT
>>or $Petal::OUTPUT (or the associated options in the constructor) are
>>set to 'HTML', then Petal will decode the HTML entities.
>>    
>>
>
>Is there any way to get petal to not touch entities at all?
>  
>
Mhh.

You could try to make a subclass of Petal which would double encode 
everything (i.e.   becomes  ) before sending it to Petal 
such as:

However there might be something horribly wrong with it. If it works, I 
might make it an experimental feature.


=================== %< ===================
package Petal::NoDecode;
use strict;
use warnings;
use base qw /Petal/;


sub _file_data_ref
{
    my $self = shift;
    my $file_path = $self->_file_path;
    $file_path =~ s/#.*$//;
    
    if ($] > 5.007)
    {
        my $encoding = Encode::resolve_alias ($DECODE_CHARSET) || 'utf8';
        open FP, "<:$encoding", "$file_path" || die 'Cannot read-open 
$file_path';
    }
    else
    {
        open FP, "<$file_path" || die 'Cannot read-open $file_path';
    }
    
    my $res = join '', <FP>;
    close FP;
    
    # kill template comments
    $res =~ s/\<!--\?.*?\-->//gsm;
    
    # double encode everything
    $res =~ s/&/&amp;/g;

    return \$res;
}


1;


__END__
=================== >% ===================

Tell us what happens... You might need to removed your cached templates 
(usually stored under /tmp/petal_cache_*) before testing.



More information about the Petal mailing list