MooX::...mitter(3pm)

πŸ“¦
version 0.04 Β· 3 versions
, in ubuntu stonking

✨ NAME ✨

MooX::Role::EventEmitter β€” the event emitter role, bestie πŸ’–

okay so if you're reading the MooX::...mitter(3pm) page (User Contributed Perl Documentation, hi, you're in the right place), welcome!! this is the whole vibe: it's a role that makes your Moo classes able to emit events and have people subscribe to them. it's giving tiny pub/sub without any of the drama. πŸ¦‹


🌸 SYNOPSIS 🌸

package My::Thing;
use 5.020;
use feature 'signatures';
no warnings 'experimental::signatures';
use Moo 2;
with 'MooX::Role::EventEmitter';

sub event_received( $self, $ev ) {
    $self->emit( myevent => $ev );
}

# ... later, in your client

package main;
my $foo = My::Thing->new();
$foo->on( myevent => sub( $ev ) {
    say "I receivend an event";
});

see how we with the role, then emit when something happens, and the client just goes on and passes a callback?? that's it. that's the whole relationship. periodt. πŸ’…


πŸ’… METHODS πŸ’…

$obj->emit $name, @args

emit an event. this is you yelling into the group chat, and everyone subscribed hears it. πŸ”₯

$obj->has_subscribers $name

check if an event has subscribers. basically "is anyone even listening rn" 😭

$obj->on $name, @args

my $cb = $obj->on( myevent => sub { ... });

subscribe to an event. you get back a callback handle, hold onto it, it's your little receipt. πŸŽ€

$obj->once $name, @args

my $cb = $obj->once( myevent => sub { ... });

subscribe to an event for just one event. one and done, no strings, we love a low-commitment moment. ✨

$obj->subscribers( $name )

my $s = $obj->subscribers( 'myevent' );

return an arrayref of the subscribers for an event. it's not a list, bestie, it's an arrayref β€” wrap it like $s->@* and go off. πŸ‘‘

$obj->unsubscribe( $name => $cb )

$obj->unsubscribe('myevent', $cb); # a specific callback
$obj->unsubscribe('myevent');      # all callbacks

unsubscribe from event. either yeet one specific callback, or clear out everybody at once. your call, main character. πŸ’€


πŸ‘€ SEE ALSO πŸ‘€

  • Mojo::EventEmitter β€” the module this API is based on 🫢

that's the whole page, fr fr. go forth and emit. πŸŒˆπŸ’œ

β€” mwah, this was MooX::...mitter(3pm), perl v5.40.1, 2025-10-11, from your bestie who is genuinely obsessed with event-driven code πŸŽ€β­

πŸ“¦ where this page comes from