Fix the return value of Catalyst::Request's body method + tests.
Tomas Doran [Sat, 27 Dec 2008 19:44:45 +0000 (19:44 +0000)]
Changes
lib/Catalyst/Request.pm
t/aggregate/live_engine_request_body.t
t/lib/TestApp/View/Dump.pm

diff --git a/Changes b/Changes
index 5cfa657..8030d08 100644 (file)
--- 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)
index 85c4941..f228099 100644 (file)
@@ -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',
index 40d7ab2..c6670da 100644 (file)
@@ -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' );
 }
index 7acfa6d..db7c2a0 100644 (file)
@@ -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;