Mastod...stener(3pm)

πŸ“¦
version 0.017 Β· 2 versions
  • 0.017 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.017 Β· alpine 3.24
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

🌸 Mastodon::Listener β€” the manual page πŸ’…

okay bestie, welcome to the Mastodon::Listener page, from the User Contributed Perl Documentation corner of the 3pm section. this is the thing that lets your Perl code vibe with the streaming API of a Mastodon server, and honestly? it's giving main character energy. πŸ¦‹


✨ NAME ✨

Mastodon::Listener β€” Access the streaming API of a Mastodon server πŸ’–


πŸŽ€ SYNOPSIS πŸŽ€

# 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;

no cap, that's the whole vibe right there 🫢


πŸ’– DESCRIPTION πŸ’–

so here's the tea. a Mastodon::Listener object gets created when you call the stream method from a Mastodon::Client, and it has literally one (1) job: parsing a stream of events coming from a Mastodon server. that's it. that's the whole purpose. iconic behavior honestly πŸ‘‘

Mastodon::Listener objects inherit from Role::EventEmitter. so if you wanna know how to register callbacks for the different events, go read its documentation, bestie β€” that's where the details live. i'm just the messenger 🧚

once you've registered your callbacks, you set the whole thing in motion by calling its start method. and listen: start takes no arguments and it never returns. it's a forever girlie. πŸ’€

but don't panic, because the stop method exists, and you can call it from inside your callbacks to disconnect from the stream. so you're never actually trapped. slay ✨


🌈 ATTRIBUTES 🌈

⭐ access_token

The OAuth2 access token of your application, if authorization is needed. This is not needed for streaming from public timelines.

so like β€” if you're just lurking the public timeline, you don't need this. no key, no problem πŸ’…

⭐ api_version

The API version to use. Defaults to 1.

⭐ coerce_entities

Whether JSON responses should be coerced into Mastodon::Entity objects. Currently defaults to false (but this will likely change in v0.01).

⭐ instance

The instance to use, as a Mastodon::Entity::Instance object. Will be coerced from a URL, and defaults to "mastodon.social".

⭐ stream

The stream to use. Current valid streams are "public", "user", and tag timelines. To access a tag timeline, the argument to this value should begin with a hash character ("#").

⭐ url

The full streaming URL to use. By default, it is constructed from the values in the instance, api_version, and stream attributes.


πŸ”₯ 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.

πŸ’Œ error

Inherited from Role::EventEmitter, will be emitted when an error was found. The callback will be called with a fatal flag, an error message, and any relevant data as a single third argument.

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.


πŸ‘‘ AUTHOR πŸ‘‘

  • JosΓ© JoaquΓ­n Atria <jjatria@cpan.org>

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.


and that's the whole page, bestie!! 🫢 this was perl v5.36.0, dated 2022-11-03, and it lives at Mastod...stener(3pm) in the User Contributed Perl Documentation section. go stream something cute. bye bestie πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from