Using encoding and CGI Sessions/Cookies

ambs on 2010-01-03T17:10:50

I am trying to use CGI::Session (and of course, CGI::Cookie) together with 'use encoding "utf-8"', but things seems not to work.

The error is 'Can't locate object method "renewed" via package "Encode::utf8" at /usr/share/perl5/site_perl/5.10.0/CGI.pm' that seems to be common to other modules. For example, a google search shown similar problems with Safe.

I am not sure yet about who is responsbible for the bug, Encode, CGI::Session or CGI::Cookie. But if this kind of problem was detected previously probably somebody knows where is the problem and can point me to the correct place, so I can try to correct this bug.


Re: Using encoding and CGI Sessions/Cookies

daxim on 2010-01-04T12:00:59

Don't do that, it's buggy. http://stackoverflow.com/questions/492838#493508

What are you trying to achieve? The Encode module is enough for most cases. Read the first two of http://p3rl.org/UNI.

Re: Using encoding and CGI Sessions/Cookies

ambs on 2010-01-04T12:23:44

The truth is that I tried to not use the encoding pragma. I do not like it as well. I prefer to binmode file handles and normally that works.

But with CGIs I get some problems. First, I am not able to binmode Template Toolkit when it opens templates. Or at least I can't find documentation on that.

The other problem is how to control the encoding from the environment variables, from CGI param and other stuff like that. But for these I think my current solution uses Encode already.

I'll fight with this script later today.

Re: Using encoding and CGI Sessions/Cookies

daxim on 2010-01-05T12:15:41

> I am not able to binmode Template Toolkit when it opens templates. Or at least I can't find documentation on that.

my $tt = Template->new({ENCODING => 'utf8',})

Documented in http://search.cpan.org/perldoc?Template::FAQ#Why_do_I_get_rubbish_for_my_utf-8_t emplates?.

$tt->process($infile, $vars, $outfile, {binmode => ':utf8'},)

Documented in http://search.cpan.org/perldoc?Template#process(%24template%2C_%5C%25vars%2C_%24 output%2C_%25options).

> how to control the encoding from the environment variables, from CGI param [...] my current solution uses Encode already.

This is the way to go.

Re: Using encoding and CGI Sessions/Cookies

ambs on 2010-01-08T19:32:12

Encode seems to have problems by itself.

Can't locate object method "renewed" via package "Encode::utf8" at /usr/lib/perl5/site_perl/5.10.0/Encode.pm line 174. ,

And this happens from time to time... :-(