Added fix for RT 63537 (from Gerv) and tests to check it.
[catagits/Catalyst-Action-REST.git] / t / lib / Test / Serialize / Controller / REST.pm
CommitLineData
86fe5297 1package Test::Serialize::Controller::REST;
2
930013e6 3use namespace::autoclean;
4use Moose;
86fe5297 5
930013e6 6BEGIN { extends qw/Catalyst::Controller::REST/ };
86fe5297 7
8__PACKAGE__->config(
9 'namespace' => '',
10 'stash_key' => 'rest',
11 'map' => {
12 'text/html' => 'YAML::HTML',
13 'text/xml' => 'XML::Simple',
14 'text/x-yaml' => 'YAML',
d6fb033c 15 'application/json' => 'JSON',
86fe5297 16 'text/x-json' => 'JSON',
17 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
18 'text/x-data-denter' => [ 'Data::Serializer', 'Data::Denter' ],
19 'text/x-data-taxi' => [ 'Data::Serializer', 'Data::Taxi' ],
20 'application/x-storable' => [ 'Data::Serializer', 'Storable' ],
21 'application/x-freezethaw' =>
22 [ 'Data::Serializer', 'FreezeThaw' ],
23 'text/x-config-general' =>
24 [ 'Data::Serializer', 'Config::General' ],
25 'text/x-php-serialization' =>
26 [ 'Data::Serializer', 'PHP::Serialization' ],
27 'text/view' => [ 'View', 'Simple' ],
f7754f67 28 'text/explodingview' => [ 'View', 'Awful' ],
86fe5297 29 'text/broken' => 'Broken',
92d78e8f 30 'text/javascript', => 'JSONP',
31 'application/x-javascript' => 'JSONP',
32 'application/javascript' => 'JSONP',
178f8470 33 'text/my-csv' => [
34 'Callback', {
35 deserialize => sub { return {split /,/, shift } },
36 serialize => sub { my $d = shift; join ',', %$d }
37 }
38 ],
86fe5297 39 },
40);
41
42sub monkey_put : Local : ActionClass('Deserialize') {
43 my ( $self, $c ) = @_;
21d3f6ae 44 if ( ref($c->req->data) eq "HASH" ) {
c93a41f2 45 my $out = ($c->req->data->{'sushi'}||'') . ($c->req->data->{'chicken'}||'');
c6c4ff28 46 utf8::encode($out);
47 $c->res->output( $out );
21d3f6ae 48 } else {
49 $c->res->output(1);
50 }
86fe5297 51}
52
53sub monkey_get : Local : ActionClass('Serialize') {
54 my ( $self, $c ) = @_;
55 $c->stash->{'rest'} = { monkey => 'likes chicken!', };
56}
57
8aa1a2ee 58sub xss_get : Local : ActionClass('Serialize') {
59 my ( $self, $c ) = @_;
60 $c->stash->{'rest'} = { monkey => 'likes chicken > sushi!', };
61}
62
63
86fe5297 641;