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; |
7f36b63e |
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'; |
7f36b63e |
27 | my $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); |
e601adda |
28 | $c->response->output( $output ); |
29 | return 1; |
30 | } |
31 | |
32 | 1; |