Port Serialize classes except for View.
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / XML / Simple.pm
CommitLineData
e601adda 1package Catalyst::Action::Serialize::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 ) = @_;
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;
71cbfa6b 18 return;
e601adda 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';
71cbfa6b 27 my $output = $xs->XMLout({ data => $c->stash->{$stash_key} });
e601adda 28 $c->response->output( $output );
29 return 1;
30}
31
321;