15 Jan 2016 10:33:43 UTC
- Distribution: Mason-Plugin-WithEncoding
- Module version: 0.2
- Source (raw)
- Browse (raw)
- How to Contribute
- Testers (242 / 90 / 16)
- KwaliteeBus factor: 0
- 75.00% Coverage
- License: perl_5
- Perl: v5.12.0
- Activity24 month
- Download (20.2KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest versionDAVEBAIRD David R. Baird
Mason::Plugin::WithEncoding - Add encoding support to Poet/Mason apps
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).
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.
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.
Output sent through
send_jsonis also encoded and the content-type header set accordingly.
This plugin only works inside a Poet environment.
send_jsonmethod 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_jsonto 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://email@example.com/msg03450.html
Dave Baird <firstname.lastname@example.org>
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.
Module Install Instructions
To install Mason::Plugin::WithEncoding, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install Mason::Plugin::WithEncoding
For more information on module installation, please visit the detailed CPAN module installation guide.