diff --git a/lib/WebGUI/Friends.pm b/lib/WebGUI/Friends.pm index a8fbdea9f..62aa487a9 100644 --- a/lib/WebGUI/Friends.pm +++ b/lib/WebGUI/Friends.pm @@ -16,6 +16,20 @@ package WebGUI::Friends; use strict; use Class::InsideOut qw(id register public readonly); + +use Moose; + +has 'session' => ( + is => 'ro', + required => 1, + weak_ref => 1, +); + +has 'user' => ( + is => 'ro', + required => 1, +); + use WebGUI::DateTime; use WebGUI::HTML; use WebGUI::Inbox; @@ -23,9 +37,6 @@ use WebGUI::International; use WebGUI::User; use WebGUI::Utility; -readonly session => my %session; -readonly user => my %user; - =head1 NAME WebGUI::Friends @@ -45,6 +56,20 @@ A user relationship management system. =cut +around BUILDARGS => sub { + my $orig = shift; + my $className = shift; + + ##Original arguments start here. + my $protoSession = $_[0]; + if (blessed $protoSession && $protoSession->isa('WebGUI::Session')) { + my $protoUser = defined $_[1] ? $_[1] : $protoSession->user; + return $className->$orig(session => $protoSession, user => $protoUser,); + } + return $className->$orig(@_); +}; + + #------------------------------------------------------------------- @@ -276,16 +301,6 @@ attached to the session. =cut -sub new { - my $class = shift; - my $session = shift; - my $user = shift || $session->user; - my $self = register($class); - $session{id $self} = $session; - $user{id $self} = $user; - return $self; -} - #------------------------------------------------------------------- =head2 rejectAddRequest ( inviteId[,sendNotification] )