[Jifty-commit] r3544 - jifty/trunk/lib/Jifty
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Jun 21 11:03:23 EDT 2007
Author: ruz
Date: Thu Jun 21 11:03:23 2007
New Revision: 3544
Modified:
jifty/trunk/lib/Jifty/CurrentUser.pm
Log:
* protect ourself from circular references between User and CurrentUser
we do it in user_object, so solution is generic should work in any case, but
only if people use the method to set user_object and user model uses _current_user
key to store reference to the CurrentUser
Modified: jifty/trunk/lib/Jifty/CurrentUser.pm
==============================================================================
--- jifty/trunk/lib/Jifty/CurrentUser.pm (original)
+++ jifty/trunk/lib/Jifty/CurrentUser.pm Thu Jun 21 11:03:23 2007
@@ -4,8 +4,9 @@
package Jifty::CurrentUser;
use base qw/Jifty::Object Class::Accessor::Fast/;
+use Scalar::Util qw();
-__PACKAGE__->mk_accessors(qw(is_superuser is_bootstrap_user user_object));
+__PACKAGE__->mk_accessors(qw(is_superuser is_bootstrap_user));
=head1 NAME
@@ -98,6 +99,19 @@
=cut
+sub user_object {
+ my $self = shift;
+ return $self->{'user_object'} unless @_;
+
+ $self->{'user_object'} = shift;
+ # protect ourself from circular refereces
+ if ( $self->{'user_object'}{'_current_user'} == $self ) {
+ Scalar::Util::weaken( $self->{'user_object'}{'_current_user'} )
+ unless Scalar::Util::isweak( $self->{'user_object'}{'_current_user'} );
+ }
+ return $self->{'user_object'};
+}
+
=head2 id
Returns C<0> if we don't have a L<user_object>. When we I<do> have a
More information about the Jifty-commit
mailing list