Commit | Line | Data |
3fea05b9 |
1 | package Catalyst::Action::Serialize::XML::Simple; |
2 | |
3 | use Moose; |
4 | use namespace::autoclean; |
5 | |
6 | extends 'Catalyst::Action'; |
7 | |
8 | our $VERSION = '0.85'; |
9 | $VERSION = eval $VERSION; |
10 | |
11 | sub execute { |
12 | my $self = shift; |
13 | my ( $controller, $c ) = @_; |
14 | |
15 | eval { |
16 | require XML::Simple |
17 | }; |
18 | if ($@) { |
19 | $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@") |
20 | if $c->debug; |
21 | return; |
22 | } |
23 | my $xs = XML::Simple->new(ForceArray => 0,); |
24 | |
25 | my $stash_key = ( |
26 | $controller->{'serialize'} ? |
27 | $controller->{'serialize'}->{'stash_key'} : |
28 | $controller->{'stash_key'} |
29 | ) || 'rest'; |
30 | my $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); |
31 | $c->response->output( $output ); |
32 | return 1; |
33 | } |
34 | |
35 | 1; |