File: test_client

package info (click to toggle)
libanyevent-xmpp-perl 0.55-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 784 kB
  • ctags: 553
  • sloc: perl: 8,004; makefile: 13
file content (58 lines) | stat: -rw-r--r-- 1,353 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/opt/perl/bin/perl
use strict;
use utf8;
use AnyEvent;
use AnyEvent::XMPP qw/xep-86/;
use AnyEvent::XMPP::Client;
use Encode;

binmode STDOUT, ":utf8";

my $j = AnyEvent->condvar;
my $cl = AnyEvent::XMPP::Client->new (debug => 1);
$cl->set_presence ('away', 'I\'m a bot now.', 1);
$cl->add_account (@ARGV, undef, undef);
$cl->reg_cb (
   connected => sub {
      $cl->send_message ("Hello!" => 'elmex@jabber.org');
      0
   },
   roster_update => sub {
      my ($cl, $acc, $roster, $contacts) = @_;
      $roster->debug_dump;
      #$acc->connection ()->send_presence ('probe' => undef, to => 'elmex@jabfber.org');
      #print "OEOFWEFIEJWFEWO\n" if not $roster->is_retrieved;
      1
   },
   presence_update => sub {
      my ($cl, $acc, $roster, $contact, $old, $new) = @_;
      $roster->debug_dump;
      1
   },
   error => sub {
      my ($cl, $acc, $error) = @_;
      print "ERROR: ".$error->string."\n";
   },
   disconnect => sub { warn "DISCON[@_]\n"; 1 },
);

$cl->reg_cb (contact_request_subscribe => sub {
   my ($cl, $acc, $roster, $contact) = @_;
   $contact->send_subscribe;
   0
});

$cl->reg_cb (contact_did_unsubscribe => sub {
   my ($cl, $acc, $roster, $contact, $rdoit) = @_;
   1
});

$cl->reg_cb (roster_update => sub {
   my ($cl, $acc, $roster, $contacts) = @_;
   $roster->debug_dump;
   0
});

$cl->start;

$j->wait;