The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Backbone::Events - a port of the Backbone.js event API

VERSION

version 0.0.3

SYNOPSIS

    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));

DESCRIPTION

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'.

METHODS

on($event, $callback)

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'.

off([$event], [$callback])

Remove a previously-bound callback from an object.

trigger($event, @args)

Trigger callbacks for the given event.

once($event, $callback)

Just like 'on', but causes the bound callback to fire only once before being removed.

Returns the callback that was passed. This is mainly so anonymous functions can be returned, and later passed back to 'off'.

listen_to($other, $event, $callback)

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'.

stop_listening([$other], [$event], [$callback])

Tell an object to stop listening to events.

listen_to_once($other, $event, $callback)

Just like 'listen_to', but causes the bound callback to fire only once before being removed.

Returns the callback that was passed. This is mainly so anonymous functions can be returned, and later passed back to 'stop_listening'.

SEE ALSO

http://backbonejs.org/#Events

AUTHOR

Mark Flickinger

COPYRIGHT AND LICENSE

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.