Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Catalyst / Action / Deserialize / XML / Simple.pm
CommitLineData
3fea05b9 1package Catalyst::Action::Deserialize::XML::Simple;
2
3use Moose;
4use namespace::autoclean;
5
6extends 'Catalyst::Action';
7
8our $VERSION = '0.85';
9$VERSION = eval $VERSION;
10
11sub 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
471;