Commit | Line | Data |
256c894f |
1 | package Catalyst::Controller::REST; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | use base 'Catalyst::Controller'; |
5511d1ff |
6 | use Params::Validate qw(:all); |
256c894f |
7 | |
8 | __PACKAGE__->mk_accessors(qw(serialize)); |
9 | |
10 | __PACKAGE__->config( |
11 | serialize => { |
eccb2137 |
12 | 'default' => 'YAML', |
256c894f |
13 | 'stash_key' => 'rest', |
eccb2137 |
14 | 'map' => { |
15 | 'text/x-yaml' => 'YAML', |
7ad87df9 |
16 | 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ], |
17 | }, |
256c894f |
18 | } |
19 | ); |
20 | |
5511d1ff |
21 | sub begin : ActionClass('Deserialize') {} |
22 | |
23 | sub end : ActionClass('Serialize') { } |
24 | |
25 | sub status_created { |
26 | my $self = shift; |
27 | my $c = shift; |
28 | my %p = validate(@_, |
29 | { |
30 | location => { type => SCALAR | OBJECT }, |
31 | entity => { optional => 1 }, |
32 | }, |
33 | ); |
256c894f |
34 | |
5511d1ff |
35 | my $location; |
36 | if (ref($p{'location'})) { |
37 | $location = $p{'location'}->as_string; |
38 | } |
39 | $c->response->status(201); |
40 | $c->response->header('Location' => $location); |
41 | if (exists($p{'entity'})) { |
42 | $c->stash->{$self->config->{'serialize'}->{'stash_key'}} = $p{'entity'}; |
43 | } |
44 | return 1; |
eccb2137 |
45 | } |
256c894f |
46 | |
47 | 1; |