Bump versions for release
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Deserialize / XML / Simple.pm
CommitLineData
e601adda 1package Catalyst::Action::Deserialize::XML::Simple;
2
930013e6 3use Moose;
4use namespace::autoclean;
e601adda 5
930013e6 6extends 'Catalyst::Action';
e601adda 7
3bb36dca 8our $VERSION = '0.82';
f465980c 9$VERSION = eval $VERSION;
10
e601adda 11sub execute {
12 my $self = shift;
13 my ( $controller, $c, $test ) = @_;
14
15 eval {
16 require XML::Simple;
17 };
18 if ($@) {
d4611771 19 $c->log->debug("Could not load XML::Simple, refusing to deserialize: $@")
20 if $c->debug;
e601adda 21 return 0;
22 }
23
24 my $body = $c->request->body;
25 if ($body) {
26 my $xs = XML::Simple->new('ForceArray' => 0,);
27 my $rdata;
28 eval {
29 $rdata = $xs->XMLin( "$body" );
30 };
31 if ($@) {
32 return $@;
33 }
34 if (exists($rdata->{'data'})) {
35 $c->request->data($rdata->{'data'});
36 } else {
37 $c->request->data($rdata);
38 }
39 } else {
40 $c->log->debug(
d4611771 41 'I would have deserialized, but there was nothing in the body!')
42 if $c->debug;
e601adda 43 }
44 return 1;
45}
46
471;