André Warnier wrote:
Hi.

I apologise if this is not really a mod_perl problem, but this list might be my best chance to find the competences required for some tips.

Platform : SunOS 5.8 (Solaris 8)
Apache : Apache/2.0.52
Perl : v5.8.5 built for sun4-solaris
CGI.pm : 3.37

That version of CGI.pm has support for what you need:

    use CGI qw( -utf8 );

Although the documentation warns it will interfere with file uploads.

As an alternative, below is a customization I've been using that tries to keep file uploads intact. It's been running live for almost 3 years now. The code looks pretty similar to what's in CGI 3.37, so maybe that warning is just FUD. I suggest you test either solution before believing me ;-)

Usage: Add it to your startup.pl, or add a "use CGI::as_utf;". It assumes you always use the object interface.

Rhesa


package CGI::as_utf;

BEGIN
{
    use strict;
    use warnings;
    use CGI;
    use Encode;

    {
        no warnings 'redefine';
        my $param_org = \&CGI::param;

        my $might_decode = sub {
            my $p = shift;
            return ( !$p || ( ref $p && fileno($p) ) )
                ? $p
                : eval { decode_utf8($p) } || $p;
        };

        *CGI::param = sub {
            my $q = $_[0];    # assume object calls always
            my $p = $_[1];

            goto &$param_org if scalar @_ != 2;

            return wantarray
                ? map { $might_decode->($_) } $q->$param_org($p)
                : $might_decode->( $q->$param_org($p) );
            }
    }
}


1;


Reply via email to