Hi Jozef,

I'd like Mason to handle encoding intelligently, but since I don't regularly 
work with utf8, you and others will have to help me with the design.

This should probably be in a plugin, e.g. Mason::Plugin::UTF8.

Some have already thought about this on stackoverflow:

   http://stackoverflow.com/questions/5858596/how-to-make-mason2-utf8-clean

So for the things you particularly mention, something like this might work:

   package Mason::Plugin::UTF8;
   use Moose;
   with 'Mason::Plugin';
   1;

   package Mason::Plugin::UTF8::Request;
   use Mason::PluginRole;
   use Encode;

   # Encode all output in utf8 - ** only works with Mason 2.13 and beyond **
   #
   after 'process_output' => sub {
       my ($self, $outref) = @_;
       $$outref = encode_utf8( $$outref );
   };

   # Decode all parameters as utf8
   #
   around 'run' => sub {
       my $orig = shift;
       my $self = shift;
   
       my %params = @_;
       while (my ($key, $value) = each(%params)) {
           $value = decode_utf8($value);
       }
       $self->$orig(%params);
   }
   
   1;

It would probably be best if you or someone else knowledgable about utf8 issues 
created this plugin rather than myself. But let me know if there are things 
needed in the Mason core to make this easier.

Jon


On Jul 26, 2011, at 3:51 AM, Jozef Mojzis wrote:

> Hi Jon,
> 
> Please, can you post some guidelines, how to correctly use Mason2 in the utf8 
> environment?
> 
> PSGI (plackup) want bytes, therefore even with the next simple component - 
> /index.mc:
> 
> <%init>
> use utf8;
> my $name = "ödön";
> </%init>
> Hello <% uc($name) %>
> 
> plackup throw error with the message:
>> Body must be bytes and should not contain wide characters (UTF-8 strings)
> 
> What is correct way deal with this issue? (so, where to do 
> Encode::{de|en}code_utf8?)
> 
> Especially:
> 1. components output with utf8
> 2. handling utf8 GET/POST arguments...
> 
> Thank you for help.
> jm


------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to