in reply to CGI.pm: automatically decode param()

Somewhere between 3.15 and 3.29 there was utf8 encoding added. I'm not sure if it will solve your problem(s) but maybe upgrading helps. The following was added to the param() method:

my $charset = $self->charset || ''; my $utf8 = $charset eq 'utf-8'; if ($utf8) { eval "require Encode; 1;" if $utf8 && !Encode->can('decode'); # +bring in these functions return wantarray ? map {Encode::decode(utf8=>$_) } @{$self->{$na +me}} : Encode::decode(utf8=>$self->{$name}->[0]); } else { return wantarray ? @{$self->{$name}} : $self->{$name}->[0]; }

Replies are listed 'Best First'.
Re^2: CGI.pm: automatically decode param()
by moritz (Cardinal) on Sep 03, 2007 at 09:38 UTC
    Sorry, I missed to say: upgrading is not an option because I don't have administrative access on the server. (It runs Debian Stable. So let's hope for a fast release of Lenny ;-))

      Have you considered installing your own private Perl library then? Installing locally is easy for modules that you can simply copy, like CGI.pm. I haven't look at a workaround to make PREFIX work with Debian, so you'll have some trouble if you want to install Perl modules locally using the standard <c>perl Makefile.PL PREFIX=~moritz/perl-lib; make test; make install

      dance.

        Sooner or later I'll have to do that I think.

        My current approach is a wrapper (not yet tested), I haven't decided yet which approach I like better (or which I detest less ;-)

        package MyCGI; use base CGI; use strict; use warnings; use Encode qw(encode); sub param { my $self = shift; if (@_ == 1){ my @val = $self->SUPER::param(@_); @val = map { encode("utf8", $_) } @val; return wantarray ? @val : $val[0]; } else { return $self->SUPER::param(@_); } } 1;