NAME
Reflex::Role::Timeout - set a wakeup callback for a relative delay
VERSION
This document describes version 0.090, released on July 30, 2011.
SYNOPSIS
package Reflex::Timeout;
use Moose;
extends 'Reflex::Base';
has delay => ( isa => 'Num', is => 'ro' );
has auto_start => ( isa => 'Bool', is => 'ro', default => 1 );
with 'Reflex::Role::Timeout' => {
delay => "delay",
cb_timeout => "on_done",
att_auto_start => "auto_start",
method_start => "start",
method_stop => "stop",
method_reset => "reset",
};
1;
DESCRIPTION
Reflex::Role::Timeout is a parameterized role. Each time it's consumed, it adds another non-blocking relative delay callback to a class. These callback will be invoked after a particular number of seconds have elapsed. The delay is contained in an attribute named by the role's delay
parameter.
Reflex::Timeout in the SYNOPSIS consumes a single Reflex::Role::Timeout. 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
delay
delay
names an attribute in the consumer that must hold the role's inactivity time, in seconds. The role will trigger a callback after that amount of time has elapsed, unless the timeout is stopped or reset before then.
Reflex usually supports fractional seconds, but this ultimately depends on the event loop being used.
Refex::Role::Timeout uses the attribute name in delay
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, a login prompt may have a short timeout to wait for input and a longer timeout to wait for authentication.
auto_start
Timeouts 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
.
method_stop
Reflex::Role::Timeout 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_" . $delay_name;
where $delay_name is the attribute name supplied by the delay
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 "reset_${timeout_name}"
, where $timeout_name is the attribute name provided in the timeout
parameter.
All Reflex methods accept a hashref of named parameters. Currently the reset method accepts one named parameter, "delay". The value of "delay" must be the new timeout to trigger a callback. If "delay" isn't provided, the timeout callback will happen at the previous time set by this module.
$self->reset_name( { delay => 60 } );
One may also set the delay attribute and reset the timer as two distinct calls.
$self->delay( 60 ); # 60 seconds from now
$self->reset_name();
method_start
This role provides a method to start timeouts, otherwise timeouts would never run if auto_start
were false. The method_start
can be used to override the default start method name, which is "start_${delay_name}". $delay_name is the name of the attribute provided in the delay
role parameter.
cb_timeout
cb_timeout
overrides the default method name that will be called when the "when" time arrives. The default is "on_${when_name}_done".
These callbacks receive no paramaters.
EXAMPLES
Reflex::Timeout is one example of using Reflex::Role::Timeout.
SEE ALSO
Please see those modules/websites for more information related to this module.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests through the web interface at http://rt.cpan.org.
AUTHOR
Rocco Caputo <rcaputo@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Rocco Caputo.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
AVAILABILITY
The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Reflex/.
The development version lives at http://github.com/rcaputo/reflex and may be cloned from git://github.com/rcaputo/reflex.git. Instead of sending patches, please fork this project using the standard git and github infrastructure.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.