MooX::Role::EventEmitter - Event emitter role
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"; });
$obj->emit $name, @args
Emit an event
$obj->has_subscribers $name
Check if an event has subscribers.
$obj->on $name, @args
my $cb = $obj->on( myevent => sub { ... });
Subscribe to an event.
$obj->once $name, @args
my $cb = $obj->once( myevent => sub { ... });
Subscribe to an event for just one event.
$obj->subscribers( $name )
my $s = $obj->subscribers( 'myevent' );
Return an arrayref of the subscribers for an event.
$obj->unsubscribe( $name => $cb )
$obj->unsubscribe('myevent', $cb); # a specific callback $obj->unsubscribe('myevent'); # all callbacks
Unsubscribe from event.
Mojo::EventEmitter - the module this API is based on
To install MooX::Role::EventEmitter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooX::Role::EventEmitter
CPAN shell
perl -MCPAN -e shell install MooX::Role::EventEmitter
For more information on module installation, please visit the detailed CPAN module installation guide.