Rocco Caputo > Reflex-0.099 > Reflex::Role::Interval

Download:
Reflex-0.099.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Module Version: 0.099   Source  

NAME ^

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

VERSION ^

This document describes version 0.099, released on April 21, 2013.

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 ^

Please see those modules/websites for more information related to this module.

BUGS AND LIMITATIONS ^

You can make new bug reports, and view existing ones, through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Reflex.

AUTHOR ^

Rocco Caputo <rcaputo@cpan.org>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2013 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 https://metacpan.org/module/Reflex/.

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.

syntax highlighting: