Initial commit of Catalyst-Action-REST
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / Action / Serialize / YAML.pm
1 #
2 # Catlyst::Action::Serialize::YAML.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::YAML;
9
10 use strict;
11 use warnings;
12
13 use base 'Catalyst::Action';
14 use YAML::Syck;
15
16 sub execute {
17     my $self = shift;
18     my ( $controller, $c, $test ) = @_;
19
20     my $stash_key = $controller->serialize->{'stash_key'} || 'rest';
21   
22     if (! $c->response->content_type ) {
23         $c->response->content_type($c->req->content_type);
24     }
25     return 1 if $c->req->method eq 'HEAD';
26     return 1 if length( $c->response->body );
27     return 1 if scalar @{ $c->error };
28     return 1 if $c->response->status =~ /^(?:204|3\d\d)$/;
29
30     $c->response->output( Dump( $c->stash->{$stash_key} ) );
31     return 1;
32 };
33
34 1;