If someone need use Poet in utf8 env, the following is ok for start hacking.

You need modify two files generated by Poet in the app/lib/App/Mason directory:

A.) File Compilation.pm

package Madplant::Mason::Compilation;
use Poet qw($conf $poet);
use Poet::Moose;
extends 'Mason::Compilation';

# Add customizations to Mason::Compilation here.
#
# e.g. Add Perl code to the top of every compiled component
#
override 'output_class_header' => sub {
    return join("\n",
            super(),
            'use utf8;',
            'use Encode qw(encode decode);'
           );
};

1;

The above adds into every compiled *.obj compoment use utf8; and use Encode.

B.) Request.pm

package Madplant::Mason::Request;
use Poet qw($conf $poet);
use Poet::Moose;
use Encode qw(encode decode);
extends 'Mason::Request';

# Add customizations to Mason::Request here.
#
# e.g. Perform tasks before and after each Mason request
#
override 'run' => sub {
    my($self, $path, $args) = @_;

    #decode  args values what are Hash::Multivalue - keep the last value
    #unfortunately don't know how to replace each key with decode('UTF-8', $key)
    foreach my $k (keys %$args) {
        $args->set($k, decode('UTF-8', $args->get($k)));
    }

    my $result = super();

    #encode output
    $result->output( encode('UTF-8', $result->output()) );
    return $result;
};

1;

You must ensure than only values are decoded - not the keys. e,g. for URL
http://example.com/component?key1=value1&key2=value2
you can have utf8 only value1 and value2 - not key1 and key2

Jon, probably will make much better solution, but for the start this
is nearly usable. :)

Not tested much - probably it is not ready for production - only for hacking.

ak.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to