Mastodon::Listener(3pm) | User Contributed Perl Documentation | Mastodon::Listener(3pm) |
Mastodon::Listener - Access the streaming API of a Mastodon server
# From Mastodon::Client my $listener = $client->stream( 'public' ); # Or use it directly my $listener = Mastodon::Listener->new( url => 'https://mastodon.cloud/api/v1/streaming/public', access_token => $token, coerce_entities => 1, ) $listener->on( update => sub { my ($listener, $status) = @_; printf "%s said: %s\n", $status->account->display_name, $status->content; }); $listener->start;
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.
Mastodon::Listener objects inherit from Role::EventEmitter. Please refer to its 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. The stop method can be called from within callbacks to disconnect from the stream.
If the error event is triggered in response to a 4xx or 5xx error, the data payload will be an array reference with the response and request objects as received from Net::Async::HTTP.
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.
2022-11-03 | perl v5.36.0 |