AnyEvent::Emitter - Event emitter base class (Mojo::EventEmitter porting).
package Cat; use 5.010; use base 'AnyEvent::Emitter'; # Emit events sub poke { my $self = shift; $self->emit(roar => 3); } package main; # Subscribe to events my $tiger = Cat->new; $tiger->on(roar => sub { my ($tiger, $times) = @_; say 'RAWR!' for 1 .. $times; }); $tiger->poke;
AnyEvent::Emitter is a simple base class for event emitting objects(Mojo::EventEmitter porting).
AnyEvent::Emitter can emit the following events.
$e->on(error => sub { my ($e, $err) = @_; ... });
This is a special event for errors, it will not be emitted directly by this class but is fatal if unhandled.
$e->on(error => sub { my ($e, $err) = @_; say "This looks bad: $err"; });
$e = $e->catch(sub {...});
Subscribe to "error" event.
# Longer version $e->on(error => sub {...});
$e = $e->emit('foo'); $e = $e->emit('foo', 123);
Emit event.
my $bool = $e->has_subscribers('foo');
Check if event has subscribers.
my $cb = $e->on(foo => sub {...});
Subscribe to event.
$e->on(foo => sub { my ($e, @args) = @_; ... });
my $cb = $e->once(foo => sub {...});
Subscribe to event and unsubscribe again after it has been emitted once.
$e->once(foo => sub { my ($e, @args) = @_; ... });
my $subscribers = $e->subscribers('foo');
All subscribers for event.
# Unsubscribe last subscriber $e->unsubscribe(foo => $e->subscribers('foo')->[-1]);
$e = $e->unsubscribe('foo'); $e = $e->unsubscribe(foo => $cb);
Unsubscribe from event.
You can set the EMITTER_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.
EMITTER_DEBUG
STDERR
EMITTER_DEBUG=1
Mojo::EventEmitter
To install AnyEvent::Emitter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Emitter
CPAN shell
perl -MCPAN -e shell install AnyEvent::Emitter
For more information on module installation, please visit the detailed CPAN module installation guide.