summaryrefslogtreecommitdiffstats
path: root/lib/OXx/Encoding.pm
blob: 8e6103cd1f712b8d34d80e61435ab9f41d2b6122 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package OXx::Encoding;
use MooseX::Role::Parameterized;
use namespace::autoclean;

use Moose::Util 'with_traits';
use OXx::Encoding::Types;

parameter encoding => (
    isa      => 'Encoding',
    required => 1,
);

parameter html_encoding => (
    isa     => 'Str',
    lazy    => 1,
    default => sub { shift->encoding },
);

role {
    my $p = shift;

    around request_class => sub {
        my $orig = shift;
        my $self = shift;

        return with_traits($self->$orig(@_),
            'OXx::Encoding::Role::Request' => {
                encoding      => $p->encoding,
                html_encoding => $p->html_encoding,
            },
        );
    };
}

1;