Adding changelog entries
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Deserialize / XML / Simple.pm
CommitLineData
e601adda 1#
2# Catlyst::Action::Deserialize::XML::Simple.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
8package Catalyst::Action::Deserialize::XML::Simple;
9
10use strict;
11use warnings;
12
13use base 'Catalyst::Action';
14
15sub execute {
16 my $self = shift;
17 my ( $controller, $c, $test ) = @_;
18
19 eval {
20 require XML::Simple;
21 };
22 if ($@) {
23 $c->log->debug("Could not load XML::Simple, refusing to deserialize: $@");
24 return 0;
25 }
26
27 my $body = $c->request->body;
28 if ($body) {
29 my $xs = XML::Simple->new('ForceArray' => 0,);
30 my $rdata;
31 eval {
32 $rdata = $xs->XMLin( "$body" );
33 };
34 if ($@) {
35 return $@;
36 }
37 if (exists($rdata->{'data'})) {
38 $c->request->data($rdata->{'data'});
39 } else {
40 $c->request->data($rdata);
41 }
42 } else {
43 $c->log->debug(
44 'I would have deserialized, but there was nothing in the body!');
45 }
46 return 1;
47}
48
491;