NAME

Reflex::Trait::Observer - Automatically observe Reflex objects.

VERSION

version 0.004

SYNOPSIS

# 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 },
);

DESCRIPTION

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.

setup

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.

role

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.

SEE ALSO

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