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
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms