Debian Codegraph @

samples/test_client

raw
1 #!/opt/perl/bin/perl
2 use strict;
3 use utf8;
4 use AnyEvent;
5 use AnyEvent::XMPP qw/xep-86/;
6 use AnyEvent::XMPP::Client;
7 use Encode;
8
9 binmode STDOUT, ":utf8";
10
11 my $j = AnyEvent->condvar;
12 my $cl = AnyEvent::XMPP::Client->new (debug => 1);
13 $cl->set_presence ('away', 'I\'m a bot now.', 1);
14 $cl->add_account (@ARGV, undef, undef);
15 $cl->reg_cb (
16 connected => sub {
17 $cl->send_message ("Hello!" => '[email protected]');
18 0
19 },
20 roster_update => sub {
21 my ($cl, $acc, $roster, $contacts) = @_;
22 $roster->debug_dump;
23 #$acc->connection ()->send_presence ('probe' => undef, to => '[email protected]');
24 #print "OEOFWEFIEJWFEWO\n" if not $roster->is_retrieved;
25 1
26 },
27 presence_update => sub {
28 my ($cl, $acc, $roster, $contact, $old, $new) = @_;
29 $roster->debug_dump;
30 1
31 },
32 error => sub {
33 my ($cl, $acc, $error) = @_;
34 print "ERROR: ".$error->string."\n";
35 },
36 disconnect => sub { warn "DISCON[@_]\n"; 1 },
37 );
38
39 $cl->reg_cb (contact_request_subscribe => sub {
40 my ($cl, $acc, $roster, $contact) = @_;
41 $contact->send_subscribe;
42 0
43 });
44
45 $cl->reg_cb (contact_did_unsubscribe => sub {
46 my ($cl, $acc, $roster, $contact, $rdoit) = @_;
47 1
48 });
49
50 $cl->reg_cb (roster_update => sub {
51 my ($cl, $acc, $roster, $contacts) = @_;
52 $roster->debug_dump;
53 0
54 });
55
56 $cl->start;
57
58 $j->wait;