Backbone::Events - a port of the Backbone.js event API
version 0.0.3
package MyProducer { use Moo; with 'Backbone::Events'; }; my $pub = MyProducer->new; package MySubscriber { use Moo; with 'Backbone::Events'; }; my $sub = MySubscriber->new; $sub->listen_to($pub, 'some-event', sub { ... }) ... $pub->trigger('some-event', qw(args for callback));
Backbone::Events is a Moo::Role which provides a simple interface for binding and triggering custom named events. Events do not have to be declared before they are bound, and may take passed arguments.
Events can be optionally namespaced by prepending the event with the namespace: '$namespace:$event'.
Bind a callback to an object.
Callbacks bound to the special 'all' event will be triggered when any event occurs, and are passed the name of the event as the first argument.
Returns the callback that was passed. This is mainly so anonymous functions can be returned, and later passed back to 'off'.
Remove a previously-bound callback from an object.
Trigger callbacks for the given event.
Just like 'on', but causes the bound callback to fire only once before being removed.
Tell an object to listen to a particular event on an other object. The other object must consume the Backbone::Events role.
Returns the callback that was passed. This is mainly so anonymous functions can be returned, and later passed back to 'stop_listening'.
Tell an object to stop listening to events.
Just like 'listen_to', but causes the bound callback to fire only once before being removed.
http://backbonejs.org/#Events
Mark Flickinger
This software is copyright (c) 2015 by Mark Flickinger.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Backbone::Events, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Backbone::Events
CPAN shell
perl -MCPAN -e shell install Backbone::Events
For more information on module installation, please visit the detailed CPAN module installation guide.