Cherry pick everything bar the use parent change from 25d49c2, fixing RT#46680
[catagits/Catalyst-Action-Serialize-Data-Serializer.git] / lib / Catalyst / Action / Serialize / XML / Simple.pm
CommitLineData
e601adda 1package Catalyst::Action::Serialize::XML::Simple;
2
3use strict;
4use warnings;
5
6use base 'Catalyst::Action';
7
8sub execute {
9 my $self = shift;
10 my ( $controller, $c ) = @_;
11
12 eval {
13 require XML::Simple
14 };
15 if ($@) {
d4611771 16 $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@")
17 if $c->debug;
e601adda 18 return 0;
19 }
20 my $xs = XML::Simple->new(ForceArray => 0,);
21
faf5c20b 22 my $stash_key = (
07682cbc 23 $controller->{'serialize'} ?
24 $controller->{'serialize'}->{'stash_key'} :
25 $controller->{'stash_key'}
faf5c20b 26 ) || 'rest';
e601adda 27 my $output;
28 eval {
29 $output = $xs->XMLout({ data => $c->stash->{$stash_key} });
30 };
31 if ($@) {
32 return $@;
33 }
34 $c->response->output( $output );
35 return 1;
36}
37
381;