remove hardcoded version strings
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / XML / Simple.pm
1 package Catalyst::Action::Serialize::XML::Simple;
2
3 use Moose;
4 use namespace::autoclean;
5
6 extends 'Catalyst::Action';
7
8 # VERSION
9
10 sub execute {
11     my $self = shift;
12     my ( $controller, $c ) = @_;
13
14     eval {
15         require XML::Simple
16     };
17     if ($@) {
18         $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@")
19             if $c->debug;
20         return;
21     }
22     my $xs = XML::Simple->new(ForceArray => 0,);
23
24     my $stash_key = (
25             $controller->{'serialize'} ?
26                 $controller->{'serialize'}->{'stash_key'} :
27                 $controller->{'stash_key'} 
28         ) || 'rest';
29     my $output = $xs->XMLout({ data => $c->stash->{$stash_key} });
30     $c->response->output( $output );
31     return 1;
32 }
33
34 __PACKAGE__->meta->make_immutable;
35
36 1;