line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Reflex::Interval; |
2
|
|
|
|
|
|
|
# vim: ts=2 sw=2 noexpandtab |
3
|
|
|
|
|
|
|
$Reflex::Interval::VERSION = '0.100'; |
4
|
6
|
|
|
6
|
|
1363479
|
use Moose; |
|
6
|
|
|
|
|
325427
|
|
|
6
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
extends 'Reflex::Base'; |
6
|
6
|
|
|
6
|
|
30824
|
use Reflex::Callbacks qw(make_emitter); |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
37
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
has interval => ( isa => 'Num', is => 'rw' ); |
9
|
|
|
|
|
|
|
has auto_repeat => ( isa => 'Bool', is => 'rw', default => 1 ); |
10
|
|
|
|
|
|
|
has auto_start => ( isa => 'Bool', is => 'ro', default => 1 ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
with 'Reflex::Role::Interval' => { |
13
|
|
|
|
|
|
|
att_auto_repeat => "auto_repeat", |
14
|
|
|
|
|
|
|
att_auto_start => "auto_start", |
15
|
|
|
|
|
|
|
att_interval => "interval", |
16
|
|
|
|
|
|
|
cb_tick => make_emitter(on_tick => "tick"), |
17
|
|
|
|
|
|
|
method_repeat => "repeat", |
18
|
|
|
|
|
|
|
method_start => "start", |
19
|
|
|
|
|
|
|
method_stop => "stop", |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
__END__ |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=pod |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=encoding UTF-8 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=for :stopwords Rocco Caputo |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 NAME |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Reflex::Interval - A stand-alone multi-shot periodic callback |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 VERSION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This document describes version 0.100, released on April 02, 2017. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SYNOPSIS |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
As with all Reflex objects, Reflex::Interval may be used in many |
45
|
|
|
|
|
|
|
different ways. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Inherit it and override its on_tick() callback, with or without using |
48
|
|
|
|
|
|
|
Moose. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
package App; |
51
|
|
|
|
|
|
|
use Reflex::Interval; |
52
|
|
|
|
|
|
|
use base qw(Reflex::Interval); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub on_tick { |
55
|
|
|
|
|
|
|
print "tick at ", scalar(localtime), "...\n"; |
56
|
|
|
|
|
|
|
shift()->repeat(); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Run it as a promise that generates periodic events. All other Reflex |
60
|
|
|
|
|
|
|
objects will also be running while C<<$pt->next()>> is blocked. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $pt = Reflex::Interval->new( |
63
|
|
|
|
|
|
|
interval => 1 + rand(), |
64
|
|
|
|
|
|
|
auto_repeat => 1, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
while (my $event = $pt->next()) { |
68
|
|
|
|
|
|
|
eg_say("promise timer returned an event ($event->{name})"); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Plain old callbacks: |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $ct = Reflex::Interval->new( |
74
|
|
|
|
|
|
|
interval => 1, |
75
|
|
|
|
|
|
|
auto_repeat => 1, |
76
|
|
|
|
|
|
|
on_tick => sub { print "coderef callback triggered\n" }, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
Reflex->run_all(); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
And so on. See Reflex, Reflex::Base and Reflex::Role::Reactive for |
81
|
|
|
|
|
|
|
details. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Reflex::Interval invokes a callback after a specified interval of time |
86
|
|
|
|
|
|
|
has passed, and then after every subsequent interval of time. |
87
|
|
|
|
|
|
|
Interval timers may be stopped and started. Their timers may be |
88
|
|
|
|
|
|
|
automatically or manually repeated. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 Public Attributes |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head3 interval |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/interval>. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head3 auto_repeat |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/auto_repeat>. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head3 auto_start |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/auto_start>. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 Public Callbacks |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head3 on_tick |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/cb_tick>. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 Public Methods |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head3 repeat |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/method_repeat>. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head3 start |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/method_start>. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head3 stop |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Implemented and documented by L<Reflex::Role::Interval/method_stop>. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 EXAMPLES |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
TODO - Many. Link to them. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 SEE ALSO |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Please see those modules/websites for more information related to this module. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over 4 |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L<Reflex|Reflex> |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<Reflex> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L<Reflex::Role> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<Reflex::Role::Interval> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L<Reflex::Role::Timeout> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item * |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
L<Reflex::Role::Wakeup> |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L<Reflex::Timeout> |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<Reflex::Wakeup> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L<Reflex/ACKNOWLEDGEMENTS> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L<Reflex/ASSISTANCE> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L<Reflex/AUTHORS> |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item * |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
L<Reflex/BUGS> |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=item * |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
L<Reflex/BUGS> |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=item * |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
L<Reflex/CONTRIBUTORS> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=item * |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
L<Reflex/COPYRIGHT> |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=item * |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L<Reflex/LICENSE> |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item * |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
L<Reflex/TODO> |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=back |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through the |
207
|
|
|
|
|
|
|
web interface at L<http://rt.cpan.org/Public/Dist/Display.html?Name=Reflex>. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=head1 AUTHOR |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Rocco Caputo <rcaputo@cpan.org> |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
This software is copyright (c) 2017 by Rocco Caputo. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
218
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 AVAILABILITY |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
The latest version of this module is available from the Comprehensive Perl |
223
|
|
|
|
|
|
|
Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN |
224
|
|
|
|
|
|
|
site near you, or see L<https://metacpan.org/module/Reflex/>. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
229
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT |
230
|
|
|
|
|
|
|
WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER |
231
|
|
|
|
|
|
|
PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, |
232
|
|
|
|
|
|
|
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE |
233
|
|
|
|
|
|
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
234
|
|
|
|
|
|
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE |
235
|
|
|
|
|
|
|
SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME |
236
|
|
|
|
|
|
|
THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
239
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
240
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE |
241
|
|
|
|
|
|
|
TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR |
242
|
|
|
|
|
|
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE |
243
|
|
|
|
|
|
|
SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
244
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
245
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
246
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
247
|
|
|
|
|
|
|
DAMAGES. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
=cut |