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 | |
7cc6122a | 8 | our $VERSION = '1.12'; |
f465980c | 9 | $VERSION = eval $VERSION; |
10 | ||
e601adda | 11 | sub execute { |
12 | my $self = shift; | |
13 | my ( $controller, $c ) = @_; | |
14 | ||
15 | eval { | |
16 | require XML::Simple | |
17 | }; | |
18 | if ($@) { | |
d4611771 | 19 | $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@") |
20 | if $c->debug; | |
7f36b63e | 21 | return; |
e601adda | 22 | } |
23 | my $xs = XML::Simple->new(ForceArray => 0,); | |
24 | ||
faf5c20b | 25 | my $stash_key = ( |
07682cbc | 26 | $controller->{'serialize'} ? |
27 | $controller->{'serialize'}->{'stash_key'} : | |
28 | $controller->{'stash_key'} | |
faf5c20b | 29 | ) || 'rest'; |
7f36b63e | 30 | my $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); |
e601adda | 31 | $c->response->output( $output ); |
32 | return 1; | |
33 | } | |
34 | ||
24748286 | 35 | __PACKAGE__->meta->make_immutable; |
36 | ||
e601adda | 37 | 1; |