MooX::...mitter(3pm)
β¨ 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
- ubuntu stonking: libmoox-role-eventemitter-perl 0.04-1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms