Lazy resolution of hostname
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / CGI.pm
index 5a09064..2c2fc87 100644 (file)
@@ -1,13 +1,10 @@
 package Catalyst::Engine::CGI;
 
-use Class::C3;
 use Moose;
 extends 'Catalyst::Engine';
 
 has env => (is => 'rw');
 
-no Moose;
-
 =head1 NAME
 
 Catalyst::Engine::CGI - The CGI Engine
@@ -73,7 +70,7 @@ 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->method( $ENV{REQUEST_METHOD} );
@@ -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,7 +211,8 @@ 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
@@ -221,8 +220,8 @@ sub write {
         $buffer = $headers . $buffer;
     }
 
-    return $self->next::method( $c, $buffer );
-}
+    return $self->$orig( $c, $buffer );
+};
 
 =head2 $self->read_chunk($c, $buffer, $length)
 
@@ -238,15 +237,11 @@ sub run { shift; shift->handle_request(@_) }
 
 =head1 SEE ALSO
 
-L<Catalyst> L<Catalyst::Engine>.
+L<Catalyst>, L<Catalyst::Engine>
 
 =head1 AUTHORS
 
-Sebastian Riedel, <sri@cpan.org>
-
-Christian Hansen, <ch@ngmedia.com>
-
-Andy Grundman, <andy@hybridized.org>
+Catalyst Contributors, see Catalyst.pm
 
 =head1 COPYRIGHT
 
@@ -254,5 +249,6 @@ This program is free software, you can redistribute it and/or modify it under
 the same terms as Perl itself.
 
 =cut
+no Moose;
 
 1;