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

NAME

Reflexive::Role::Collective - Provides a composable behavior for containers watching contained events

VERSION

version 1.113340

DESCRIPTION

Reflexive::Role::Collective provides are more comprehensive and extensible way to define collections that act upon events emitted from contained objects.

While Reflex::Collection merely watches for the 'stopped' event and removes it from the collection, a more sophisticated Collection can be built using this role that will do much more such as proper socket management, re-emit events, etc.

ROLE_PARAMETERS

collection

    default: objects

store contains the name of the attribute that holds the actual collection of objects.

method_add_object

    default: add_object

method_add_object is the name of the method that adds an object to the collection.

method_del_object

    default: delete_object

method_del_object is the name of the method that deletes objects from the collection.

method_count_objects

    default: count_objects

method_count_objects is the name of the method that returns the current count of objects within the collection.

method_clear_objects

    default: clear_objects

method_clear_objects is the name of the method that clears the collection of any objects.

method_remember

    default: remember

method_remember is the name of the method that stores the collectible and sets up watching the events that collectible emits.

method_forget

    default: forget

method_forget is the name of the method that removes the collectible and ignores any events that the collectible emits.

stored_constraint

    default: Any

stored_constraint stores a Moose::Meta::TypeConstaint object to be used to constraint collectibles before they are stored into the collection.

watched_events

    isa: ArrayRef[Tuple[Str,Str|Tuple[Str,Str]]],

watched_events contains an arrayref of tuples that indicate the event to watch and the callback method name to call when that event occurs. If the callback method name is also a tuple, a method will be setup with the name of the first element of the tuple and it will emit the event in the second element

    # example
    [ some_event => [ 'some_method_that_emits' => 'this_event' ] ]

Internally, the embedded tuple is passed unmodified to "method_emit" in Reflex::Role. This allows for easy setup of watched events that merely re-emit.

ROLE_REQUIRES

ignore

This role requires the method ignore from Reflex::Base

watch

This role requires the method watch from Reflex::Base

clear_objects

This role requires the method named in method_clear_objects

count_objects

This role requires the method named in method_count_objects

add_object

This role requires the method named in method_add_object

delete_object

This role requires the method named in method_del_object

PUBLIC_METHODS

remember

remember takes an object constrained by "store_constraint". It will then watch all of the events listed in "watched_events" and store the object into the collection

forget

forget takes an object constrained by "store_constraint". It will then ignore all of the events the collection was watching and the object will be removed from the collection.

AUTHOR

Nicholas R. Perez <nperez@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Nicholas R. Perez <nperez@cpan.org>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.