Newer Older
65 lines | 1.432kb
copy gitweblite soruce code
root authored on 2012-11-23
1
package Mojolicious::Plugin::Charset;
2
use Mojo::Base 'Mojolicious::Plugin';
3

            
4
sub register {
5
  my ($self, $app, $conf) = @_;
6

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
7
  return unless my $c = $conf->{charset};
copy gitweblite soruce code
root authored on 2012-11-23
8
  $app->types->type(html => "text/html;charset=$c");
9
  $app->renderer->encoding($c);
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
10
  $app->hook(before_dispatch =>
11
      sub { shift->req->default_charset($c)->url->query->charset($c) });
copy gitweblite soruce code
root authored on 2012-11-23
12
}
13

            
14
1;
15

            
update Mojolicious to 4.57
Yuki Kimoto authored on 2013-12-02
16
=encoding utf8
17

            
copy gitweblite soruce code
root authored on 2012-11-23
18
=head1 NAME
19

            
20
Mojolicious::Plugin::Charset - Charset plugin
21

            
22
=head1 SYNOPSIS
23

            
24
  # Mojolicious
25
  $self->plugin(Charset => {charset => 'Shift_JIS'});
26

            
27
  # Mojolicious::Lite
28
  plugin Charset => {charset => 'Shift_JIS'};
29

            
30
=head1 DESCRIPTION
31

            
32
L<Mojolicious::Plugin::Charset> is a plugin to easily set the default charset
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
33
and encoding on all layers of L<Mojolicious>.
34

            
35
The code of this plugin is a good example for learning to build new plugins,
36
you're welcome to fork it.
copy gitweblite soruce code
root authored on 2012-11-23
37

            
38
=head1 OPTIONS
39

            
40
L<Mojolicious::Plugin::Charset> supports the following options.
41

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
42
=head2 charset
copy gitweblite soruce code
root authored on 2012-11-23
43

            
44
  # Mojolicious::Lite
45
  plugin Charset => {charset => 'Shift_JIS'};
46

            
47
Application charset.
48

            
49
=head1 METHODS
50

            
51
L<Mojolicious::Plugin::Charset> inherits all methods from
52
L<Mojolicious::Plugin> and implements the following new ones.
53

            
update Mojolicious and added...
Yuki Kimoto authored on 2013-03-20
54
=head2 register
copy gitweblite soruce code
root authored on 2012-11-23
55

            
upgraded Mojolicious to v3.7...
Yuki Kimoto authored on 2013-01-28
56
  $plugin->register(Mojolicious->new, {charset => 'Shift_JIS'});
copy gitweblite soruce code
root authored on 2012-11-23
57

            
update Mojolicious to 4.57
Yuki Kimoto authored on 2013-12-02
58
Register hook L<Mojolicious/"before_dispatch"> in application and change a few
59
defaults.
copy gitweblite soruce code
root authored on 2012-11-23
60

            
61
=head1 SEE ALSO
62

            
63
L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
64

            
65
=cut