Bump versions for release
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Deserialize / XML / Simple.pm
1 package Catalyst::Action::Deserialize::XML::Simple;
2
3 use Moose;
4 use namespace::autoclean;
5
6 extends 'Catalyst::Action';
7
8 our $VERSION = '0.82';
9 $VERSION = eval $VERSION;
10
11 sub execute {
12     my $self = shift;
13     my ( $controller, $c, $test ) = @_;
14
15     eval {
16         require XML::Simple;
17     };
18     if ($@) {
19         $c->log->debug("Could not load XML::Simple, refusing to deserialize: $@")
20             if $c->debug;
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(
41             'I would have deserialized, but there was nothing in the body!')
42                 if $c->debug;
43     }
44     return 1;
45 }
46
47 1;