Home: Perl Programming Help: Intermediate:
Can't locate method "push_write"



tobi
New User

Jan 2, 2013, 5:31 AM


Views: 3994
Can't locate method "push_write"

Hi there!

I'm trying to send a message via XMPP, but I only get the error:

Code
Can't locate object method "push_write" via package "AnyEvent::Util::guard" at /usr/local/share/perl/5.14.2/AnyEvent/XMPP/SimpleConnection.pm line 113.

All needed modules are installed and I don't know what's wrong here.

This is the script:

Code
#!/usr/bin/perl 
use utf8;
use AnyEvent;
use AnyEvent::XMPP::IM::Connection;
use AnyEvent::XMPP::IM::Presence;
use AnyEvent::XMPP::Util qw/split_jid/;

my $con =
AnyEvent::XMPP::Connection->new (
username => "root",
domain => "perlx.de",
hostname => "localhost",
password => "123458765",
resource => "Blubb"
);

$con->reg_cb (stream_ready => sub { print "bereit!\n" });
$con->connect;


AnyEvent::XMPP::IM::Message->new (
body => "test",
to => "tk@perlx.de"
)->send ($con);


I am grateful for any help.
Regards,
Tobi


FishMonger
Veteran / Moderator

Jan 2, 2013, 6:44 AM


Views: 3990
Re: [tobi] Can't locate method "push_write"

Are you sure all needed modules are installed and were installed without errors?

The "push_write" method is defined in the AnyEvent::Handle module. I have not looked at each of the modules you are loading to see which one, if any, load that module, but start by adding it to your list of use statements.

You should also add the warnings and strict pragmas, which should be in every script you write.


tobi
New User

Jan 2, 2013, 11:10 PM


Views: 3970
Re: [FishMonger] Can't locate method "push_write"

Thank's for your reply FishMonger!

Modues where all installed with "make test -- OK" and "make install -- OK".

Actualy it didn't run because I'm too soopid:
I invoked send() after reg_cb() was finished.
Instead, this works for me:

Code
 $con->reg_cb ( 
...
AnyEvent::XMPP::IM::Message->new (
...
)->send ($con);
);

Best regards
Tobi