Beam::Emitter - Role for event emitting classes
package My::Emitter; use Moo; with 'Beam::Emitter'; sub do_something { my ( $self ) = @_; # Give event listeners a chance to prevent something my $event = $self->emit( "before_something" ); return if $event->is_default_stopped; # ... do something # Notify listeners we're done with something $self->emit( 'after_something' ); }
This role is used by classes that want to emit Beam::Event objects to subscribers.
Beam::Event
Subscribe to an event from this object. event_name is the name of the event. subref is a subroutine reference that takes a single argument, the Beam::Event that is being emitted.
event_name
subref
Unsubscribe from an event. event_name is the name of the event. subref is the single listener subref to be removed. If no subref is given, will remove all listeners for this event.
Emit an event with the given name. event_args is a list of name => value pairs to give to the Beam::Event object.
name
event_args
Use the class key in event_args to specify a different Event class.
class
To install Beam::Emitter, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Beam::Emitter
CPAN shell
perl -MCPAN -e shell install Beam::Emitter
For more information on module installation, please visit the detailed CPAN module installation guide.