Additional pod cleanups
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Deserialize.pm
CommitLineData
7ad87df9 1#
2# Catlyst::Action::Deserialize
be3c588a 3# Created by: Adam Jacob, Marchex, <adam@hjksolutions.com>
7ad87df9 4#
5# $Id$
6
7package Catalyst::Action::Deserialize;
8
9use strict;
10use warnings;
11
e601adda 12use base 'Catalyst::Action::SerializeBase';
7ad87df9 13use Module::Pluggable::Object;
def65dcc 14use MRO::Compat;
7ad87df9 15
16__PACKAGE__->mk_accessors(qw(plugins));
17
18sub execute {
19 my $self = shift;
e601adda 20 my ( $controller, $c ) = @_;
7ad87df9 21
7ad87df9 22 my @demethods = qw(POST PUT OPTIONS);
eccb2137 23 my $method = $c->request->method;
24 if ( grep /^$method$/, @demethods ) {
9a76221e 25 my ( $sclass, $sarg, $content_type ) =
26 $self->_load_content_plugins( 'Catalyst::Action::Deserialize',
27 $controller, $c );
28 return 1 unless defined($sclass);
e601adda 29 my $rc;
eccb2137 30 if ( defined($sarg) ) {
e601adda 31 $rc = $sclass->execute( $controller, $c, $sarg );
7ad87df9 32 } else {
e601adda 33 $rc = $sclass->execute( $controller, $c );
34 }
9a76221e 35 if ( $rc eq "0" ) {
36 return $self->_unsupported_media_type( $c, $content_type );
37 } elsif ( $rc ne "1" ) {
38 return $self->_serialize_bad_request( $c, $content_type, $rc );
7ad87df9 39 }
9a76221e 40 }
e601adda 41
def65dcc 42 $self->maybe::next::method(@_);
e601adda 43
44 return 1;
eccb2137 45}
7ad87df9 46
398c5a1b 47=head1 NAME
48
49Catalyst::Action::Deserialize - Deserialize Data in a Request
50
51=head1 SYNOPSIS
52
53 package Foo::Controller::Bar;
54
55 __PACKAGE__->config(
faf5c20b 56 'default' => 'text/x-yaml',
57 'stash_key' => 'rest',
58 'map' => {
59 'text/x-yaml' => 'YAML',
60 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
61 },
398c5a1b 62 );
63
e601adda 64 sub begin :ActionClass('Deserialize') {}
398c5a1b 65
66=head1 DESCRIPTION
67
68This action will deserialize HTTP POST, PUT, and OPTIONS requests.
69It assumes that the body of the HTTP Request is a serialized object.
70The serializer is selected by introspecting the requests content-type
71header.
72
398c5a1b 73The specifics of deserializing each content-type is implemented as
74a plugin to L<Catalyst::Action::Deserialize>. You can see a list
75of currently implemented plugins in L<Catalyst::Controller::REST>.
76
77The results of your Deserializing will wind up in $c->req->data.
78This is done through the magic of L<Catalyst::Request::REST>.
79
e601adda 80While it is common for this Action to be called globally as a
81C<begin> method, there is nothing stopping you from using it on a
82single routine:
398c5a1b 83
e601adda 84 sub foo :Local :Action('Deserialize') {}
398c5a1b 85
e601adda 86Will work just fine.
398c5a1b 87
9a76221e 88When you use this module, the request class will be changed to
89L<Catalyst::Request::REST>.
90
398c5a1b 91=head1 SEE ALSO
92
93You likely want to look at L<Catalyst::Controller::REST>, which implements
94a sensible set of defaults for a controller doing REST.
95
96L<Catalyst::Action::Serialize>, L<Catalyst::Action::REST>
97
5cb5f6bb 98=head1 AUTHORS
398c5a1b 99
5cb5f6bb 100See L<Catalyst::Action::REST> for authors.
398c5a1b 101
102=head1 LICENSE
103
104You may distribute this code under the same terms as Perl itself.
105
106=cut
107
7ad87df9 1081;