Index: perl/modules/jabber.pl
===================================================================
--- perl/modules/jabber.pl	(revision 8f2ce3a2d784853e0969b8ebddb70dda860bdae3)
+++ perl/modules/jabber.pl	(revision bed4ff12c029686af968dfc32923b7be76fd7a38)
@@ -39,12 +39,14 @@
     my $jidStr = shift;
 
-    $self->{Client}->{$jidStr} = 
-      Net::Jabber::Client->new(
-          debuglevel => owl::getvar('debug') eq 'on' ? 1 : 0,
-          debugfile => 'jabber.log'
-      );
-    my $refConn = \$self->{Client}->{$jidStr};
-    $self->{Roster}->{$jidStr} = $$refConn->Roster();
-    return $refConn;
+    my $client = Net::Jabber::Client->new(
+        owl::getvar('debug') eq 'on'
+          ? (debuglevel =>  ? 1 : 0,
+             debugfile => 'jabber.log')
+          : ()
+         );
+
+    $self->{Client}->{$jidStr} = $client;
+    $self->{Roster}->{$jidStr} = $client->Roster();
+    return $client;
 }
 
@@ -52,14 +54,11 @@
     my $self = shift;
     my $jidStr = shift;
-    my $ret = 0;
-    foreach my $j ( keys %{ $self->{Client} } ) {
-        if ($j eq $jidStr) {
-            $self->{Client}->{$j}->Disconnect();
-            delete $self->{Roster}->{$j};
-            delete $self->{Client}->{$j};
-            $ret = 1;
-        }
-    }
-    return $ret;
+    return 0 unless exists $self->{Client}->{$jidStr};
+    
+    $self->{Client}->{$jidStr}->Disconnect();
+    delete $self->{Roster}->{$jidStr};
+    delete $self->{Client}->{$jidStr};
+    
+    return 1;
 }
 
@@ -77,8 +76,5 @@
     my $self = shift;
     my $jidStr = shift;
-    foreach my $j ( keys %{ $self->{Client} } ) {
-        return 1 if ($j eq $jidStr);
-    }
-    return 0;
+    return exists $self->{Client}->{$jidStr};
 }
 
@@ -92,45 +88,33 @@
 }
 
