The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mastodon::Listener - Access the streaming API of a Mastodon server

SYNOPSIS

  use Mastodon::Client;

  my $client = Mastodon::Client->new(
    instance        => 'mastodon.social',
    name            => 'PerlBot',
    client_id       => $client_id,
    client_secret   => $client_secret,
    access_token    => $access_token,
    coerce_entities => 1,
  );

  $client->post_status('Posted to a Mastodon server!');
  $client->post_status('And now in secret...',
    { visibility => 'unlisted ' }
  )

  # Streaming interface might change!
  my $listener = $client->stream( 'public' );
  $listener->on( update => sub {
    my ($listener, $status) = @_;
    printf "%s said: %s\n",
      $status->account->display_name,
      $status->content;
  });
  $listener->start;

DESCRIPTION

A Mastodon::Listener object is created by calling the stream method from a Mastodon::Client, and it exists for the sole purpose of parsing a stream of events from a Mastodon server.

Matodon::Listener objects inherit from AnyEvent::Emitter. Please refer to their documentation for details on how to register callbacks for the different events.

Once callbacks have been registered, the listener can be set in motion by calling its start() method, which takes no arguments and never returns.

EVENTS

update

A new status has appeared. Callback will be called with the listener and the new status.

notification

A new notification has appeared. Callback will be called with the listener and the new notification.

delete

A status has been deleted. Callback will be called with the listener and the ID of the deleted status.

heartbeat

A new :thump has been received from the server. This is mostly for debugging purposes.

AUTHOR

  • José Joaquín Atria <jjatria@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by José Joaquín Atria.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.