From: Tomas Doran Date: Sat, 27 Dec 2008 19:44:45 +0000 (+0000) Subject: Fix the return value of Catalyst::Request's body method + tests. X-Git-Tag: 5.8000_05~67 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=610bc6eccd3d749c9e14422575c3b8787f48fcf1 Fix the return value of Catalyst::Request's body method + tests. --- diff --git a/Changes b/Changes index 5cfa657..8030d08 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,8 @@ # This file documents the revision history for Perl extension Catalyst. + - Fix return value of $c->req->body, which delegates to the body + method on the HTTP::Body of the request (t0m) + - Test for this (t0m) - Fix calling $c->req->body from inside an overridden prepare_action method in a plugin, as used by Catalyst::Plugin::Server (t0m) - Test for this (t0m) diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 85c4941..f228099 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -98,13 +98,15 @@ has base => ( has _body => ( is => 'rw', - accessor => 'body', ); - -before body => sub { - my ($self) = @_; +# Eugh, ugly. Should just be able to rename accessor methods to 'body' +# and provide a custom reader.. +sub body { + my $self = shift; $self->_context->prepare_body(); -}; + $self->_body(@_) if scalar @_; + return blessed $self->_body ? $self->_body->body : $self->_body; +} has hostname => ( is => 'rw', diff --git a/t/aggregate/live_engine_request_body.t b/t/aggregate/live_engine_request_body.t index 40d7ab2..c6670da 100644 --- a/t/aggregate/live_engine_request_body.t +++ b/t/aggregate/live_engine_request_body.t @@ -1,12 +1,11 @@ #!perl - use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; -use Test::More tests => 21; +use Test::More tests => 23; use Catalyst::Test 'TestApp'; use Catalyst::Request; @@ -39,6 +38,7 @@ use HTTP::Request::Common; isa_ok( $creq, 'Catalyst::Request' ); is( $creq->method, 'POST', 'Catalyst::Request method' ); is( $creq->content_type, 'text/plain', 'Catalyst::Request Content-Type' ); + is( $creq->{__body_type}, 'File::Temp' ); is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' ); } @@ -72,6 +72,7 @@ use HTTP::Request::Common; isa_ok( $creq, 'Catalyst::Request' ); is( $creq->method, 'POST', 'Catalyst::Request method' ); is( $creq->content_type, 'text/plain', 'Catalyst::Request Content-Type' ); + is( $creq->{__body_type}, 'File::Temp' ); is( $creq->content_length, $request->content_length, 'Catalyst::Request Content-Length' ); } diff --git a/t/lib/TestApp/View/Dump.pm b/t/lib/TestApp/View/Dump.pm index 7acfa6d..db7c2a0 100644 --- a/t/lib/TestApp/View/Dump.pm +++ b/t/lib/TestApp/View/Dump.pm @@ -4,7 +4,7 @@ use strict; use base 'Catalyst::View'; use Data::Dumper (); -use Scalar::Util qw(weaken); +use Scalar::Util qw(blessed weaken); sub dump { my ( $self, $reference ) = @_; @@ -28,12 +28,14 @@ sub process { # Force processing of on-demand data $c->prepare_body; - # Remove context from reference if needed - my $context = delete $reference->{_context}; - # Remove body from reference if needed + $reference->{__body_type} = blessed $reference->body + if (blessed $reference->{_body}); my $body = delete $reference->{_body}; + # Remove context from reference if needed + my $context = delete $reference->{_context}; + if ( my $output = $self->dump( $reference || $c->stash->{dump} || $c->stash ) ) { @@ -46,6 +48,7 @@ sub process { weaken( $reference->{_context} ); # Repair body + delete $reference->{__body_type}; $reference->{_body} = $body; return 1;