From: Sebastian Riedel Date: Sat, 23 Apr 2005 17:04:10 +0000 (+0000) Subject: Reverted chansens changes X-Git-Tag: 5.7099_04~1444 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=d7945f329f0e167dbcdd31b1830615f48b1db3b8 Reverted chansens changes --- diff --git a/lib/Catalyst/Engine.pm b/lib/Catalyst/Engine.pm index cbc5896..1a2d3ee 100644 --- a/lib/Catalyst/Engine.pm +++ b/lib/Catalyst/Engine.pm @@ -179,12 +179,13 @@ sub finalize { $c->finalize_error; } - if ( !$c->response->body_length && $c->response->status !~ /^(1|3)\d\d$/ ) { + if ( !$c->response->body && $c->response->status !~ /^(1|3)\d\d$/ ) { $c->finalize_error; } - if ( $c->response->body_length && !$c->response->content_length ) { - $c->response->content_length( $c->response->body_length ); + if ( $c->response->body && !$c->response->content_length ) { + use bytes; # play safe with a utf8 aware perl + $c->response->content_length( length $c->response->body ); } my $status = $c->finalize_headers; @@ -400,7 +401,6 @@ sub prepare { request => Catalyst::Request->new( { arguments => [], - body => undef, cookies => {}, headers => HTTP::Headers->new, parameters => {}, @@ -409,12 +409,7 @@ sub prepare { } ), response => Catalyst::Response->new( - { - body => undef, - cookies => {}, - headers => HTTP::Headers->new, - status => 200 - } + { cookies => {}, headers => HTTP::Headers->new, status => 200 } ), stash => {}, state => 0 @@ -430,10 +425,10 @@ sub prepare { } $c->prepare_request($engine); - $c->prepare_connection; + $c->prepare_path; $c->prepare_headers; $c->prepare_cookies; - $c->prepare_path; + $c->prepare_connection; $c->prepare_action; my $method = $c->req->method || ''; diff --git a/lib/Catalyst/Engine/Test.pm b/lib/Catalyst/Engine/Test.pm index f7afec3..779a636 100644 --- a/lib/Catalyst/Engine/Test.pm +++ b/lib/Catalyst/Engine/Test.pm @@ -55,7 +55,7 @@ This class overloads some methods from C. sub finalize_body { my $c = shift; - $c->http->response->content_ref( $c->response->body_ref ); + $c->http->response->content( $c->response->body ); } =item $c->finalize_headers @@ -151,8 +151,8 @@ sub prepare_parameters { } } - $c->request->param(\@params); - $c->request->upload(\@uploads); + $c->req->_assign_values( $c->req->parameters, \@params ); + $c->req->_assign_values( $c->req->uploads, \@uploads ); } =item $c->prepare_path diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index 09741ab..d6fb488 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -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 or C. 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 objects. my $upload = $c->request->uploads->{field}; diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index a433f02..2d83a48 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -20,8 +20,6 @@ Catalyst::Response - Catalyst Response Class $resp = $c->response; $resp->body; - $resp->body_length; - $resp->body_ref; $resp->content_encoding; $resp->content_length; $resp->content_type; @@ -49,34 +47,6 @@ to response data. Contains the final output. -=item $resp->body_length - -Returns the length of body in bytes. - - print $c->response->body_length - -=cut - -sub body_length { - my $self = shift; - - use bytes; - - return 0 unless $self->body; - return length($self->body); -} - -=item $resp->body_ref - -Returns a reference to body. - -=cut - -sub body_ref { - my $self = shift; - return \$self->{body}; -} - =item $resp->content_encoding Shortcut to $resp->headers->content_encoding