AnyEve...:Event(3pm)

πŸ“¦ version 0.20, in ubuntu stonking

🌸 AnyEvent::FTP::Role::Event πŸ’…

okay bestie, welcome to the perl manual page for AnyEvent::FTP::Role::Event β€” that's a 3pm section page living in the User Contributed Perl Documentation, and it's genuinely so useful, no cap.


✨ NAME ✨

AnyEvent::FTP::Role::Event β€” literally the event interface for AnyEvent::FTP objects πŸ¦‹


πŸŽ€ VERSION πŸŽ€

version 0.20 β€” she's grown, she's thriving ✨


🧚 SYNOPSIS 🧚

here's the whole vibe. first you make a class and pull in the role:

package AnyEvent::FTP::Foo;

use Moo;
with 'AnyEvent::FTP::Role::Event';
__PACKAGE__->define_events(qw( error good ));

sub some_method
{
  my($self) = @_;

  if($self->other_method)
  {
    $self->emit(good => 'paylod message');
  }
  else
  {
    $self->emit(error => 'something went wrong!');
  }
}

then, later on somewhere else, you actually listen for the events:

use AnyEvent::FTP::Foo;

my $foo = AnyEvent::FTP::Foo->new;
$foo->on_good(sub {
  my($message) = @_;
  print "worked: $message";
});
$foo->on_error(sub {
  my($message) = @_;
  print "failed: $message";
});

$foo->some_method

see how it's giving main character energy? define the events once, flex them anywhere πŸ’–


πŸ’œ DESCRIPTION πŸ’œ

so this role hands every class in AnyEvent::FTP the same uniform event callback mechanism, which is honestly iconic of her. 🫢

you declare your events with the define_events method. once they're declared, you get on_event_name to attach a callback to a particular event, and emit to actually trigger those callbacks. it's a whole little ecosystem and i'm obsessed 😭


πŸ‘‘ METHODS πŸ‘‘

πŸ’« define_events

__PACKAGE__->define_events( @list_of_event_names );

you call this inside the class package to declare the event names for every event the class is gonna use. in return it makes methods shaped like on_event_name, which are exactly the ones you use to add callbacks to events. slay ✨

πŸ’« emit

$obj->emit($event_name, @arguments);

this calls the callbacks that are associated with the $event_name you pass in. and it passes your @arguments straight along to that callback. no middleman nonsense, just direct delivery πŸ“¬


🌈 SEE ALSO 🌈

  • AnyEvent::FTP β€” the parent vibe, go read her too πŸ’–

πŸ“ AUTHOR πŸ“

Author: Graham Ollis <plicease@cpan.org>

Contributors:

  • Ryo Okamoto
  • Shlomi Fish
  • JosΓ© JoaquΓ­n Atria

This software is copyright (c) 2017-2022 by Graham Ollis.

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


ngl none of this would exist without Graham Ollis and the contributors β€” legends only πŸ’…

and that's a wrap, bestie!! this page came from perl v5.40.1 and was dated 2026-02-16, so go forth and emit responsibly βœ¨πŸ’–πŸ¦‹ periodt

πŸ“¦ where this page comes from