1 package Catalyst::Action::Deserialize;
4 use namespace::autoclean;
6 extends 'Catalyst::Action::SerializeBase';
7 use Module::Pluggable::Object;
10 __PACKAGE__->mk_accessors(qw(plugins));
14 my ( $controller, $c ) = @_;
16 my @demethods = qw(POST PUT OPTIONS);
17 my $method = $c->request->method;
18 if ( grep /^$method$/, @demethods ) {
19 my ( $sclass, $sarg, $content_type ) =
20 $self->_load_content_plugins( 'Catalyst::Action::Deserialize',
22 return 1 unless defined($sclass);
24 if ( defined($sarg) ) {
25 $rc = $sclass->execute( $controller, $c, $sarg );
27 $rc = $sclass->execute( $controller, $c );
30 return $self->_unsupported_media_type( $c, $content_type );
31 } elsif ( $rc ne "1" ) {
32 return $self->_serialize_bad_request( $c, $content_type, $rc );
36 $self->maybe::next::method(@_);
43 Catalyst::Action::Deserialize - Deserialize Data in a Request
47 package Foo::Controller::Bar;
50 'default' => 'text/x-yaml',
51 'stash_key' => 'rest',
53 'text/x-yaml' => 'YAML',
54 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
58 sub begin :ActionClass('Deserialize') {}
62 This action will deserialize HTTP POST, PUT, and OPTIONS requests.
63 It assumes that the body of the HTTP Request is a serialized object.
64 The serializer is selected by introspecting the requests content-type
67 The specifics of deserializing each content-type is implemented as
68 a plugin to L<Catalyst::Action::Deserialize>. You can see a list
69 of currently implemented plugins in L<Catalyst::Controller::REST>.
71 The results of your Deserializing will wind up in $c->req->data.
72 This is done through the magic of L<Catalyst::Request::REST>.
74 While it is common for this Action to be called globally as a
75 C<begin> method, there is nothing stopping you from using it on a
78 sub foo :Local :Action('Deserialize') {}
82 When you use this module, the request class will be changed to
83 L<Catalyst::Request::REST>.
87 You likely want to look at L<Catalyst::Controller::REST>, which implements
88 a sensible set of defaults for a controller doing REST.
90 L<Catalyst::Action::Serialize>, L<Catalyst::Action::REST>
94 See L<Catalyst::Action::REST> for authors.
98 You may distribute this code under the same terms as Perl itself.