in reply to Net::Jabber: Receiving answers without callbacks

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re: Net::Jabber: Receiving answers without callbacks

Replies are listed 'Best First'.
Re^2: Net::Jabber: Receiving answers without callbacks
by enhering (Sexton) on Sep 09, 2006 at 20:06 UTC
    On the chatterbox somebody (sorry for forgetting
    who did help me) suggested me to use closures.
    I did it and it worked fine. The example
    code follows below. Thanks everyone for the
    inspiration!
    sub gpib_write { my ($self, $command) = @_; print "Sending ->$command<- to gpib ud=$self->{ud}.\n" if ($debug); my $message = "GPIB|write|$self->{ud}|$command"; # Send message to gpib server $self->{conn}->MessageSend(to=>'gpibserver@xxx.yyy.zzz', subject=>"", type=>"groupchat", body=>$message, thread=>"", priority=>10); print " Message sent: ->$message<-\n" if ($debug); # Acknowledge comes through callback my $answer; $self->{conn}->SetCallBacks( message=>sub{ my $sid = shift; my $message = shift; my $body = $message->GetBody(); print " Acknowledge received: ->$body<-\n" if +($debug); $answer = $body; } ); return $answer; }