Is it correct to switch the default perl IO value to utf-8 when using Plack and Middlewares?

Two starting points:

Is it right to use

 use uni::perl; # or any similar 

in the PSGI application and / or in my modules?

uni::perl changes the default IO value for UTF-8, thus:

 use open qw(:std :utf8); binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); 

Will it tear something in Plaka or its average? Or is this the only right way to write applications for Plack explicitly encoding / decoding on opening, so without open pragma ?

+6
source share
2 answers

You really do not want to set STDIN / STDOUT to UTF-8 by default in Plack, because you do not know, for example, whether they will be binary data. For instance. if these file descriptors are FastCGI protocol connectors, they will have encoded binary structures, not UTF-8 text. Therefore, they should not have a certain level of coding, or these binary structures will be distorted or rejected as invalid.

+2
source

On modern GNU / Linux systems, you must completely switch to UTF-8 around the world. It means setting up

 LANG="xx_YY.UTF-8" PERL_UNICODE=SDAL PERL5OPT=-Mutf8 

in your /etc/environment or /etc/sysconfig/i18n or /etc/default/locale or whatever your system configuration file is. Due to a RHEL / Centos error, I designated /etc/environment before sysconfig/i18n .

Scripts that rely on binary input must set binmode to STDIN / OUT / ERR (?) Or use open pragma, or must be called with the -C0 option.

The problem is that some DBD drivers are erroneous, for example. DBD :: JDBC , and you must set the utf8 flag manually.

 use Encode qw/_utf8_on/; map { _utf8_on $_; } @strings; 
-1
source

Source: https://habr.com/ru/post/917950/


All Articles