Change all classes to Moose
[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 sub execute {
9     my $self = shift;
10     my ( $controller, $c ) = @_;
11
12     eval {
13         require XML::Simple
14     };
15     if ($@) {
16         $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@")
17             if $c->debug;
18         return 0;
19     }
20     my $xs = XML::Simple->new(ForceArray => 0,);
21
22     my $stash_key = (
23             $controller->{'serialize'} ?
24                 $controller->{'serialize'}->{'stash_key'} :
25                 $controller->{'stash_key'} 
26         ) || 'rest';
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
38 1;