added connection stuff
Sebastian Riedel [Sun, 20 Mar 2005 18:00:47 +0000 (18:00 +0000)]
Changes
MANIFEST
lib/Catalyst.pm
lib/Catalyst/Engine.pm
lib/Catalyst/Engine/Apache.pm
lib/Catalyst/Engine/CGI.pm
lib/Catalyst/Request.pm

diff --git a/Changes b/Changes
index 043c1ca..01bee69 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 This file documents the revision history for Perl extension Catalyst.
 
+4.30  XXX XXX XX XX:00:00 2005
+        - added connection informations (Christian Hansen)
+
 4.28  Sat Mar 19 22:00:00 2005
         - fixed isa tree (Christian Hansen)
         - added script/cgi-server.pl, so no more server restarting after
index 83a8914..e26067b 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -34,3 +34,4 @@ t/10redirect.t
 t/11stash.t
 t/12default.t
 t/13beginend.t
+t/14connection.t
index 98c8776..3182f94 100644 (file)
@@ -7,7 +7,7 @@ use Catalyst::Log;
 
 __PACKAGE__->mk_classdata($_) for qw/_config log/;
 
-our $VERSION = '4.28';
+our $VERSION = '4.30';
 our @ISA;
 
 =head1 NAME
index 7395270..38d8aef 100644 (file)
@@ -124,7 +124,6 @@ sub action {
     }
 }
 
-
 =item $c->benchmark($coderef)
 
 Takes a coderef with arguments and returns elapsed time as float.
@@ -491,9 +490,13 @@ sub prepare {
     $c->prepare_path;
     $c->prepare_cookies;
     $c->prepare_headers;
-    my $method = $c->req->method || '';
-    my $path   = $c->req->path   || '';
-    $c->log->debug(qq/"$method" request for "$path"/) if $c->debug;
+    $c->prepare_connection;
+    my $method   = $c->req->method   || '';
+    my $path     = $c->req->path     || '';
+    my $hostname = $c->req->hostname || '';
+    my $address  = $c->req->address  || '';
+    $c->log->debug(qq/"$method" request for "$path" from $hostname($address)/)
+      if $c->debug;
     $c->prepare_action;
     $c->prepare_parameters;
 
@@ -562,6 +565,14 @@ sub prepare_action {
       if ( $c->debug && @args );
 }
 
+=item $c->prepare_connection;
+
+Prepare connection.
+
+=cut
+
+sub prepare_connection { }
+
 =item $c->prepare_cookies;
 
 Prepare cookies.
index 55d8e89..aca61ad 100644 (file)
@@ -9,6 +9,7 @@ use URI;
 # mod_perl
 if (MP2) {
     require Apache2;
+    require Apache::Connection;
     require Apache::RequestIO;
     require Apache::RequestRec;
     require Apache::SubRequest;
@@ -96,6 +97,16 @@ sub finalize_output {
     $c->original_request->print( $c->response->{output} );
 }
 
+=item $c->prepare_connection
+
+=cut
+
+sub prepare_connection {
+    my $c = shift;
+    $c->req->hostname( $c->apache_request->connection->remote_host );
+    $c->req->address( $c->apache_request->connection->remote_ip );
+}
+
 =item $c->prepare_cookies
 
 =cut
index 1efa954..e944526 100644 (file)
@@ -106,6 +106,16 @@ sub finalize_output {
     print $c->response->output;
 }
 
+=item $c->prepare_connection
+
+=cut
+
+sub prepare_connection {
+    my $c = shift;
+    $c->req->hostname( $c->cgi->remote_host );
+    $c->req->address( $c->cgi->remote_addr );
+}
+
 =item $c->prepare_cookies
 
 Sets up cookies.
index f6ad5a6..f06e27e 100644 (file)
@@ -4,8 +4,8 @@ use strict;
 use base 'Class::Accessor::Fast';
 
 __PACKAGE__->mk_accessors(
-    qw/action arguments base cookies headers match method parameters path
-      snippets uploads/
+    qw/action address arguments base cookies headers hostname match method
+      parameters path snippets uploads/
 );
 
 *args   = \&arguments;
@@ -31,6 +31,12 @@ Contains the action.
 
     print $c->request->action;
 
+=head3 address
+
+Contains the remote address.
+
+    print $c->request->address
+
 =head3 arguments (args)
 
 Returns an arrayref containing the arguments.
@@ -53,6 +59,12 @@ Returns a L<HTTP::Headers> object containing the headers.
 
     print $c->request->headers->header('X-Catalyst');
 
+=head3 hostname
+
+Contains the remote hostname.
+
+    print $c->request->hostname
+
 =head3 match
 
 Contains the match.