Commit | Line | Data |
e601adda |
1 | package Catalyst::Action::Serialize::XML::Simple; |
2 | |
930013e6 |
3 | use Moose; |
4 | use namespace::autoclean; |
e601adda |
5 | |
930013e6 |
6 | extends 'Catalyst::Action'; |
e601adda |
7 | |
8 | sub 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 | |
38 | 1; |