Reflex::Trait::Observer - Automatically observe Reflex objects.
version 0.010
# Not a complete program. This example comes from Reflex's main # synopsis.
has clock => ( isa => 'Reflex::Timer', is => 'rw', traits => [ 'Reflex::Trait::Observer' ], setup => { interval => 1, auto_repeat => 1 }, );
Reflex::Trait::Observer allows one Reflex::Object to automatically observe other another it has stored in an attribute. In the SYNOPSIS, storing a Reflex::Timer in the clock() attribute allows the owner to observe the timer's events.
This trait is a bit of Moose-based syntactic sugar for Reflex::Object's more explict observe() and observe_role() methods.
The "setup" option provides default constructor parameters for the attribute. In the above example, clock() will by default contain
Reflex::Timer->new(interval => 1, auto_repeat => 1);
In other words, it will emit the Reflex::Timer event ("tick") once per second until destroyed.
Attribute events are mapped to the owner's methods using Reflex's role-based callback convention. For example, Reflex will look for an on_clock_tick() method to handle "tick" events from an object with the 'clock" role.
The "role" option allows roles to be set or overridden. An observer attribute's name is its default role.
The "setup" option is a work-around for unfortunate default timing. It will be deprecated if default can be made to work instead.
Reflex Reflex::Trait::Emitter
"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex
To install Reflex, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Reflex
CPAN shell
perl -MCPAN -e shell install Reflex
For more information on module installation, please visit the detailed CPAN module installation guide.