Deeme - a Database-agnostic driven Event Emitter
package Cat; use Deeme::Obj 'Deeme'; use Deeme::Backend::Meerkat; # app1.pl package main; # Subscribe to events in an application (thread, fork, whatever) my $tiger = Cat->new(backend=> Deeme::Backend::Meerkat->new(...) ); #or you can just do Deeme->new $tiger->on(roar => sub { my ($tiger, $times) = @_; say 'RAWR!' for 1 .. $times; }); ... #then, later in another application # app2.pl my $tiger = Cat->new(backend=> Deeme::Backend::Meerkat->new(...)); $tiger->emit(roar => 3);
Deeme is a database-agnostic driven event emitter base-class. Deeme allows you to define binding subs on different points in multiple applications, and execute them later, in another worker. It is handy if you have to attach subs to events that are delayed in time and must be fixed. It can act also like a jobqueue and It is strongly inspired by (and a rework of) Mojo::EventEmitter.
Have a look at Deeme::Worker for the jobqueue functionality.
Deeme can emit the following events.
$e->on(error => sub { my ($e, $err) = @_; ... });
Emitted for event errors, fatal if unhandled.
$e->on(error => sub { my ($e, $err) = @_; say "This looks bad: $err"; });
Deeme inherits all methods from Deeme::Obj and implements the following new ones.
$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.
$e = $e->reset;
Delete all events on the backend.
$e = $e->emit_safe('foo'); $e = $e->emit_safe('foo', 123);
Emit event safely and emit "error" event on failure.
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 DEEME_DEBUG environment variable to get some advanced diagnostics information printed to STDERR.
DEEME_DEBUG
STDERR
DEEME_DEBUG=1
mudler <mudler@dark-lab.net>
Copyright 2014- mudler
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Deeme::Worker, Deeme::Backend::Memory, Deeme::Backend::Mango, Deeme::Backend::Meerkat, Mojo::EventEmitter, Mojolicious
To install Deeme, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Deeme
CPAN shell
perl -MCPAN -e shell install Deeme
For more information on module installation, please visit the detailed CPAN module installation guide.