Configuration patches to handle component based configuration in a sane way, as well...
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Deserialize / JSON.pm
1 #
2 # Catlyst::Action::Deserialize::JSON.pm
3 # Created by: Adam Jacob, Marchex, <adam@marchex.com>
4 # Created on: 10/12/2006 03:00:32 PM PDT
5 #
6 # $Id$
7
8 package Catalyst::Action::Deserialize::JSON;
9
10 use strict;
11 use warnings;
12
13 use base 'Catalyst::Action';
14 use JSON::Syck;
15
16 sub execute {
17     my $self = shift;
18     my ( $controller, $c, $test ) = @_;
19
20     my $body = $c->request->body;
21     my $rbody;
22
23     if ($body) {
24         while (my $line = <$body>) {
25             $rbody .= $line;
26         }
27     }
28
29     if ( $rbody ) {
30         my $rdata = eval { JSON::Syck::Load( $rbody ); };
31         if ($@) {
32             return $@;
33         }
34         $c->request->data($rdata);
35     } else {
36         $c->log->debug(
37             'I would have deserialized, but there was nothing in the body!')
38             if $c->debug;
39     }
40     return 1;
41 }
42
43 1;