Skip to content

Instantly share code, notes, and snippets.

@masaru-b-cl
Forked from anonymous/Charset.pm
Created August 10, 2016 00:48
Show Gist options
  • Save masaru-b-cl/fe7e763de65c6067b4a33326b058bb85 to your computer and use it in GitHub Desktop.
Save masaru-b-cl/fe7e763de65c6067b4a33326b058bb85 to your computer and use it in GitHub Desktop.
Mojolicious::Plugin::Charset;でエンコーディングとキャラセット分けて指定できるようにする
package Mojolicious::Plugin::Charset;
use Mojo::Base 'Mojolicious::Plugin';
sub register {
my ($self, $app, $conf) = @_;
return unless my $c = $conf->{charset};
return unless my $e = $conf->{encoding};
$app->types->type(html => "text/html;charset=$c");
$app->renderer->encoding($e);
$app->hook(before_dispatch =>
sub { shift->req->default_charset($e)->url->query->charset($e) });
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment