Mojo::EventEmitter(3)

πŸŽ€ NAME β€” Mojo::EventEmitter(3) ✨

okay bestie, welcome to the Mojo::EventEmitter(3) page from the User Contributed Perl Documentation. this is all about Mojo::EventEmitter - Event emitter base class. it’s giving tiny but mighty. πŸ’…

πŸ¦‹ SYNOPSIS

package Cat;
use Mojo::Base 'Mojo::EventEmitter', -signatures;

# Emit events
sub poke ($self) { $self->emit(roar => 3) }

package main;

# Subscribe to events
my $tiger = Cat->new;
$tiger->on(roar => sub ($tiger, $times) { say 'RAWR!' for 1 .. $times });
$tiger->poke;

πŸ’– DESCRIPTION

Mojo::EventEmitter is a simple base class for event emitting objects. literally that’s the whole vibe. ✨

🌈 EVENTS

Mojo::EventEmitter can emit the following events. here’s the event menu πŸ‘‘

😭 error

$e->on(error => sub ($e, $err) {...});

this is a special event for errors, bestie. it will not be emitted directly by this class, but it is fatal if unhandled. subclasses may choose to emit it, but they are not required to do so. no cap.

$e->on(error => sub ($e, $err) { say "This looks bad: $err" });

πŸ› οΈ METHODS

Mojo::EventEmitter inherits all methods from Mojo::Base and implements the following new ones. periodt.

🧲 catch

$e = $e->catch(sub {...});

Subscribe to the "error" event. it’s giving shortcut energy. longer version:

# Longer version
$e->on(error => sub {...});

πŸš€ emit

$e = $e->emit('foo');
$e = $e->emit('foo', 123);

Emit event.

πŸ” has_subscribers

my $bool = $e->has_subscribers('foo');

Check if event has subscribers.

πŸ‘‚ on

my $cb = $e->on(foo => sub {...});

Subscribe to event.

$e->on(foo => sub ($e, @args) {...});

1️⃣ once

my $cb = $e->once(foo => sub {...});

Subscribe to event and unsubscribe again after it has been emitted once.

$e->once(foo => sub ($e, @args) {...});

πŸ‘₯ subscribers

my $subscribers = $e->subscribers('foo');

All subscribers for event.

# Unsubscribe last subscriber
$e->unsubscribe(foo => $e->subscribers('foo')->[-1]);

# Change order of subscribers
@{$e->subscribers('foo')} = reverse @{$e->subscribers('foo')};

βœ‚οΈ unsubscribe

$e = $e->unsubscribe('foo');
$e = $e->unsubscribe(foo => $cb);

Unsubscribe from event.

πŸ”¬ DEBUGGING

You can set the "MOJO_EVENTEMITTER_DEBUG" environment variable to get some advanced diagnostics information printed to "STDERR". yes bestie, diagnostics tea β˜•

MOJO_EVENTEMITTER_DEBUG=1

🫢 SEE ALSO

Mojolicious, Mojolicious::Guides, <https://mojolicious.org> β€” go explore, iykyk.

okay that’s the whole page, bestie 🫢 β€” this is the Mojo::EventEmitter(3) manual from perl v5.42.0, dated 2026-07-15. mwah πŸ’‹

πŸ“¦ where this page comes from