AnyEvent-Net-MPD

 view release on metacpan or  search on metacpan

t/example/chat.pl  view on Meta::CPAN

# channel without subscribers is an error.
foreach my $name (keys %accounts) {
  my @commands = map { [ subscribe => $_ ] } keys %accounts;
  $accounts{$name}->send( \@commands )->recv;
}

# Check for messages every X seconds
my $interval = 1;

# Check for messages in channels this account is subscribed to
my $timer = AnyEvent->timer(
  after => 1,
  interval => $interval,
  cb => sub {
    # We check for messages for all accounts
    foreach my $name (keys %accounts) {
      $accounts{$name}->send( 'read_messages', sub {
        # The message payload is an array of hashes. Each has the name of the
        # channel (= the sender) and an arrayref with the unseen messages
        foreach my $channel (@{shift->recv}) {
          # Print who said who, and reply. We don't want to be rude!



( run in 1.313 second using v1.01-cache-2.11-cpan-49f99fa48dc )