Split into new dist
[catagits/Catalyst-Action-Serialize-Data-Serializer.git] / t / lib / Test / Serialize / Controller / REST.pm
1 package Test::Serialize::Controller::REST;
2
3 use namespace::autoclean;
4 use Moose;
5
6 BEGIN { extends qw/Catalyst::Controller::REST/ };
7
8 __PACKAGE__->config(
9     'namespace' => '',
10     'stash_key' => 'rest',
11     'map'       => {
12         'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
13         'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],
14         'text/x-data-taxi'   => [ 'Data::Serializer', 'Data::Taxi' ],
15         'application/x-storable' => [ 'Data::Serializer', 'Storable' ],
16         'application/x-freezethaw' =>
17             [ 'Data::Serializer', 'FreezeThaw' ],
18         'text/x-config-general' =>
19             [ 'Data::Serializer', 'Config::General' ],
20         'text/x-php-serialization' =>
21              [ 'Data::Serializer', 'PHP::Serialization' ],
22     },
23 );
24
25 sub monkey_put : Local : ActionClass('Deserialize') {
26     my ( $self, $c ) = @_;
27     if ( ref($c->req->data) eq "HASH" ) {
28         my $out = ($c->req->data->{'sushi'}||'') . ($c->req->data->{'chicken'}||'');
29         utf8::encode($out);
30         $c->res->output( $out );
31     } else {
32         $c->res->output(1);
33     }
34 }
35
36 sub monkey_get : Local : ActionClass('Serialize') {
37     my ( $self, $c ) = @_;
38     $c->stash->{'rest'} = { monkey => 'likes chicken!', };
39 }
40
41 sub xss_get : Local : ActionClass('Serialize') {
42     my ( $self, $c ) = @_;
43     $c->stash->{'rest'} = { monkey => 'likes chicken > sushi!', };
44 }
45
46
47 1;