Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: CGI.pm: automatically decode param()

by moritz (Cardinal)
on Sep 03, 2007 at 10:51 UTC ( [id://636714]=note: print w/replies, xml ) Need Help??


in reply to Re^3: CGI.pm: automatically decode param()
in thread CGI.pm: automatically decode param()

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;

Replies are listed 'Best First'.
Re^5: CGI.pm: automatically decode param()
by rhesa (Vicar) on Sep 04, 2007 at 12:02 UTC
    Watch out for file upload fields: if you utf-encode $q->param('upload'), you'll mangle the underlying filehandle. I use an override that's pretty much the same as yours, except that I added the following check:
    sub param { my $self = shift; if (@_ == 1){ my @val = $self->SUPER::param(@_); @val = map { maybe_decode( $_ ) } @val; # rest of your param() } sub maybe_decode { my $p = shift; return ( !$p || ( ref $p && fileno($p) ) ) ? $p : encode('utf8', $p); }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://636714]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-19 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found