X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FEngine%2FCGI.pm;h=fa329020466e591f4abf40b76f2c916e384d72e4;hp=5a090642f223599b87c007df4e702a37303674bc;hb=536bee890cf24e0e4bcda7562e7b70cc03ca0620;hpb=0fc2d522eec43202c21e9f0062e43f10db4d9008 diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index 5a09064..fa32902 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -1,12 +1,9 @@ package Catalyst::Engine::CGI; -use Class::C3; use Moose; extends 'Catalyst::Engine'; -has env => (is => 'rw'); - -no Moose; +has _header_buf => (is => 'rw', clearer => '_clear_header_buf', predicate => '_has_header_buf'); =head1 NAME @@ -44,8 +41,7 @@ sub finalize_headers { $c->response->header( Status => $c->response->status ); - $self->{_header_buf} - = $c->response->headers->as_string("\015\012") . "\015\012"; + $self->_header_buf($c->response->headers->as_string("\015\012") . "\015\012"); } =head2 $self->prepare_connection($c) @@ -73,9 +69,10 @@ sub prepare_connection { $request->address($ip); } - $request->hostname( $ENV{REMOTE_HOST} ); + $request->hostname( $ENV{REMOTE_HOST} ) if exists $ENV{REMOTE_HOST}; $request->protocol( $ENV{SERVER_PROTOCOL} ); - $request->user( $ENV{REMOTE_USER} ); + $request->user( $ENV{REMOTE_USER} ); # XXX: Deprecated. See Catalyst::Request for removal information + $request->remote_user( $ENV{REMOTE_USER} ); $request->method( $ENV{REQUEST_METHOD} ); if ( $ENV{HTTPS} && uc( $ENV{HTTPS} ) eq 'ON' ) { @@ -175,14 +172,15 @@ sub prepare_path { =cut -sub prepare_query_parameters { +around prepare_query_parameters => sub { + my $orig = shift; my ( $self, $c ) = @_; local (*ENV) = $self->env || \%ENV; if ( $ENV{QUERY_STRING} ) { - $self->next::method( $c, $ENV{QUERY_STRING} ); + $self->$orig( $c, $ENV{QUERY_STRING} ); } -} +}; =head2 $self->prepare_request($c, (env => \%env)) @@ -202,10 +200,10 @@ Enable autoflush on the output handle for CGI-based engines. =cut -sub prepare_write { +around prepare_write => sub { *STDOUT->autoflush(1); - return shift->next::method(@_); -} + return shift->(@_); +}; =head2 $self->write($c, $buffer) @@ -213,16 +211,17 @@ Writes the buffer to the client. =cut -sub write { +around write => sub { + my $orig = shift; my ( $self, $c, $buffer ) = @_; # Prepend the headers if they have not yet been sent - if ( my $headers = delete $self->{_header_buf} ) { - $buffer = $headers . $buffer; + if ( $self->_has_header_buf ) { + $buffer = $self->_clear_header_buf . $buffer; } - return $self->next::method( $c, $buffer ); -} + return $self->$orig( $c, $buffer ); +}; =head2 $self->read_chunk($c, $buffer, $length) @@ -234,25 +233,22 @@ sub read_chunk { shift; shift; *STDIN->sysread(@_); } =cut -sub run { shift; shift->handle_request(@_) } +sub run { shift; shift->handle_request( env => \%ENV ) } =head1 SEE ALSO -L L. +L, L =head1 AUTHORS -Sebastian Riedel, - -Christian Hansen, - -Andy Grundman, +Catalyst Contributors, see Catalyst.pm =head1 COPYRIGHT -This program is free software, you can redistribute it and/or modify it under +This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =cut +no Moose; 1;