Reverted chansens changes
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request.pm
index 09741ab..d6fb488 100644 (file)
@@ -19,6 +19,23 @@ sub header           { shift->headers->header(@_)           }
 sub referer          { shift->headers->referer(@_)          }
 sub user_agent       { shift->headers->user_agent(@_)       }
 
+sub _assign_values {
+    my ( $self, $map, $values ) = @_;
+
+    while ( my ( $name, $value ) = splice( @{$values}, 0, 2 ) ) {
+
+        if ( exists $map->{$name} ) {
+            for ( $map->{$name} ) {
+                $_ = [$_] unless ref($_) eq "ARRAY";
+                push( @$_, $value );
+            }
+        }
+        else {
+            $map->{$name} = $value;
+        }
+    }
+}
+
 =head1 NAME
 
 Catalyst::Request - Catalyst Request Class
@@ -33,8 +50,6 @@ Catalyst::Request - Catalyst Request Class
     $req->arguments;
     $req->base;
     $req->body;
-    $req->body_length;
-    $req->body_ref;
     $req->content_encoding;
     $req->content_length;
     $req->content_type;
@@ -101,34 +116,6 @@ C<application/x-www-form-urlencoded> or C<multipart/form-data>.
 
     print $c->request->body
 
-=item $req->body_length
-
-Returns the length of body in bytes.
-
-    print $c->request->body_length
-
-=cut
-
-sub body_length {
-    my $self = shift;
-    
-    use bytes;
-    
-    return 0 unless $self->body;
-    return length($self->body);
-}
-
-=item $req->body_ref
-
-Returns a reference to body.
-
-=cut
-
-sub body_ref {
-    my $self = shift;    
-    return \$self->{body};
-}
-
 =item $req->content_encoding
 
 Shortcut to $req->headers->content_encoding
@@ -197,41 +184,22 @@ sub param {
         return keys %{ $self->parameters };
     }
 
-    if ( @_ == 1 and ref( $_[0] ) eq 'ARRAY' ) {
-
-        while ( my ( $field, $value ) = splice( @{ $_[0] }, 0, 2 ) ) {
+    my $param = shift;
 
-            if ( exists $self->parameters->{$field} ) {
-                for ( $self->parameters->{$field} ) {
-                    $_ = [$_] unless ref($_) eq "ARRAY";
-                    push( @$_, $value );
-                }
-            }
-            else {
-                $self->parameters->{$field} = $value;
-            }
-        }
+    unless ( exists $self->parameters->{$param} ) {
+        return wantarray ? () : undef;
     }
-    
-    if ( @_ == 1 ) {
-
-        my $param = shift;
-
-        unless ( exists $self->parameters->{$param} ) {
-            return wantarray ? () : undef;
-        }
 
-        if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
-            return (wantarray)
-              ? @{ $self->parameters->{$param} }
-              : $self->parameters->{$param}->[0];
-        }
-        else {
-            return (wantarray)
-              ? ( $self->parameters->{$param} )
-              : $self->parameters->{$param};
-        }
-    }    
+    if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
+        return (wantarray)
+          ? @{ $self->parameters->{$param} }
+          : $self->parameters->{$param}->[0];
+    }
+    else {
+        return (wantarray)
+          ? ( $self->parameters->{$param} )
+          : $self->parameters->{$param};
+    }
 }
 
 =item $req->params
@@ -269,7 +237,7 @@ A convenient method to $req->uploads.
     $upload  = $c->request->upload('field');
     @uploads = $c->request->upload('field');
     @fields  = $c->request->upload;
-
+    
     for my $upload ( $c->request->upload('field') ) {
         print $upload->filename;
     }
@@ -283,46 +251,27 @@ sub upload {
         return keys %{ $self->uploads };
     }
 
-    if ( @_ == 1 and ref( $_[0] ) eq 'ARRAY' ) {
-
-        while ( my ( $field, $upload ) = splice( @{ $_[0] }, 0, 2 ) ) {
+    my $upload = shift;
 
-            if ( exists $self->uploads->{$field} ) {
-                for ( $self->uploads->{$field} ) {
-                    $_ = [$_] unless ref($_) eq "ARRAY";
-                    push( @$_, $upload );
-                }
-            }
-            else {
-                $self->uploads->{$field} = $upload;
-            }
-        }
+    unless ( exists $self->uploads->{$upload} ) {
+        return wantarray ? () : undef;
     }
 
-    if ( @_ == 1 ) {
-
-        my $upload = shift;
-
-        unless ( exists $self->uploads->{$upload} ) {
-            return wantarray ? () : undef;
-        }
-
-        if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
-            return (wantarray)
-              ? @{ $self->uploads->{$upload} }
-              : $self->uploads->{$upload}->[0];
-        }
-        else {
-            return (wantarray)
-               ? ( $self->uploads->{$upload} )
-               : $self->uploads->{$upload};
-        }
+    if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
+        return (wantarray)
+          ? @{ $self->uploads->{$upload} }
+          : $self->uploads->{$upload}->[0];
+    }
+    else {
+        return (wantarray)
+          ? ( $self->uploads->{$upload} )
+          : $self->uploads->{$upload};
     }
 }
 
 =item $req->uploads
 
-Returns a reference to a hash containing uploads. Values can be either a
+Returns a reference to a hash containing uploads. Values can be either a 
 hashref or a arrayref containing C<Catalyst::Request::Upload> objects.
 
     my $upload = $c->request->uploads->{field};