fix body_parameters is undef when no params
Gerda Shank [Thu, 24 May 2012 16:47:01 +0000 (12:47 -0400)]
Changes
lib/Catalyst/Request.pm
t/lib/TestApp/Controller/BodyParams.pm
t/live_catalyst_test.t

diff --git a/Changes b/Changes
index fdf77c6..ef21fb5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+ Bug fixes:
+  - Fix request body parameters is undef with no parameters
+
 5.90012 - 2012-05-16 09:59:00
 
  Distribution META.yml changes:
index 6610358..d2c1c7f 100644 (file)
@@ -220,7 +220,7 @@ sub prepare_body_parameters {
     my ( $self ) = @_;
 
     $self->prepare_body if ! $self->_has_body;
-    return unless $self->_body;
+    return {} unless $self->_body;
 
     return $self->_body->param;
 }
index 5732211..ea6bf3a 100644 (file)
@@ -10,4 +10,11 @@ sub default : Private {
     $c->res->status(200);
 }
 
+sub no_params : Local {
+    my ( $self, $c ) = @_;
+    my $params = $c->req->body_parameters;
+    $c->res->output(ref $params);
+    $c->res->status(200);
+}
+
 1;
index e7f8df9..8248527 100644 (file)
@@ -50,5 +50,10 @@ my $req = '/dump/request';
     is($response, 'that', 'body param overridden');
 }
 
+{
+       my $response = request( POST( '/bodyparams/no_params' ) )->content;
+    is($response, 'HASH', 'empty body param is hashref');
+}
+
 done_testing;