line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ZMQ::Raw::Loop::Event; |
2
|
|
|
|
|
|
|
$ZMQ::Raw::Loop::Event::VERSION = '0.38'; |
3
|
14
|
|
|
14
|
|
93
|
use strict; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
391
|
|
4
|
14
|
|
|
14
|
|
66
|
use warnings; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
344
|
|
5
|
14
|
|
|
14
|
|
65
|
use Carp; |
|
14
|
|
|
|
|
21
|
|
|
14
|
|
|
|
|
705
|
|
6
|
14
|
|
|
14
|
|
75
|
use Scalar::Util qw/weaken/; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
1258
|
|
7
|
|
|
|
|
|
|
|
8
|
0
|
|
|
0
|
|
0
|
sub CLONE_SKIP { 1 } |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @attributes; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN |
13
|
|
|
|
|
|
|
{ |
14
|
14
|
|
|
14
|
|
69
|
@attributes = qw/ |
15
|
|
|
|
|
|
|
read_handle |
16
|
|
|
|
|
|
|
write_handle |
17
|
|
|
|
|
|
|
timeout |
18
|
|
|
|
|
|
|
timer |
19
|
|
|
|
|
|
|
on_set |
20
|
|
|
|
|
|
|
on_timeout |
21
|
|
|
|
|
|
|
/; |
22
|
|
|
|
|
|
|
|
23
|
14
|
|
|
14
|
|
104
|
no strict 'refs'; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
1402
|
|
24
|
14
|
|
|
|
|
36
|
foreach my $accessor (@attributes) |
25
|
|
|
|
|
|
|
{ |
26
|
84
|
|
|
|
|
722
|
*{$accessor} = sub |
27
|
|
|
|
|
|
|
{ |
28
|
264
|
100
|
|
264
|
|
2501
|
@_ > 1 ? $_[0]->{$accessor} = $_[1] : $_[0]->{$accessor} |
|
|
|
|
264
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
|
264
|
|
|
|
29
|
84
|
|
|
|
|
424
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
14
|
|
|
14
|
|
97
|
use ZMQ::Raw; |
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
5648
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 NAME |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
ZMQ::Raw::Loop::Event - Event class |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 VERSION |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
version 0.38 |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
A L represents an event, usable in a |
46
|
|
|
|
|
|
|
L. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
B: The API of this module is unstable and may change without warning |
49
|
|
|
|
|
|
|
(any change will be appropriately documented in the changelog). |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
use ZMQ::Raw; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my $event = ZMQ::Raw::Loop::Event->new |
56
|
|
|
|
|
|
|
( |
57
|
|
|
|
|
|
|
$ctx, |
58
|
|
|
|
|
|
|
on_set => sub |
59
|
|
|
|
|
|
|
{ |
60
|
|
|
|
|
|
|
print "Event set!\n"; |
61
|
|
|
|
|
|
|
}, |
62
|
|
|
|
|
|
|
timeout => 10000, |
63
|
|
|
|
|
|
|
on_timeout => |
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
print "Event timed out\n"; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
my $timer = ZMQ::Raw::Loop::Timer->new |
70
|
|
|
|
|
|
|
( |
71
|
|
|
|
|
|
|
timer => ZMQ::Raw::Timer->new ($ctx, after => 100), |
72
|
|
|
|
|
|
|
on_timeout => sub |
73
|
|
|
|
|
|
|
{ |
74
|
|
|
|
|
|
|
$event->set; |
75
|
|
|
|
|
|
|
}, |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $loop = ZMQ::Raw::Loop->new; |
79
|
|
|
|
|
|
|
$loop->add ($event); |
80
|
|
|
|
|
|
|
$loop->run; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 METHODS |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 new( $context, %args ) |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Create a new loop event |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 set( ) |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Set the event |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 reset( ) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Reset the event |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
our $id = 0; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub new |
101
|
|
|
|
|
|
|
{ |
102
|
10
|
|
|
10
|
1
|
3508
|
my ($this, $context, %args) = @_; |
103
|
|
|
|
|
|
|
|
104
|
10
|
100
|
66
|
|
|
62
|
if (!defined ($context) || ref ($context) ne 'ZMQ::Raw::Context') |
105
|
|
|
|
|
|
|
{ |
106
|
1
|
|
|
|
|
183
|
croak "context not set or not a 'ZMQ::Raw::Context'"; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
9
|
100
|
66
|
|
|
45
|
if (!$args{on_set} || ref ($args{on_set}) ne 'CODE') |
110
|
|
|
|
|
|
|
{ |
111
|
1
|
|
|
|
|
111
|
croak "on_set not set or not a code ref"; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
8
|
100
|
100
|
|
|
35
|
if ($args{on_timeout} && ref ($args{on_timeout}) ne 'CODE') |
115
|
|
|
|
|
|
|
{ |
116
|
1
|
|
|
|
|
85
|
croak "on_timeout not a code ref"; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
7
|
100
|
100
|
|
|
25
|
if ($args{on_timeout} && !exists ($args{timeout})) |
120
|
|
|
|
|
|
|
{ |
121
|
1
|
|
|
|
|
83
|
croak "on_timeout provided but timeout not set"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
6
|
|
|
|
|
25
|
my $endpoint = "inproc://_loop_event-".(++$id); |
125
|
6
|
|
|
|
|
44
|
my $read = ZMQ::Raw::Socket->new ($context, ZMQ::Raw->ZMQ_PAIR); |
126
|
6
|
|
|
|
|
196
|
$read->bind ($endpoint); |
127
|
|
|
|
|
|
|
|
128
|
6
|
|
|
|
|
34
|
my $write = ZMQ::Raw::Socket->new ($context, ZMQ::Raw->ZMQ_PAIR); |
129
|
6
|
|
|
|
|
289
|
$write->connect ($endpoint); |
130
|
|
|
|
|
|
|
|
131
|
6
|
|
33
|
|
|
45
|
my $class = ref ($this) || $this; |
132
|
|
|
|
|
|
|
my $self = |
133
|
|
|
|
|
|
|
{ |
134
|
|
|
|
|
|
|
read_handle => $read, |
135
|
|
|
|
|
|
|
write_handle => $write, |
136
|
|
|
|
|
|
|
timeout => $args{timeout}, |
137
|
|
|
|
|
|
|
on_set => $args{on_set}, |
138
|
|
|
|
|
|
|
on_timeout => $args{on_timeout}, |
139
|
6
|
|
|
|
|
32
|
}; |
140
|
|
|
|
|
|
|
|
141
|
6
|
|
|
|
|
36
|
return bless $self, $class; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub set |
147
|
|
|
|
|
|
|
{ |
148
|
15
|
|
|
15
|
1
|
59
|
my ($this) = @_; |
149
|
|
|
|
|
|
|
|
150
|
15
|
|
|
|
|
60
|
$this->write_handle->send ('', ZMQ::Raw->ZMQ_DONTWAIT); |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub reset |
156
|
|
|
|
|
|
|
{ |
157
|
21
|
|
|
21
|
1
|
68
|
my ($this) = @_; |
158
|
|
|
|
|
|
|
|
159
|
35
|
100
|
|
|
|
117
|
AGAIN: |
160
|
|
|
|
|
|
|
goto AGAIN if (defined ($this->read_handle->recv (ZMQ::Raw->ZMQ_DONTWAIT))); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=for Pod::Coverage read_handle write_handle timeout timer on_set on_timeout |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 AUTHOR |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Jacques Germishuys |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Copyright 2017 Jacques Germishuys. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
174
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
175
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; # End of ZMQ::Raw::Loop::Event |