-sub getConnRefFromSid {
+sub getConnectionFromSid {
     my $self = shift;
     my $sid = shift;
-    foreach my $j ( keys %{ $self->{Client} } ) {
-        if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
-            return \$self->{Client}->{$j};
-        }
+    foreach my $c (values %{ $self->{Client} }) {
+        return $c if $c->{SESSION}->{id} eq $sid;
     }
     return undef;
 }
 
-sub getConnRefFromJidStr {
+sub getConnectionFromJidStr {
     my $self = shift;
     my $jidStr = shift;
-    foreach my $j ( keys %{ $self->{Client} } ) {
-        if ($jidStr eq $j) {
-            return \$self->{Client}->{$j};
-        }
-    }
-    return undef;
-}
-
-sub getRosterRefFromSid {
+    return $self->{Client}->{$jidStr};
+}
+
+sub getRosterFromSid {
     my $self = shift;
     my $sid = shift;
-    foreach my $j ( keys %{ $self->{Client} } ) {
-        if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid) {
-            return \$self->{Roster}->{$j};
-        }
+    foreach my $j ( $self->getJids ) {
+        return $self->{Roster}->{$j}
+          if $self->{Client}->{$j}->{SESSION}->{id} eq $sid;
     }
     return undef;
 }
 
-sub getRosterRefFromJidStr {
+sub getRosterFromJidStr {
     my $self = shift;
     my $jidStr = shift;
-    foreach my $j ( keys %{ $self->{Client} } ) {
-        if ($jidStr eq $j) {
-            return \$self->{Roster}->{$j};
-        }
-    }
+    return $self->{Roster}->{$jidStr};
     return undef;
 }
@@ -161,5 +145,5 @@
 
     foreach my $jid ( $conn->getJids() ) {
-        my $client = $conn->getConnRefFromJidStr($jid);
+        my $client = $conn->getConnectionFromJidStr($jid);
 
         my $status = $client->Process(0);
@@ -209,6 +193,6 @@
     return "" unless $jid;
     my $blist = "";
-    my $roster = $conn->getRosterRefFromJidStr($jid);
-    if ($$roster) {
+    my $roster = $conn->getRosterFromJidStr($jid);
+    if ($roster) {
         $blist .= "\n" . boldify("Jabber Roster for $jid\n");
 
@@ -351,5 +335,5 @@
             normal    => sub { owl_jabber::process_incoming_normal_message(@_) }
         );
-        $$client->SetPresenceCallBacks(
+        $client->SetPresenceCallBacks(
 #            available    => sub { owl_jabber::process_presence_available(@_) },
 #            unavailable  => sub { owl_jabber::process_presence_available(@_) },
@@ -379,6 +363,6 @@
         }
             else {
-                ${ $conn->getRosterRefFromJidStr($jidStr) }->fetch();
-                $$client->PresenceSend( priority => 1 );
+                ${ $conn->getRosterFromJidStr($jidStr) }->fetch();
+                $client->PresenceSend( priority => 1 );
                 queue_admin_msg("Connected to jabber as $jidStr");
             }
@@ -570,5 +554,5 @@
     }
 
-    ${ $conn->getConnRefFromJidStr($jid) }->Send($presence);
+    $conn->getConnectionFromJidStr($jid)->Send($presence);
 }
 
@@ -579,6 +563,5 @@
     die("Usage: jmuc part {muc} [-a account]") unless $muc;
 
-    ${ $conn->getConnRefFromJidStr($jid) }
-      ->PresenceSend( to => $muc, type => 'unavailable' );
+    $conn->getConnectionFromJidStr($jid)->PresenceSend( to => $muc, type => 'unavailable' );
     queue_admin_msg("$jid has left $muc.");
 }
@@ -598,5 +581,5 @@
     $x->AddInvite();
     $x->GetInvite()->SetTo($invite_jid);
-    ${ $conn->getConnRefFromJidStr($jid) }->Send($message);
+    $conn->getConnectionFromJidStr($jid)->Send($message);
     queue_admin_msg("$jid has invited $invite_jid to $muc.");
 }
@@ -613,5 +596,5 @@
     $x->SetType('submit');
 
-    ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
+    $conn->getConnectionFromJidStr($jid)->Send($iq);
     queue_admin_msg("Accepted default instant configuration for $muc");
 }
@@ -677,5 +660,5 @@
     my $baseJid = baseJID($jid);
 
-    my $roster = $conn->getRosterRefFromJidStr($jid);
+    my $roster = $conn->getRosterFromJidStr($jid);
 
     # Adding lots of users with the same name is a bad idea.
@@ -686,8 +669,8 @@
 
     foreach my $to (@ARGV) {
-        jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($$roster->exists($to));
+        jroster_add($jid, $name, \@groups, $purgeGroups, ($to)) unless ($roster->exists($to));
 
         $p->SetTo($to);
-        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
+        $conn->getConnectionFromJidStr($jid)->Send($p);
         queue_admin_msg("You ($baseJid) have requested a subscription to ($to)'s presence.");
     }
@@ -705,5 +688,5 @@
     foreach my $to (@ARGV) {
         $p->SetTo($to);
-        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
+        $conn->getConnectionFromJidStr($jid)->Send($p);
         queue_admin_msg("You ($baseJid) have unsubscribed from ($to)'s presence.");
     }
@@ -717,5 +700,5 @@
     my $baseJid = baseJID($jid);
 
-    my $roster = $conn->getRosterRefFromJidStr($jid);
+    my $roster = $conn->getRosterFromJidStr($jid);
 
     # Adding lots of users with the same name is a bad idea.
@@ -723,5 +706,5 @@
 
     foreach my $to (@ARGV) {
-        my %jq  = $$roster->query($to);
+        my %jq  = $roster->query($to);
         my $iq = new Net::XMPP::IQ;
         $iq->SetType('set');
@@ -747,5 +730,5 @@
         $item->put_attrib(jid => $to);
         $item->put_attrib(name => $name) if $name;
-        ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
+        $conn->getConnectionFromJidStr($jid)->Send($iq);
         my $msg = "$baseJid: "
           . ($name ? "$name ($to)" : "($to)")
@@ -771,5 +754,5 @@
     foreach my $to (@ARGV) {
         $item->put_attrib(jid => $to);
-        ${ $conn->getConnRefFromJidStr($jid) }->Send($iq);
+        $conn->getConnectionFromJidStr($jid)->Send($iq);
         queue_admin_msg("You ($baseJid) have removed ($to) from your roster.");
     }
@@ -787,5 +770,5 @@
     foreach my $to (@ARGV) {
         $p->SetTo($to);
-        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
+        $conn->getConnectionFromJidStr($jid)->Send($p);
         queue_admin_msg("($to) has been subscribed to your ($baseJid) presence.");
     }
@@ -803,5 +786,5 @@
     foreach my $to (@ARGV) {
         $p->SetTo($to);
-        ${ $conn->getConnRefFromJidStr($jid) }->Send($p);
+        $conn->getConnectionFromJidStr($jid)->Send($p);
         queue_admin_msg("($to) has been unsubscribed from your ($baseJid) presence.");
     }
@@ -833,8 +816,8 @@
 
     if ($vars{jwrite}{sid} && $conn->sidExists( $vars{jwrite}{sid} )) {
-        ${ $conn->getConnRefFromSid($vars{jwrite}{sid}) }->Send($j);
+        $conn->getConnectionFromSid($vars{jwrite}{sid})->Send($j);
     }
     else {
-        ${ $conn->getConnRefFromJidStr($vars{jwrite}{from}) }->Send($j);
+        $conn->getConnectionFromJidStr($vars{jwrite}{from})->Send($j);
     }
 
@@ -968,5 +951,5 @@
             $to eq $cJid->GetJID('full')) {
 	    my $reply = $p->Reply(type=>"unsubscribed");
-	    ${ $conn->getConnRefFromJidStr($jid) }->Send($reply);
+	    $conn->getConnectionFromJidStr($jid)->Send($reply);
 	    return;
 	}
