better warnings when code is stupid and calls ->params(undef)
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request.pm
index 15f7b7b..39cc3a4 100644 (file)
@@ -17,7 +17,7 @@ use namespace::clean -except => 'meta';
 
 with 'MooseX::Emulate::Class::Accessor::Fast';
 
-has env => (is => 'ro', writer => '_set_env', predicate => 'has_env');
+has env => (is => 'ro', writer => '_set_env', predicate => '_has_env');
 # XXX Deprecated crap here - warn?
 has action => (is => 'rw');
 # XXX: Deprecated in docs ages ago (2006), deprecated with warning in 5.8000 due
@@ -96,7 +96,7 @@ has _log => (
 
 has io_fh => (
     is=>'ro',
-    predicate=>'has_io_fh',
+    predicate=>'_has_io_fh',
     lazy=>1,
     builder=>'_build_io_fh');
 
@@ -243,7 +243,7 @@ sub prepare_body {
     # If previously applied middleware created the HTTP::Body object, then we
     # just use that one.  
 
-    if(my $plack_body = $self->env->{'plack.request.http.body'}) {
+    if(my $plack_body = $self->_has_env ? $self->env->{'plack.request.http.body'} : undef) {
         $self->_body($plack_body);
         $self->_body->cleanup(1);
         return;
@@ -439,6 +439,7 @@ Catalyst::Request - provides information about the current client request
     $req->uri;
     $req->user;
     $req->user_agent;
+    $req->env;
 
 See also L<Catalyst>, L<Catalyst::Request::Upload>.
 
@@ -644,9 +645,15 @@ sub param {
         return keys %{ $self->parameters };
     }
 
-    if ( @_ == 1 ) {
+    # If anything in @_ is undef, carp about that, and remove it from
+    # the list;
+    
+    my @params = grep { defined($_) ? 1 : do {carp "You called ->params with an undefined value"; 0} } @_;
+
+    if ( @params == 1 ) {
 
-        my $param = shift;
+        defined(my $param = shift @params) ||
+          carp "You called ->params with an undefined value 2";
 
         unless ( exists $self->parameters->{$param} ) {
             return wantarray ? () : undef;
@@ -663,8 +670,8 @@ sub param {
               : $self->parameters->{$param};
         }
     }
-    elsif ( @_ > 1 ) {
-        my $field = shift;
+    elsif ( @params > 1 ) {
+        my $field = shift @params;
         $self->parameters->{$field} = [@_];
     }
 }
@@ -989,6 +996,9 @@ combined from those in the request and those in the body.
 
 If parameters have already been set will clear the parameters and build them again.
 
+=head2 $self->env
+
+Access to the raw PSGI env.  
 
 =head2 meta