NAME

Reflex::Role::Interval - set a periodic, recurring timer

VERSION

version 0.060

SYNOPSIS

package Reflex::Interval;

use Moose;
extends 'Reflex::Base';

has interval    => ( isa => 'Num', is  => 'ro' );
has auto_repeat => ( isa => 'Bool', is => 'ro', default => 1 );
has auto_start  => ( isa => 'Bool', is => 'ro', default => 1 );

with 'Reflex::Role::Interval' => {
	interval      => "interval",
	auto_start    => "auto_start",
	auto_repeat   => "auto_repeat",
	cb_tick       => "on_tick",
	method_start  => "start",
	method_stop   => "stop",
	method_repeat => "repeat",
};

1;

DESCRIPTION

Reflex::Role::Interval adds a periodic timer and callback to a class. It's parameterized, so it can be consumed multiple times to add more than one interval timer to the same class.

In the SYNOPSIS, the Reflex::Interval class consumes a single Reflex::Role::Interval. Reflex::Interval provides some data in the form of interval(), auto_repeat() and auto_start(). The role provides a callback to the on_tick() method, which is also provided by the role. The role also provides some control methods, start(), stop() and repeat().

The general rules and conventions for Reflex paramaeterized roles are covered in Reflex::Role.

Attribute Parameters

Attribute parameters specify the names of attributes in the consumer that control the role's behavior.

interval

interval names an attribute in the consumer that must hold the role's interval, in seconds. The role will trigger a callback every interval() seconds, if the auto_repeat attribute is true.

interval is a Reflex::Role "key" attribute. The interval attribute's name is used in the default names for the role's internal and public attributes, methods and callbacks.

auto_repeat

Interval timers will repeat automatically if the value of the attribute named in auto_repeat is true. Otherwise, repeat() must be called to trigger the next interval callback, interval seconds after repeat() is called.

auto_start

Interval timers will automatically start if the value of the attribute named in auto_start is true. Otherwise, the class consuming this role must call the role's start method, named in method_start.

Callback Parameters

Callback parameters specify the names of methods in the consumer that will be called when the role notifies the class of events.

cb_tick

cb_tick sets the name of the tick callback method, which must be implemented by this role's consumer. cb_tick is optional, and will default to the catenation of "on_", the name of the interval attribute, and "_tick".

Reflex::Role::Interval provides a default callback that will emit the "tick" event and repeat the timer if <$self-$auto_repeat()>> evaluates to true.

Method Parameters

Method parameters generally specify the names of methods the role will provide to modify the role's behavior.

method_repeat

Reflex::Role::Interval provides a method to manually trigger repetition of the interval timer. This method exists in case auto_repeat evaluates to false. The repeat method name may be overridden by method_repeat's value. By default, the repeat method will be "repeat_" prepended to the name of the interval attribute.

method_start

Reflex::Role::Interval provides a method to start the interval timer, which is vital for cases when auto_start evaluates to false. The start method name may be overridden by method_start's value. By default, the start method will be "start_" prepended to the name of the interval attribute.

method_stop

Reflex::Role::Interval provides a method to stop the interval timer. This method will be flattened into the consuming class, per Moose. method_stop allows the role's consumer to define the name of that method. By default, the stop method's name will be "stop_" prepended to the name of the interval attribute.

EXAMPLES

Reflex::Timeout is one example of using Reflex::Role::Timeout.

SEE ALSO

Reflex Reflex::Interval Reflex::Role

"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