NAME

Reflex::Role::Wakeup - set a wakeup callback for a particular UNIX time

VERSION

version 0.085

SYNOPSIS

package Reflex::Wakeup;

use Moose;
extends 'Reflex::Base';

has when => ( isa => 'Num', is  => 'rw' );

with 'Reflex::Role::Wakeup' => {
	when          => "when",
	cb_wakeup     => "on_time",
	method_stop   => "stop",
	method_reset  => "reset",
};

1;

DESCRIPTION

Reflex::Role::Wakeup is a parameterized role. Each time it's consumed, it adds another non-blocking wakeup callback to a class. These callback will be invoked at particular UNIX times, established by the contents of the "when" attributes named at composition time.

Reflex::Wakeup in the SYNOPSIS consumes a single Reflex::Role::Wakeup. The parameters define the names of attributes that control the timer's behavior, the names of callback methods, and the names of methods that manipulate the timer.

Required Role Parameters

None. All role parameters have defaults.

Optional Role Parameters

when

when names an attribute in the consumer that must hold the role's wakeup time. Wakeup times are specified as seconds since the UNIX epoch. Reflex usually supports fractional seconds, but this ultimately depends on the event loop being used.

Refex::Role::Wakeup uses the attribute name in when to differentiate between multiple applications of the same role to the same class. Reflex roles are building blocks of program behavior, and it's reasonable to expect a class to need multiple building blocks of the same type. For instance, multiple wakeup timers for different purposes.

method_stop

Reflex::Role::Wakeup will provide a method to stop the timer. This method will become part of the consuming class, per Moose. method_stop allows the consumer to define the name of that method. By default, the method will be named:

$method_stop = "stop_" . $when_name;

where $when_name is the attribute name supplied by the when parameter.

The stop method neither takes parameters nor returns anything.

method_reset

method_reset allows the role's consumer to override the default reset method name. The default is "stop_${when_name}", where $when_name is the attribute name provided in the when parameter.

All Reflex methods accept a hashref of named parameters. Currently the reset method accepts one named parameter, "when". The value of "when" must be the new time to trigger a callback. If "when" isn't provided, the wakeup callback will happen at the previous time set by this module.

$self->reset_name( { when => time() + 60 } );

One may also set the when() attribute and reset() the timer as two distinct calls.

$self->time( time() + 60 );  # 60 seconds from now
$self->reset_time();

cb_wakeup

cb_wakeup overrides the default method name that will be called when the "when" time arrives. The default is "on_${when_name}_wakeup".

These callbacks receive no paramaters.

EXAMPLES

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

SEE ALSO

Reflex Reflex::Wakeup 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