2 # Catlyst::Action::Deserialize
3 # Created by: Adam Jacob, Marchex, <adam@marchex.com>
7 package Catalyst::Action::Deserialize;
12 use base 'Catalyst::Action';
13 use Module::Pluggable::Object;
14 use Catalyst::Request::REST;
16 __PACKAGE__->mk_accessors(qw(plugins));
20 my ( $controller, $c, $test ) = @_;
22 my $nreq = bless( $c->request, 'Catalyst::Request::REST' );
25 unless ( defined( $self->plugins ) ) {
26 my $mpo = Module::Pluggable::Object->new(
28 'search_path' => ['Catalyst::Action::Deserialize'],
30 my @plugins = $mpo->plugins;
31 $self->plugins( \@plugins );
33 my $content_type = $c->request->content_type;
34 my $sclass = 'Catalyst::Action::Deserialize::';
36 my $map = $controller->serialize->{'map'};
37 if ( exists( $map->{$content_type} ) ) {
39 if ( ref( $map->{$content_type} ) eq "ARRAY" ) {
40 $mc = $map->{$content_type}->[0];
41 $sarg = $map->{$content_type}->[1];
43 $mc = $map->{$content_type};
46 if ( !grep( /^$sclass$/, @{ $self->plugins } ) ) {
47 die "Cannot find plugin $sclass for $content_type!";
50 if ( exists( $controller->serialize->{'default'} ) ) {
51 $sclass .= $controller->serialize->{'default'};
53 die "I cannot find a default serializer!";
57 my @demethods = qw(POST PUT OPTIONS);
58 my $method = $c->request->method;
59 if ( grep /^$method$/, @demethods ) {
60 if ( defined($sarg) ) {
61 $sclass->execute( $controller, $c, $sarg );
63 $sclass->execute( $controller, $c );
65 $self->NEXT::execute( @_, );
67 $self->NEXT::execute(@_);