NAME

Reflex::Trait::Emitter - Emit an event when an attribute's value changes.

VERSION

version 0.010

SYNOPSIS

# Not a complete program.  See examples eg-09-emitter-trait.pl
# and eg-10-setup.pl for working examples.

package Counter;
use Moose;
extends 'Reflex::Object';
use Reflex::Trait::Emitter;

has count   => (
	traits    => ['Reflex::Trait::Emitter'],
	isa       => 'Int',
	is        => 'rw',
	default   => 0,
);

DESCRIPTION

An attribute with the Reflex::Trait::Emitter trait emit an event on behalf of its object whenever its value changes. The event will be named after the attribute by default. It will be accompanied by a "value" parameter, the value of which is the attribute's new value at the time of the change.

In the SYNOPSIS example, changes to count() cause its Counter object to emit "count" events.

event

The "default" option can be used to override the default event emitted by the Reflex::Trait::Emitter trait. That default, by the way, is the name of the attribute.

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.

CAVEATS

The "setup" option is a work-around for unfortunate default timing. It will be deprecated if default can be made to work instead.

SEE ALSO

Reflex Reflex::Trait::Observer

"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