prevent $request->path used as setter from keeping stale data
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request.pm
index 7624db7..074e350 100644 (file)
@@ -144,8 +144,11 @@ C<application/x-www-form-urlencoded> or C<multipart/form-data>.
 =cut
 
 sub body {
-    my ( $self, $body ) = @_;
+    my $self = shift;
     $self->{_context}->prepare_body;
+    
+    return unless $self->{_body};
+    
     return $self->{_body}->body;
 }
 
@@ -362,22 +365,24 @@ Alias for path, added for compability with L<CGI>.
 =cut
 
 sub path {
-    my ( $self, $params ) = @_;
+    my ( $self, @params ) = @_;
 
-    if ($params) {
-        $self->uri->path($params);
+    if (@params) {
+        $self->uri->path(@params);
+        undef $self->{path};
     }
-    else {
-        return $self->{path} if $self->{path};
+    elsif ( defined( my $path = $self->{path} ) ) {
+        return $path;
     }
+    else {
+        my $path     = $self->uri->path;
+        my $location = $self->base->path;
+        $path =~ s/^(\Q$location\E)?//;
+        $path =~ s/^\///;
+        $self->{path} = $path;
 
-    my $path     = $self->uri->path;
-    my $location = $self->base->path;
-    $path =~ s/^(\Q$location\E)?//;
-    $path =~ s/^\///;
-    $self->{path} = $path;
-
-    return $path;
+        return $path;
+    }
 }
 
 =head2 $req->protocol
@@ -484,7 +489,8 @@ sub upload {
 =head2 $req->uploads
 
 Returns a reference to a hash containing uploads. Values can be either a
-hashref or a arrayref containing L<Catalyst::Request::Upload> objects.
+L<Catalyst::Request::Upload> object, or an arrayref of 
+L<Catalyst::Request::Upload> objects.
 
     my $upload = $c->request->uploads->{field};
     my $upload = $c->request->uploads->{field}->[0];