NAME

MooseX::EventEmitter - Moose Event emitter

SYNOPSIS

package Person {
	use Moose;

	with 'MooseX::EventEmitter';

	...

	sub save {
		my $self = shift();

		...

		$self->emit( 'saved', time() );
	}

	__PACKAGE__->meta()->make_immutable();
}

package main {
	use Person;

	my $person = Person->new( { ... } );

	$person->on( saved => sub {
			my ( $self, $saved_at ) = @_;

			printf( "Person saved at %d\n", $saved_at );
		}
	);

	$person->unsubscribe();
}

DESCRIPTION

This was inspired by Mojo::EventEmitter but adapted for Moose. Mojolicious has it's own object system, I wanted to make this a Moose "native" component. It's a lighter alternative to MooseX::Event. which more knobs if you need that.

METHODS

on

$object->on( event_name => sub { ... } );

Adds and subscriber to a named event.

emit

$object->emit( 'event_name', $arg1, $arg2 );

Calls all subscribers to a given event and passes the arguments to each callback.

unsubscribe

$object->unsubscribe( 'event_name' )
$object->unsubscribe( 'event_name', $callback );

Removed a subscriber or all subscribers for the named event.

AUTHOR

Tudor Marghidanu <tudor@marghidanu.com>

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO