0.60 release branch
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / Data / Serializer.pm
CommitLineData
7ad87df9 1#
2# Catalyst::Action::Serialize::Data::Serializer
3# Created by: Adam Jacob, Marchex, <adam@marchex.com>
4#
5# $Id$
6
7package Catalyst::Action::Serialize::Data::Serializer;
8
9use strict;
10use warnings;
11
12use base 'Catalyst::Action';
13use Data::Serializer;
14
15sub execute {
16 my $self = shift;
17 my ( $controller, $c, $serializer ) = @_;
18
e601adda 19 my $stash_key = $controller->config->{'serialize'}->{'stash_key'} || 'rest';
20 my $sp = $serializer;
21 $sp =~ s/::/\//g;
22 $sp .= ".pm";
23 eval {
24 require $sp
25 };
26 if ($@) {
27 $c->log->debug("Could not load $serializer, refusing to serialize: $@");
28 return 0;
29 }
eccb2137 30 my $dso = Data::Serializer->new( serializer => $serializer );
e601adda 31 my $data;
32 eval {
33 $data = $dso->raw_serialize($c->stash->{$stash_key});
34 };
35 if ($@) {
36 return $@;
37 }
38 $c->response->output( $data );
7ad87df9 39 return 1;
eccb2137 40}
7ad87df9 41
421;