Skip to content

Commit

Permalink
better event emitter example
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 10, 2011
1 parent 8e686e5 commit dc99804
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/Mojo/EventEmitter.pm
Expand Up @@ -94,27 +94,28 @@ __END__
=head1 NAME
Mojo::EventEmitter - IOLoop event emitter
Mojo::EventEmitter - Event emitter base class
=head1 SYNOPSIS
use Mojo::EventEmitter;
# Subclass
package Cat;
use Mojo::Base 'Mojo::EventEmitter';
# Create new event emitter
my $e = Mojo::EventEmitter->new;
package main;
# Subscribe to events
$e->on(test => sub {
my ($self, $message) = @_;
say "test: $message";
my $tiger = Cat->new;
$tiger->on(roar => sub {
my ($self, $times) = @_;
say 'RAWR!' for 1 .. $times;
});
# Emit events
$e->emit(test => 'Hello!');
$tiger->emit(roar => 5);
=head1 DESCRIPTION
L<Mojo::EventEmitter> is the event emitter used by L<Mojo::IOLoop>.
L<Mojo::EventEmitter> is a simple base class for event emitting objects.
Note that this module is EXPERIMENTAL and might change without warning!
=head1 METHODS
Expand Down

0 comments on commit dc99804

Please sign in to comment.