Change all classes to Moose
[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
8sub execute {
9 my $self = shift;
10 my ( $controller, $c, $test ) = @_;
11
12 eval {
13 require XML::Simple;
14 };
15 if ($@) {
d4611771 16 $c->log->debug("Could not load XML::Simple, refusing to deserialize: $@")
17 if $c->debug;
e601adda 18 return 0;
19 }
20
21 my $body = $c->request->body;
22 if ($body) {
23 my $xs = XML::Simple->new('ForceArray' => 0,);
24 my $rdata;
25 eval {
26 $rdata = $xs->XMLin( "$body" );
27 };
28 if ($@) {
29 return $@;
30 }
31 if (exists($rdata->{'data'})) {
32 $c->request->data($rdata->{'data'});
33 } else {
34 $c->request->data($rdata);
35 }
36 } else {
37 $c->log->debug(
d4611771 38 'I would have deserialized, but there was nothing in the body!')
39 if $c->debug;
e601adda 40 }
41 return 1;
42}
43
441;