[Catalyst-commits] r9380 - in Catalyst-Runtime/5.80/branches/deprecate_req_user: . lib lib/Catalyst lib/Catalyst/Engine t/aggregate

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Sat Feb 21 01:30:01 GMT 2009


Author: t0m
Date: 2009-02-21 01:30:01 +0000 (Sat, 21 Feb 2009)
New Revision: 9380

Added:
   Catalyst-Runtime/5.80/branches/deprecate_req_user/t/aggregate/live_engine_request_remote_user.t
Modified:
   Catalyst-Runtime/5.80/branches/deprecate_req_user/Changes
   Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst.pm
   Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Engine/CGI.pm
   Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Request.pm
Log:
Add patch from dwc to warn about c->req->user deprecation

Modified: Catalyst-Runtime/5.80/branches/deprecate_req_user/Changes
===================================================================
--- Catalyst-Runtime/5.80/branches/deprecate_req_user/Changes	2009-02-21 01:27:02 UTC (rev 9379)
+++ Catalyst-Runtime/5.80/branches/deprecate_req_user/Changes	2009-02-21 01:30:01 UTC (rev 9380)
@@ -28,6 +28,7 @@
         - namespace::clean related cleanups (rafl)
         - Import related cleanups and consistency fixes (rafl)
         - Fix test suite TestApp /dump/env action (t0m)
+        - Add $c->req->remote_user to disambiguate from $c->req->user (dwc)
 
 5.8000_06 2009-02-04 21:00
         - Disallow writing to config after setup (rafl)

Modified: Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Engine/CGI.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Engine/CGI.pm	2009-02-21 01:27:02 UTC (rev 9379)
+++ Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Engine/CGI.pm	2009-02-21 01:30:01 UTC (rev 9380)
@@ -72,7 +72,8 @@
 
     $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' ) {

Modified: Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Request.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Request.pm	2009-02-21 01:27:02 UTC (rev 9379)
+++ Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Request.pm	2009-02-21 01:30:01 UTC (rev 9380)
@@ -26,7 +26,7 @@
 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',
@@ -121,6 +121,20 @@
 
 has _path => ( is => 'rw', predicate => '_has_path', clearer => '_clear_path' );
 
+# XXX: Deprecated in 5.8000 due to confusion between Engines and Plugin::Authentication. Remove in 5.x000?
+has user => (is => 'rw');
+
+before user => sub {
+  my ($self, $user) = @_;
+  # Allow Engines and Plugin::Authentication to set without warning
+  my $caller = (caller(2))[0];
+  if ( $caller !~ /^Catalyst::(Engine|Plugin::Authentication)/ ) {
+    $self->_context->log->warn(
+      'Attempt to use $c->req->user; this is deprecated. ' .
+      'You probably meant to call $c->user or $c->req->remote_user' );
+  }
+};
+
 sub args            { shift->arguments(@_) }
 sub body_params     { shift->body_parameters(@_) }
 sub input           { shift->body(@_) }
@@ -577,6 +591,11 @@
 Returns the currently logged in user. Deprecated. The method recommended for
 newer plugins is $c->user.
 
+=head2 $req->remote_user
+
+Returns the value of the C<REMOTE_USER> environment variable. Previously
+available via $req->user.
+
 =head2 $req->user_agent
 
 Shortcut to $req->headers->user_agent. Returns the user agent (browser)

Modified: Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst.pm	2009-02-21 01:27:02 UTC (rev 9379)
+++ Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst.pm	2009-02-21 01:30:01 UTC (rev 9380)
@@ -2595,6 +2595,8 @@
 
 Drew Taylor
 
+dwc: Daniel Westermann-Clark <danieltwc at cpan.org>
+
 esskar: Sascha Kiefer
 
 fireartist: Carl Franks <cfranks at cpan.org>

Added: Catalyst-Runtime/5.80/branches/deprecate_req_user/t/aggregate/live_engine_request_remote_user.t
===================================================================
--- Catalyst-Runtime/5.80/branches/deprecate_req_user/t/aggregate/live_engine_request_remote_user.t	                        (rev 0)
+++ Catalyst-Runtime/5.80/branches/deprecate_req_user/t/aggregate/live_engine_request_remote_user.t	2009-02-21 01:30:01 UTC (rev 9380)
@@ -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' );
+}




More information about the Catalyst-commits mailing list