Fix documentation for overriding Serialize and Deserialize actions
in Catalyst::Controller::REST.
+ Avoid warning with empty response bodies and new Catalyst version
+ (>= 5.80030)
+
+ Returning a body of '' is now possible - Catalyst::Action::Serialize
+ acts like Catalyst::Action::RenderView (>= 0.16) by using the has_body
+ predicate in Catalyst::Response (>= 5.80030)
+
Wed 3 Nov 2010 19:46:00 GMT - Release 0.87
Fix Request class role when used with new Moose and other request
requires 'Moose' => '1.03';
requires 'namespace::autoclean';
-requires('Catalyst::Runtime' => '5.80');
+requires('Catalyst::Runtime' => '5.80030');
requires('Params::Validate' => '0.76');
requires('YAML::Syck' => '0.67');
requires('Module::Pluggable::Object' => undef);
sensible set of defaults for a controller doing REST.
This class automatically adds the L<Catalyst::TraitFor::Request::REST> role to
-your request class. If you're writing a webapp which provides RESTful
+your request class. If you're writing a web application which provides RESTful
responses and still needs to accommodate web browsers, you may prefer to use
L<Catalyst::TraitFor::Request::REST::ForBrowsers> instead.
$self->maybe::next::method(@_);
return 1 if $c->req->method eq 'HEAD';
- return 1 if length( $c->response->body );
+ return 1 if $c->response->has_body;
return 1 if scalar @{ $c->error };
return 1 if $c->response->status =~ /^(?:204)$/;
use strict;
use warnings;
-use Test::More tests => 9;
+use Test::More 0.88;
use Data::Serializer;
use FindBin;
ok( $res2->is_success, 'request succeeded (deprecated config)' );
is( $res2->content, "{'lou' => 'is my cat'}", "request returned proper data");
-1;
+$res = request($t->get(url => '/serialize/empty_serialized'));
+is $res->content, q[{'foo' => 'bar'}], 'normal case ok';
+ok $res->header('Content-Length'), 'set content-length when we serialize';
+
+$res = request($t->get(url => '/serialize/empty_not_serialized_undef'));
+is $res->content, '', "body explicitly set to undef results in '' content";
+ok !$res->header('Content-Length'), "body explicitly set to undef - no automatic content-length";
+
+$res = request($t->get(url => '/serialize/empty_not_serialized_blank'));
+is $res->content, '', "body explicitly set to '' results in '' content";
+ok !$res->header('Content-Length'), "body explicitly set to '' - no automatic content-length";
+
+done_testing;
+
},
);
__PACKAGE__->setup;
-__PACKAGE__->log( Test::Catalyst::Log->new );
+__PACKAGE__->log( Test::Catalyst::Log->new )
+ unless __PACKAGE__->debug;
1;
};
}
+# For testing saying 'here is an explicitly empty body, do not serialize'
+sub empty : Chained('/') PathPart('serialize') CaptureArgs(0) {
+ my ($self, $c) = @_;
+ $c->stash( rest => { foo => 'bar' } );
+}
+
+# Normal case
+sub empty_serialized :Chained('empty') Args(0) ActionClass('Serialize') {
+}
+
+# Undef body
+sub empty_not_serialized_undef :Chained('empty') Args(0) ActionClass('Serialize') {
+ my ($self, $c) = @_;
+ $c->res->body(undef);
+}
+
+# Blank body
+sub empty_not_serialized_blank :Chained('empty') Args(0) ActionClass('Serialize') {
+ my ($self, $c) = @_;
+ $c->res->body('');
+}
+
1;