[Catalyst-commits] r9381 - Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst

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


Author: t0m
Date: 2009-02-21 01:31:05 +0000 (Sat, 21 Feb 2009)
New Revision: 9381

Modified:
   Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Request.pm
Log:
Change the way the warning is generated to warn once only on first _read_, so that the evil caller tricks aren't needed.

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:30:01 UTC (rev 9380)
+++ Catalyst-Runtime/5.80/branches/deprecate_req_user/lib/Catalyst/Request.pm	2009-02-21 01:31:05 UTC (rev 9381)
@@ -121,18 +121,21 @@
 
 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?
+# 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');
+has _user_deprecated_has_warned => ( is => 'rw', default => 0 );
+before user => sub {
+    my ($self, $user) = @_;
+    return if $user; # Allow Engines and Plugin::Authentication to set without warning
 
-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' );
-  }
+    if (! $self->_user_deprecated_has_warned) {
+        $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'
+        );
+        $self->_user_deprecated_has_warned(1);
+     }
 };
 
 sub args            { shift->arguments(@_) }
@@ -588,13 +591,12 @@
 
 =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. Previously
-available via $req->user.
+Returns the value of the C<REMOTE_USER> environment variable.
 
 =head2 $req->user_agent
 




More information about the Catalyst-commits mailing list