Commit | Line | Data |
e601adda |
1 | # |
2 | # Catlyst::Action::Serialize::XML::Simple.pm |
be3c588a |
3 | # Created by: Adam Jacob, Marchex, <adam@hjksolutions.com> |
e601adda |
4 | # Created on: 10/12/2006 03:00:32 PM PDT |
5 | # |
6 | # $Id$ |
7 | |
8 | package Catalyst::Action::Serialize::XML::Simple; |
9 | |
10 | use strict; |
11 | use warnings; |
12 | |
13 | use base 'Catalyst::Action'; |
14 | |
15 | sub execute { |
16 | my $self = shift; |
17 | my ( $controller, $c ) = @_; |
18 | |
19 | eval { |
20 | require XML::Simple |
21 | }; |
22 | if ($@) { |
d4611771 |
23 | $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@") |
24 | if $c->debug; |
e601adda |
25 | return 0; |
26 | } |
27 | my $xs = XML::Simple->new(ForceArray => 0,); |
28 | |
faf5c20b |
29 | my $stash_key = ( |
07682cbc |
30 | $controller->{'serialize'} ? |
31 | $controller->{'serialize'}->{'stash_key'} : |
32 | $controller->{'stash_key'} |
faf5c20b |
33 | ) || 'rest'; |
e601adda |
34 | my $output; |
35 | eval { |
36 | $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); |
37 | }; |
38 | if ($@) { |
39 | return $@; |
40 | } |
41 | $c->response->output( $output ); |
42 | return 1; |
43 | } |
44 | |
45 | 1; |