| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package ZMQ::Raw::Loop::Timer; |
|
2
|
|
|
|
|
|
|
$ZMQ::Raw::Loop::Timer::VERSION = '0.39'; |
|
3
|
14
|
|
|
14
|
|
92
|
use strict; |
|
|
14
|
|
|
|
|
26
|
|
|
|
14
|
|
|
|
|
501
|
|
|
4
|
14
|
|
|
14
|
|
86
|
use warnings; |
|
|
14
|
|
|
|
|
36
|
|
|
|
14
|
|
|
|
|
435
|
|
|
5
|
14
|
|
|
14
|
|
98
|
use Scalar::Util qw/weaken/; |
|
|
14
|
|
|
|
|
27
|
|
|
|
14
|
|
|
|
|
665
|
|
|
6
|
14
|
|
|
14
|
|
80
|
use Carp; |
|
|
14
|
|
|
|
|
29
|
|
|
|
14
|
|
|
|
|
1459
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
|
0
|
sub CLONE_SKIP { 1 } |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @attributes; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN |
|
13
|
|
|
|
|
|
|
{ |
|
14
|
14
|
|
|
14
|
|
85
|
@attributes = qw/ |
|
15
|
|
|
|
|
|
|
timer |
|
16
|
|
|
|
|
|
|
on_cancel |
|
17
|
|
|
|
|
|
|
on_timeout |
|
18
|
|
|
|
|
|
|
/; |
|
19
|
|
|
|
|
|
|
|
|
20
|
14
|
|
|
14
|
|
104
|
no strict 'refs'; |
|
|
14
|
|
|
|
|
35
|
|
|
|
14
|
|
|
|
|
1345
|
|
|
21
|
14
|
|
|
|
|
43
|
foreach my $accessor (@attributes) |
|
22
|
|
|
|
|
|
|
{ |
|
23
|
42
|
|
|
|
|
465
|
*{$accessor} = sub |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
456
|
50
|
|
456
|
|
4026
|
@_ > 1 ? $_[0]->{$accessor} = $_[1] : $_[0]->{$accessor} |
|
26
|
42
|
|
|
|
|
143
|
}; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
14
|
|
|
14
|
|
91
|
use ZMQ::Raw; |
|
|
14
|
|
|
|
|
29
|
|
|
|
14
|
|
|
|
|
6620
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
ZMQ::Raw::Loop::Timer - Timer class |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 VERSION |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
version 0.39 |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
A L represents a timer, usable in a |
|
43
|
|
|
|
|
|
|
L. |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
B: The API of this module is unstable and may change without warning |
|
46
|
|
|
|
|
|
|
(any change will be appropriately documented in the changelog). |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use ZMQ::Raw; |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $context = ZMQ::Raw::Context->new; |
|
53
|
|
|
|
|
|
|
my $loop = ZMQ::Raw::Loop->new ($context); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $timer = ZMQ::Raw::Loop::Timer->new |
|
56
|
|
|
|
|
|
|
( |
|
57
|
|
|
|
|
|
|
timer => ZMQ::Raw::Timer->new ($context, after => 100), |
|
58
|
|
|
|
|
|
|
on_timeout => sub |
|
59
|
|
|
|
|
|
|
{ |
|
60
|
|
|
|
|
|
|
print "Timed out!\n"; |
|
61
|
|
|
|
|
|
|
$loop->terminate(); |
|
62
|
|
|
|
|
|
|
}, |
|
63
|
|
|
|
|
|
|
on_cancel => sub |
|
64
|
|
|
|
|
|
|
{ |
|
65
|
|
|
|
|
|
|
print "Cancelled!\n"; |
|
66
|
|
|
|
|
|
|
}, |
|
67
|
|
|
|
|
|
|
); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$loop->add ($timer); |
|
70
|
|
|
|
|
|
|
$loop->run; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 METHODS |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 new( ) |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Create a new loop timer. |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 cancel( ) |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Cancel the underlying timer. |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 reset( ) |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Reset the underlying timer. |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 expire( ) |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Expire the underlying timer. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 running( ) |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Check if the timer is running. |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub new |
|
97
|
|
|
|
|
|
|
{ |
|
98
|
13
|
|
|
13
|
1
|
89
|
my ($this, %args) = @_; |
|
99
|
|
|
|
|
|
|
|
|
100
|
13
|
50
|
33
|
|
|
117
|
if (!$args{timer} || ref ($args{timer}) ne 'ZMQ::Raw::Timer') |
|
101
|
|
|
|
|
|
|
{ |
|
102
|
0
|
|
|
|
|
0
|
croak "timer not provided or not a 'ZMQ::Raw::Timer'"; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
13
|
50
|
33
|
|
|
78
|
if (!$args{on_timeout} || ref ($args{on_timeout}) ne 'CODE') |
|
106
|
|
|
|
|
|
|
{ |
|
107
|
0
|
|
|
|
|
0
|
croak "on_timeout not a code ref"; |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
13
|
50
|
66
|
|
|
72
|
if ($args{on_cancel} && ref ($args{on_cancel}) ne 'CODE') |
|
111
|
|
|
|
|
|
|
{ |
|
112
|
0
|
|
|
|
|
0
|
croak "on_cancel not a code ref"; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
13
|
|
33
|
|
|
53
|
my $class = ref ($this) || $this; |
|
116
|
|
|
|
|
|
|
my $self = |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
|
|
|
|
|
|
timer => $args{timer}, |
|
119
|
|
|
|
|
|
|
on_timeout => $args{on_timeout}, |
|
120
|
|
|
|
|
|
|
on_cancel => $args{on_cancel}, |
|
121
|
13
|
|
|
|
|
57
|
}; |
|
122
|
|
|
|
|
|
|
|
|
123
|
13
|
|
|
|
|
146
|
return bless $self, $class; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub loop |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
159
|
|
|
159
|
0
|
364
|
my ($this, $loop) = @_; |
|
131
|
|
|
|
|
|
|
|
|
132
|
159
|
100
|
|
|
|
385
|
if (scalar (@_) > 1) |
|
133
|
|
|
|
|
|
|
{ |
|
134
|
76
|
|
|
|
|
214
|
$this->{loop} = $loop; |
|
135
|
76
|
|
|
|
|
383
|
weaken ($this->{loop}); |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
159
|
|
|
|
|
530
|
return $this->{loop}; |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub cancel |
|
144
|
|
|
|
|
|
|
{ |
|
145
|
7
|
|
|
7
|
1
|
31
|
my ($this) = @_; |
|
146
|
|
|
|
|
|
|
|
|
147
|
7
|
|
|
|
|
22
|
$this->timer->cancel; |
|
148
|
|
|
|
|
|
|
|
|
149
|
7
|
50
|
|
|
|
43
|
if ($this->loop) |
|
150
|
|
|
|
|
|
|
{ |
|
151
|
7
|
|
|
|
|
19
|
$this->loop->remove ($this); |
|
152
|
|
|
|
|
|
|
|
|
153
|
7
|
100
|
|
|
|
30
|
if ($this->on_cancel) |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
1
|
|
|
|
|
5
|
&{$this->on_cancel}(); |
|
|
1
|
|
|
|
|
5
|
|
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub reset |
|
163
|
|
|
|
|
|
|
{ |
|
164
|
23
|
|
|
23
|
1
|
1118
|
my ($this) = @_; |
|
165
|
|
|
|
|
|
|
|
|
166
|
23
|
|
|
|
|
75
|
$this->timer->reset; |
|
167
|
|
|
|
|
|
|
|
|
168
|
23
|
50
|
|
|
|
160
|
if ($this->loop) |
|
169
|
|
|
|
|
|
|
{ |
|
170
|
23
|
|
|
|
|
68
|
$this->loop->remove ($this); |
|
171
|
23
|
|
|
|
|
83
|
$this->loop->add ($this); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
} |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub expire |
|
178
|
|
|
|
|
|
|
{ |
|
179
|
1
|
|
|
1
|
1
|
10
|
my ($this) = @_; |
|
180
|
|
|
|
|
|
|
|
|
181
|
1
|
|
|
|
|
5
|
$this->timer->expire; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub running |
|
187
|
|
|
|
|
|
|
{ |
|
188
|
76
|
|
|
76
|
1
|
270
|
my ($this) = @_; |
|
189
|
|
|
|
|
|
|
|
|
190
|
76
|
|
|
|
|
195
|
return $this->timer->running; |
|
191
|
|
|
|
|
|
|
} |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=for Pod::Coverage timer loop on_cancel on_timeout |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 AUTHOR |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Jacques Germishuys |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Copyright 2017 Jacques Germishuys. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
204
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
205
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; # End of ZMQ::Raw::Loop::Timer |