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

NAME

Reflex::Trait::Observed - Automatically watch Reflex objects.

VERSION

version 0.060

SYNOPSIS

# Not a complete program. This example comes from Reflex's main # synopsis.

        has clock => (
                isa     => 'Reflex::Interval',
                is      => 'rw',
                traits  => [ 'Reflex::Trait::Observed' ],
                setup   => { interval => 1, auto_repeat => 1 },
        );

DESCRIPTION

Reflex::Trait::Observed modifies a member to automatically observe any Reflex::Base object stored within it. In the SYNOPSIS, storing a Reflex::Interval in the clock() attribute allows the owner to watch the timer's events.

This trait is a bit of Moose-based syntactic sugar for Reflex::Base's more explict watch() and watch_role() methods.

setup

The "setup" option provides default constructor parameters for the attribute. In the above example, clock() will by default contain

        Reflex::Interval->new(interval => 1, auto_repeat => 1);

In other words, it will emit the Reflex::Interval 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. A watcher attribute's name is its default role.

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::EmitsOnChange

"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