Mason::Plugin::WithEncoding - Add encoding support to Poet/Mason apps
version 0.2
In your Poet config file: # This is important or the first (and *only* the first) request will # not use Plack::Request::WithEncoding server.load_modules: - Mason::Plugin::WithEncoding mason: extra_plugins: - WithEncoding server.encoding.request: UTF-8 server.encoding.response: UTF-8 server.default_content_type: text/html; charset=UTF-8
To decode the request, the plugin loads Plack::Request::WithEncoding and configures it with the encoding specified in server.encoding.request. If no such setting is found, the request is not decoded. This matches the default behaviour of Poet/Mason, but is different from Plack::Request::WithEncoding, (which would normally default to UTF-8).
server.encoding.request
Output generated by your Mason templates is encoded according to the setting in server.encoding.response. If no such setting is found, the response is not encoded. This is the default behaviour of Poet/Mason.
server.encoding.response
The content-type default header is set according to server.default_content_type. If no such setting is found, the default header is text/html, as in the default Poet/Mason setup. This tells the client what encoding to use when decoding our content, and also (AFAIK) tells the client what encoding to use when sending us data.
server.default_content_type
text/html
Output sent through send_json is also encoded and the content-type header set accordingly.
send_json
This plugin only works inside a Poet environment.
The send_json method added to the Mason request object by Poet always encodes its output as UTF8, which is pretty much always the correct thing to do. But if you are using some other encoding, you'll need to patch this plugin to get send_json to use that instead of UTF8.
http://stackoverflow.com/questions/27806684/mason2-wrong-utf8-encoding-with-the-go-method http://stackoverflow.com/questions/5858596/how-to-make-mason2-utf-8-clean https://www.mail-archive.com/mason-users@lists.sourceforge.net/msg03450.html
Dave Baird <dave@zerofive.co.uk>
This software is copyright (c) 2016 by David R. Baird.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Mason::Plugin::WithEncoding, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mason::Plugin::WithEncoding
CPAN shell
perl -MCPAN -e shell install Mason::Plugin::WithEncoding
For more information on module installation, please visit the detailed CPAN module installation guide.