| 1 |
#!/opt/perl/bin/perl |
| 2 |
use strict; |
| 3 |
use utf8; |
| 4 |
use Event; |
| 5 |
use AnyEvent; |
| 6 |
use Net::XMPP2::Client; |
| 7 |
|
| 8 |
my $j = AnyEvent->condvar; |
| 9 |
my $cl = Net::XMPP2::Client->new (debug => 1); |
| 10 |
$cl->add_account ('net_xmpp2@jabber.org', 'test'); |
| 11 |
$cl->reg_cb ( |
| 12 |
session_ready => sub { |
| 13 |
my ($cl, $acc) = @_; |
| 14 |
print "session ready\n"; |
| 15 |
$cl->send_message ( |
| 16 |
"Hi! I'm too stupid to adjust examples!" => 'elmex@jabber.org', undef, 'chat' |
| 17 |
); |
| 18 |
}, |
| 19 |
disconnect => sub { |
| 20 |
my ($cl, $acc, $h, $p, $reas) = @_; |
| 21 |
print "disconnect ($h:$p): $reas\n"; |
| 22 |
}, |
| 23 |
error => sub { |
| 24 |
my ($cl, $acc, $err) = @_; |
| 25 |
print "ERROR: " . $err->string . "\n"; |
| 26 |
}, |
| 27 |
message => sub { |
| 28 |
my ($cl, $acc, $msg) = @_; |
| 29 |
print "message from: " . $msg->from . ": " . $msg->any_body . "\n"; |
| 30 |
} |
| 31 |
); |
| 32 |
$cl->start; |
| 33 |
$j->wait; |