Merge the branch which gives ->req->remote_user without the deprecation code which...
Tomas Doran [Thu, 21 May 2009 13:44:58 +0000 (13:44 +0000)]
Changes
lib/Catalyst.pm
lib/Catalyst/Engine/CGI.pm
lib/Catalyst/Request.pm
t/aggregate/live_engine_request_remote_user.t [new file with mode: 0644]
t/lib/DeprecatedTestApp/C/Root.pm

diff --git a/Changes b/Changes
index a917b78..c2ab3a2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Add $c->req->remote_user to disambiguate from $c->req->user (dwc)
+
 5.80004 2009-05-18 17:03:23
         - Rename the actions attribute in Catalyt::Controller to
           _controller_actions to avoid name clashes with application
index 8a8c9e8..310553b 100644 (file)
@@ -2712,6 +2712,8 @@ dkubb: Dan Kubb <dan.kubb-cpan@onautopilot.com>
 
 Drew Taylor
 
+dwc: Daniel Westermann-Clark <danieltwc@cpan.org>
+
 esskar: Sascha Kiefer
 
 fireartist: Carl Franks <cfranks@cpan.org>
index fa2e23e..17a6e6c 100644 (file)
@@ -72,7 +72,8 @@ sub prepare_connection {
 
     $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' ) {
index a488acd..87b2012 100644 (file)
@@ -26,7 +26,7 @@ has query_parameters  => (is => 'rw', default => sub { {} });
 has secure => (is => 'rw', default => 0);
 has captures => (is => 'rw', default => sub { [] });
 has uri => (is => 'rw', predicate => 'has_uri');
-has user => (is => 'rw');
+has remote_user => (is => 'rw');
 has headers => (
   is      => 'rw',
   isa     => 'HTTP::Headers',
@@ -126,6 +126,10 @@ has hostname => (
 
 has _path => ( is => 'rw', predicate => '_has_path', clearer => '_clear_path' );
 
+# XXX: Deprecated in docs ages ago (2006), deprecated with warning in 5.8000 due
+# to confusion between Engines and Plugin::Authentication. Remove in 5.8100?
+has user => (is => 'rw');
+
 sub args            { shift->arguments(@_) }
 sub body_params     { shift->body_parameters(@_) }
 sub input           { shift->body(@_) }
@@ -587,8 +591,12 @@ sub uri_with {
 
 =head2 $req->user
 
-Returns the currently logged in user. Deprecated. The method recommended for
-newer plugins is $c->user.
+Returns the currently logged in user. B<Highly deprecated>, do not call,
+this will be removed in version 5.81.
+
+=head2 $req->remote_user
+
+Returns the value of the C<REMOTE_USER> environment variable.
 
 =head2 $req->user_agent
 
diff --git a/t/aggregate/live_engine_request_remote_user.t b/t/aggregate/live_engine_request_remote_user.t
new file mode 100644 (file)
index 0000000..10b071b
--- /dev/null
@@ -0,0 +1,42 @@
+#!perl
+
+# This tests to make sure the REMOTE_USER environment variable is properly passed through by the engine.
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use Test::More tests => 7;
+use Catalyst::Test 'TestApp';
+
+use Catalyst::Request;
+use HTTP::Request::Common;
+
+{
+    my $creq;
+
+    local $ENV{REMOTE_USER} = 'dwc';
+    my $request = GET(
+        'http://localhost/dump/request',
+    );
+
+    ok( my $response = request($request), 'Request' );
+    ok( $response->is_success, 'Response Successful 2xx' );
+    is( $response->content_type, 'text/plain', 'Response Content-Type' );
+    like( $response->content, qr/'Catalyst::Request'/,
+        'Content is a serialized Catalyst::Request' );
+
+    {
+        no strict 'refs';
+        ok(
+            eval '$creq = ' . $response->content,
+            'Unserialize Catalyst::Request'
+        );
+    }
+
+    isa_ok( $creq, 'Catalyst::Request' );
+    
+    is( $creq->remote_user, 'dwc', '$c->req->remote_user ok' );
+}
index 7b8b74f..9a3e1d0 100644 (file)
@@ -10,4 +10,9 @@ sub index : Private {
     $c->res->body('root index');
 }
 
+sub req_user : Local {
+    my ( $self, $c ) = @_;
+    $c->res->body('REMOTE_USER = ' . $c->req->user);
+}
+
 1;