Commit | Line | Data |
e601adda |
1 | # |
2 | # Catlyst::Action::Serialize::XML::Simple.pm |
3 | # Created by: Adam Jacob, Marchex, <adam@marchex.com> |
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 ($@) { |
23 | $c->log->debug("Could not load XML::Serializer, refusing to serialize: $@"); |
24 | return 0; |
25 | } |
26 | my $xs = XML::Simple->new(ForceArray => 0,); |
27 | |
28 | my $stash_key = $controller->config->{'serialize'}->{'stash_key'} || 'rest'; |
29 | my $output; |
30 | eval { |
31 | $output = $xs->XMLout({ data => $c->stash->{$stash_key} }); |
32 | }; |
33 | if ($@) { |
34 | return $@; |
35 | } |
36 | $c->response->output( $output ); |
37 | return 1; |
38 | } |
39 | |
40 | 1; |