line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZMQ::Raw::Loop::Timer; |
2
|
|
|
|
|
|
|
$ZMQ::Raw::Loop::Timer::VERSION = '0.38'; |
3
|
14
|
|
|
14
|
|
110
|
use strict; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
533
|
|
4
|
14
|
|
|
14
|
|
87
|
use warnings; |
|
14
|
|
|
|
|
27
|
|
|
14
|
|
|
|
|
457
|
|
5
|
14
|
|
|
14
|
|
79
|
use Scalar::Util qw/weaken/; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
622
|
|
6
|
14
|
|
|
14
|
|
79
|
use Carp; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
1483
|
|
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
|
0
|
sub CLONE_SKIP { 1 } |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @attributes; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN |
13
|
|
|
|
|
|
|
{ |
14
|
14
|
|
|
14
|
|
69
|
@attributes = qw/ |
15
|
|
|
|
|
|
|
timer |
16
|
|
|
|
|
|
|
on_cancel |
17
|
|
|
|
|
|
|
on_timeout |
18
|
|
|
|
|
|
|
/; |
19
|
|
|
|
|
|
|
|
20
|
14
|
|
|
14
|
|
99
|
no strict 'refs'; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
1344
|
|
21
|
14
|
|
|
|
|
69
|
foreach my $accessor (@attributes) |
22
|
|
|
|
|
|
|
{ |
23
|
42
|
|
|
|
|
509
|
*{$accessor} = sub |
24
|
|
|
|
|
|
|
{ |
25
|
456
|
50
|
|
456
|
|
4244
|
@_ > 1 ? $_[0]->{$accessor} = $_[1] : $_[0]->{$accessor} |
26
|
42
|
|
|
|
|
164
|
}; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
14
|
|
|
14
|
|
92
|
use ZMQ::Raw; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
6852
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 NAME |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
ZMQ::Raw::Loop::Timer - Timer class |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 VERSION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
version 0.38 |
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
|
93
|
my ($this, %args) = @_; |
99
|
|
|
|
|
|
|
|
100
|
13
|
50
|
33
|
|
|
121
|
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
|
|
|
74
|
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
|
|
|
68
|
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
|
|
|
51
|
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
|
|
|
|
|
65
|
}; |
122
|
|
|
|
|
|
|
|
123
|
13
|
|
|
|
|
177
|
return bless $self, $class; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub loop |
129
|
|
|
|
|
|
|
{ |
130
|
159
|
|
|
159
|
0
|
355
|
my ($this, $loop) = @_; |
131
|
|
|
|
|
|
|
|
132
|
159
|
100
|
|
|
|
527
|
if (scalar (@_) > 1) |
133
|
|
|
|
|
|
|
{ |
134
|
76
|
|
|
|
|
194
|
$this->{loop} = $loop; |
135
|
76
|
|
|
|
|
299
|
weaken ($this->{loop}); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
159
|
|
|
|
|
475
|
return $this->{loop}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub cancel |
144
|
|
|
|
|
|
|
{ |
145
|
7
|
|
|
7
|
1
|
33
|
my ($this) = @_; |
146
|
|
|
|
|
|
|
|
147
|
7
|
|
|
|
|
20
|
$this->timer->cancel; |
148
|
|
|
|
|
|
|
|
149
|
7
|
50
|
|
|
|
52
|
if ($this->loop) |
150
|
|
|
|
|
|
|
{ |
151
|
7
|
|
|
|
|
50
|
$this->loop->remove ($this); |
152
|
|
|
|
|
|
|
|
153
|
7
|
100
|
|
|
|
27
|
if ($this->on_cancel) |
154
|
|
|
|
|
|
|
{ |
155
|
1
|
|
|
|
|
4
|
&{$this->on_cancel}(); |
|
1
|
|
|
|
|
5
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub reset |
163
|
|
|
|
|
|
|
{ |
164
|
23
|
|
|
23
|
1
|
1129
|
my ($this) = @_; |
165
|
|
|
|
|
|
|
|
166
|
23
|
|
|
|
|
69
|
$this->timer->reset; |
167
|
|
|
|
|
|
|
|
168
|
23
|
50
|
|
|
|
154
|
if ($this->loop) |
169
|
|
|
|
|
|
|
{ |
170
|
23
|
|
|
|
|
62
|
$this->loop->remove ($this); |
171
|
23
|
|
|
|
|
69
|
$this->loop->add ($this); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub expire |
178
|
|
|
|
|
|
|
{ |
179
|
1
|
|
|
1
|
1
|
7
|
my ($this) = @_; |
180
|
|
|
|
|
|
|
|
181
|
1
|
|
|
|
|
4
|
$this->timer->expire; |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub running |
187
|
|
|
|
|
|
|
{ |
188
|
76
|
|
|
76
|
1
|
206
|
my ($this) = @_; |
189
|
|
|
|
|
|
|
|
190
|
76
|
|
|
|
|
171
|
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 |