line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2010-2021 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
9
|
|
|
9
|
|
103
|
use v5.26; |
|
9
|
|
|
|
|
28
|
|
7
|
9
|
|
|
9
|
|
49
|
use Object::Pad 0.41; |
|
9
|
|
|
|
|
110
|
|
|
9
|
|
|
|
|
47
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Tangence::ObjectProxy 0.28; |
10
|
|
|
|
|
|
|
class Tangence::ObjectProxy; |
11
|
|
|
|
|
|
|
|
12
|
9
|
|
|
9
|
|
2878
|
use Carp; |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
562
|
|
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
9
|
|
55
|
use Syntax::Keyword::Match 0.06; |
|
9
|
|
|
|
|
151
|
|
|
9
|
|
|
|
|
61
|
|
15
|
|
|
|
|
|
|
|
16
|
9
|
|
|
9
|
|
979
|
use Future::AsyncAwait; |
|
9
|
|
|
|
|
12732
|
|
|
9
|
|
|
|
|
65
|
|
17
|
9
|
|
|
9
|
|
482
|
use Future::Exception; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
306
|
|
18
|
|
|
|
|
|
|
|
19
|
9
|
|
|
9
|
|
54
|
use Tangence::Constants; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
1409
|
|
20
|
|
|
|
|
|
|
|
21
|
9
|
|
|
9
|
|
58
|
use Tangence::Types; |
|
9
|
|
|
|
|
14
|
|
|
9
|
|
|
|
|
597
|
|
22
|
|
|
|
|
|
|
|
23
|
9
|
|
|
9
|
|
54
|
use Scalar::Util qw( weaken ); |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
3376
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 NAME |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
C - proxy for a C object in a |
28
|
|
|
|
|
|
|
C |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Instances in this class act as a proxy for an object in the |
33
|
|
|
|
|
|
|
L, allowing methods to be called, events to be subscribed |
34
|
|
|
|
|
|
|
to, and properties to be watched. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
These objects are not directly constructed by calling the C class method; |
37
|
|
|
|
|
|
|
instead they are returned by methods on L, or by methods on |
38
|
|
|
|
|
|
|
other C instances. Ultimately every object proxy that a |
39
|
|
|
|
|
|
|
client uses will come from either the proxy to the registry, or the root |
40
|
|
|
|
|
|
|
object. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
19
|
|
|
19
|
0
|
38
|
has $_client :param :weak :reader; |
|
19
|
|
|
|
|
51
|
|
45
|
56
|
|
|
56
|
1
|
122
|
has $_id :param :reader; |
|
56
|
|
|
|
|
256
|
|
46
|
0
|
|
|
0
|
1
|
0
|
has $_class :param :reader; |
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has $_destroyed; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has %_subscriptions; |
51
|
|
|
|
|
|
|
has %_props; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
method destroy |
54
|
2
|
|
|
2
|
0
|
6
|
{ |
55
|
2
|
|
|
|
|
3
|
$_destroyed = 1; |
56
|
|
|
|
|
|
|
|
57
|
2
|
|
|
|
|
5
|
foreach my $cb ( @{ $_subscriptions{destroy} } ) { |
|
2
|
|
|
|
|
6
|
|
58
|
2
|
|
|
|
|
8
|
$cb->(); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The following methods documented in an C expression return L |
65
|
|
|
|
|
|
|
instances. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
9
|
|
|
9
|
|
64
|
use overload '""' => \&STRING; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
79
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
method STRING |
72
|
114
|
|
|
114
|
0
|
226
|
{ |
73
|
114
|
|
|
|
|
458
|
return "Tangence::ObjectProxy[id=$_id]"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 id |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
$id = $proxy->id |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Returns the object ID for the C object being proxied for. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# generated accessor |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 classname |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$classname = $proxy->classname |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns the name of the class of the C object being proxied for. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
method classname |
95
|
6
|
|
|
6
|
1
|
14
|
{ |
96
|
6
|
|
|
|
|
18
|
return $_class->name; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 class |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$class = $proxyobj->class |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Returns the L object representing the class of this |
104
|
|
|
|
|
|
|
object. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# generated accessor |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 can_method |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$method = $proxy->can_method( $name ) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the L object representing the named method, or |
115
|
|
|
|
|
|
|
C if no such method exists. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
method can_method |
120
|
8
|
|
|
8
|
1
|
28
|
{ |
121
|
8
|
|
|
|
|
38
|
return $_class->method( @_ ); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head2 can_event |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
$event = $proxy->can_event( $name ) |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns the L object representing the named event, or |
129
|
|
|
|
|
|
|
C if no such event exists. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=cut |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
method can_event |
134
|
13
|
|
|
13
|
1
|
723
|
{ |
135
|
13
|
|
|
|
|
48
|
return $_class->event( @_ ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head2 can_property |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
$property = $proxy->can_property( $name ) |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns the L object representing the named |
143
|
|
|
|
|
|
|
property, or C if no such property exists. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
method can_property |
148
|
118
|
|
|
118
|
1
|
976
|
{ |
149
|
118
|
|
|
|
|
409
|
return $_class->property( @_ ); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Don't want to call it "isa" |
153
|
|
|
|
|
|
|
method proxy_isa |
154
|
0
|
|
|
0
|
0
|
0
|
{ |
155
|
0
|
0
|
|
|
|
0
|
if( @_ ) { |
156
|
0
|
|
|
|
|
0
|
my ( $class ) = @_; |
157
|
0
|
|
|
|
|
0
|
return !! grep { $_->name eq $class } $_class, $_class->superclasses; |
|
0
|
|
|
|
|
0
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
else { |
160
|
0
|
|
|
|
|
0
|
return $_class, $_class->superclasses |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
10
|
|
|
|
|
16
|
method grab ( $smashdata ) |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
12
|
|
165
|
10
|
|
|
10
|
0
|
26
|
{ |
166
|
10
|
|
|
|
|
20
|
foreach my $property ( keys %{ $smashdata } ) { |
|
10
|
|
|
|
|
50
|
|
167
|
20
|
|
|
|
|
56
|
my $value = $smashdata->{$property}; |
168
|
20
|
|
|
|
|
65
|
my $dim = $self->can_property( $property )->dimension; |
169
|
|
|
|
|
|
|
|
170
|
20
|
50
|
|
|
|
56
|
if( $dim == DIM_OBJSET ) { |
171
|
|
|
|
|
|
|
# Comes across in a LIST. We need to map id => obj |
172
|
0
|
|
|
|
|
0
|
$value = { map { $_->id => $_ } @$value }; |
|
0
|
|
|
|
|
0
|
|
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
20
|
|
50
|
|
|
91
|
my $prop = $_props{$property} ||= {}; |
176
|
20
|
|
|
|
|
70
|
$prop->{cache} = $value; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 call_method |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
$result = await $proxy->call_method( $mname, @args ) |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Calls the given method on the server object, passing in the given arguments. |
185
|
|
|
|
|
|
|
Returns a L that will yield the method's result. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
6
|
|
|
|
|
10
|
async method call_method ( $method, @args ) |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
9
|
|
190
|
6
|
|
|
|
|
20
|
{ |
191
|
|
|
|
|
|
|
# Detect void-context legacy uses |
192
|
|
|
|
|
|
|
defined wantarray or |
193
|
6
|
50
|
|
|
|
18
|
croak "->call_method in void context no longer useful - it now returns a Future"; |
194
|
|
|
|
|
|
|
|
195
|
6
|
100
|
|
|
|
17
|
my $mdef = $self->can_method( $method ) |
196
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a method $method"; |
197
|
|
|
|
|
|
|
|
198
|
4
|
|
|
|
|
32
|
my $request = Tangence::Message->new( $_client, MSG_CALL ) |
199
|
|
|
|
|
|
|
->pack_int( $self->id ) |
200
|
|
|
|
|
|
|
->pack_str( $method ); |
201
|
|
|
|
|
|
|
|
202
|
4
|
|
|
|
|
20
|
my @argtypes = $mdef->argtypes; |
203
|
4
|
|
|
|
|
18
|
$argtypes[$_]->pack_value( $request, $args[$_] ) for 0..$#argtypes; |
204
|
|
|
|
|
|
|
|
205
|
4
|
|
|
|
|
19
|
my $message = await $_client->request( request => $request ); |
206
|
|
|
|
|
|
|
|
207
|
3
|
|
|
|
|
169
|
my $code = $message->code; |
208
|
|
|
|
|
|
|
|
209
|
3
|
50
|
|
|
|
23
|
if( $code == MSG_RESULT ) { |
210
|
3
|
100
|
|
|
|
13
|
my $result = $mdef->ret ? $mdef->ret->unpack_value( $message ) |
211
|
|
|
|
|
|
|
: undef; |
212
|
3
|
|
|
|
|
72
|
return $result; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
else { |
215
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
216
|
|
|
|
|
|
|
} |
217
|
6
|
|
|
6
|
1
|
1937
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head2 subscribe_event |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
await $proxy->subscribe_event( $event, %callbacks ) |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Subscribes to the given event on the server object, installing a callback |
224
|
|
|
|
|
|
|
function which will be invoked whenever the event is fired. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
Takes the following named callbacks: |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=over 8 |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=item on_fire => CODE |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Callback function to invoke whenever the event is fired |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
$on_fire->( @args ) |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
The returned C it is guaranteed to be completed before any invocation |
237
|
|
|
|
|
|
|
of the C event handler. |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=back |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=cut |
242
|
|
|
|
|
|
|
|
243
|
7
|
|
|
|
|
11
|
async method subscribe_event ( $event, %args ) |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
10
|
|
244
|
7
|
|
|
|
|
28
|
{ |
245
|
|
|
|
|
|
|
# Detect void-context legacy uses |
246
|
|
|
|
|
|
|
defined wantarray or |
247
|
7
|
50
|
|
|
|
24
|
croak "->subscribe_event in void context no longer useful - it now returns a Future"; |
248
|
|
|
|
|
|
|
|
249
|
7
|
50
|
|
|
|
31
|
ref( my $callback = delete $args{on_fire} ) eq "CODE" |
250
|
|
|
|
|
|
|
or croak "Expected 'on_fire' as a CODE ref"; |
251
|
|
|
|
|
|
|
|
252
|
7
|
100
|
|
|
|
19
|
$self->can_event( $event ) |
253
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have an event $event"; |
254
|
|
|
|
|
|
|
|
255
|
5
|
50
|
|
|
|
20
|
if( my $cbs = $_subscriptions{$event} ) { |
256
|
0
|
|
|
|
|
0
|
push @$cbs, $callback; |
257
|
0
|
|
|
|
|
0
|
return; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
5
|
|
|
|
|
12
|
my @cbs = ( $callback ); |
261
|
5
|
|
|
|
|
12
|
$_subscriptions{$event} = \@cbs; |
262
|
|
|
|
|
|
|
|
263
|
5
|
100
|
|
|
|
30
|
return if $event eq "destroy"; # This is automatically handled |
264
|
|
|
|
|
|
|
|
265
|
3
|
|
|
|
|
24
|
my $message = await $_client->request( |
266
|
|
|
|
|
|
|
request => Tangence::Message->new( $_client, MSG_SUBSCRIBE ) |
267
|
|
|
|
|
|
|
->pack_int( $self->id ) |
268
|
|
|
|
|
|
|
->pack_str( $event ) |
269
|
|
|
|
|
|
|
); |
270
|
|
|
|
|
|
|
|
271
|
2
|
|
|
|
|
98
|
my $code = $message->code; |
272
|
|
|
|
|
|
|
|
273
|
2
|
50
|
|
|
|
7
|
if( $code == MSG_SUBSCRIBED ) { |
274
|
2
|
|
|
|
|
14
|
return; |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
else { |
277
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
278
|
|
|
|
|
|
|
} |
279
|
7
|
|
|
7
|
1
|
2739
|
} |
280
|
|
|
|
|
|
|
|
281
|
2
|
|
|
|
|
4
|
method handle_request_EVENT ( $message ) |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
3
|
|
282
|
2
|
|
|
2
|
0
|
6
|
{ |
283
|
2
|
|
|
|
|
9
|
my $event = $message->unpack_str(); |
284
|
2
|
50
|
|
|
|
62
|
my $edef = $self->can_event( $event ) or return; |
285
|
|
|
|
|
|
|
|
286
|
2
|
|
|
|
|
10
|
my @args = map { $_->unpack_value( $message ) } $edef->argtypes; |
|
4
|
|
|
|
|
12
|
|
287
|
|
|
|
|
|
|
|
288
|
2
|
50
|
|
|
|
50
|
if( my $cbs = $_subscriptions{$event} ) { |
289
|
2
|
|
|
|
|
9
|
foreach my $cb ( @$cbs ) { $cb->( @args ) } |
|
2
|
|
|
|
|
7
|
|
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=head2 unsubscribe_event |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
$proxy->unsubscribe_event( $event ) |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Removes an event subscription on the given event on the server object that was |
298
|
|
|
|
|
|
|
previously installed using C. |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
=cut |
301
|
|
|
|
|
|
|
|
302
|
2
|
|
|
|
|
3
|
method unsubscribe_event ( $event ) |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
4
|
|
303
|
2
|
|
|
2
|
1
|
1123
|
{ |
304
|
2
|
50
|
|
|
|
6
|
$self->can_event( $event ) |
305
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have an event $event"; |
306
|
|
|
|
|
|
|
|
307
|
2
|
50
|
|
|
|
7
|
return if $event eq "destroy"; # This is automatically handled |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
$_client->request( |
310
|
|
|
|
|
|
|
request => Tangence::Message->new( $_client, MSG_UNSUBSCRIBE ) |
311
|
|
|
|
|
|
|
->pack_int( $self->id ) |
312
|
|
|
|
|
|
|
->pack_str( $event ), |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
2
|
|
|
on_response => sub {}, |
315
|
2
|
|
|
|
|
14
|
); |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
=head2 get_property |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
await $value = $proxy->get_property( $prop ) |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
Requests the current value of the property from the server object. |
323
|
|
|
|
|
|
|
|
324
|
|
|
|
|
|
|
=cut |
325
|
|
|
|
|
|
|
|
326
|
8
|
|
|
|
|
16
|
async method get_property ( $property ) |
|
8
|
|
|
|
|
27
|
|
|
8
|
|
|
|
|
13
|
|
327
|
8
|
|
|
|
|
22
|
{ |
328
|
|
|
|
|
|
|
# Detect void-context legacy uses |
329
|
|
|
|
|
|
|
defined wantarray or |
330
|
8
|
50
|
|
|
|
26
|
croak "->get_property in void context no longer useful - it now returns a Future"; |
331
|
|
|
|
|
|
|
|
332
|
8
|
100
|
|
|
|
22
|
my $pdef = $self->can_property( $property ) |
333
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a property $property"; |
334
|
|
|
|
|
|
|
|
335
|
6
|
|
|
|
|
53
|
my $message = await $_client->request( |
336
|
|
|
|
|
|
|
request => Tangence::Message->new( $_client, MSG_GETPROP ) |
337
|
|
|
|
|
|
|
->pack_int( $self->id ) |
338
|
|
|
|
|
|
|
->pack_str( $property ), |
339
|
|
|
|
|
|
|
); |
340
|
|
|
|
|
|
|
|
341
|
5
|
|
|
|
|
227
|
my $code = $message->code; |
342
|
|
|
|
|
|
|
|
343
|
5
|
50
|
|
|
|
18
|
if( $code == MSG_RESULT ) { |
344
|
5
|
|
|
|
|
21
|
return $pdef->overall_type->unpack_value( $message ); |
345
|
|
|
|
|
|
|
} |
346
|
|
|
|
|
|
|
else { |
347
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
348
|
|
|
|
|
|
|
} |
349
|
8
|
|
|
8
|
1
|
874
|
} |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head2 get_property_element |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
await $value = $proxy->get_property_element( $property, $index_or_key ) |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
Requests the current value of an element of the property from the server |
356
|
|
|
|
|
|
|
object. |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
=cut |
359
|
|
|
|
|
|
|
|
360
|
4
|
|
|
|
|
7
|
async method get_property_element ( $property, $index_or_key ) |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
7
|
|
361
|
4
|
|
|
|
|
12
|
{ |
362
|
|
|
|
|
|
|
# Detect void-context legacy uses |
363
|
|
|
|
|
|
|
defined wantarray or |
364
|
4
|
50
|
|
|
|
11
|
croak "->get_property_element in void context no longer useful - it now returns a Future"; |
365
|
|
|
|
|
|
|
|
366
|
4
|
50
|
|
|
|
11
|
my $pdef = $self->can_property( $property ) |
367
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a property $property"; |
368
|
|
|
|
|
|
|
|
369
|
4
|
|
|
|
|
25
|
my $request = Tangence::Message->new( $_client, MSG_GETPROPELEM ) |
370
|
|
|
|
|
|
|
->pack_int( $self->id ) |
371
|
|
|
|
|
|
|
->pack_str( $property ); |
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
match( $pdef->dimension : == ) { |
374
|
|
|
|
|
|
|
case( DIM_HASH ) { |
375
|
2
|
|
|
|
|
7
|
$request->pack_str( $index_or_key ); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
case( DIM_ARRAY ), case( DIM_QUEUE ) { |
378
|
2
|
|
|
|
|
9
|
$request->pack_int( $index_or_key ); |
379
|
|
|
|
|
|
|
} |
380
|
4
|
100
|
33
|
|
|
14
|
default { |
|
|
50
|
|
|
|
|
|
381
|
0
|
|
|
|
|
0
|
croak "Cannot get_property_element of a non hash, array or queue"; |
382
|
|
|
|
|
|
|
} |
383
|
|
|
|
|
|
|
} |
384
|
|
|
|
|
|
|
|
385
|
4
|
|
|
|
|
13
|
my $message = await $_client->request( |
386
|
|
|
|
|
|
|
request => $request, |
387
|
|
|
|
|
|
|
); |
388
|
|
|
|
|
|
|
|
389
|
4
|
|
|
|
|
160
|
my $code = $message->code; |
390
|
|
|
|
|
|
|
|
391
|
4
|
50
|
|
|
|
13
|
if( $code == MSG_RESULT ) { |
392
|
4
|
|
|
|
|
22
|
return $pdef->type->unpack_value( $message ); |
393
|
|
|
|
|
|
|
} |
394
|
|
|
|
|
|
|
else { |
395
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
396
|
|
|
|
|
|
|
} |
397
|
4
|
|
|
4
|
1
|
2771
|
} |
398
|
|
|
|
|
|
|
|
399
|
|
|
|
|
|
|
=head2 prop |
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
$value = $proxy->prop( $property ) |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
Returns the locally-cached value of a smashed property. If the named property |
404
|
|
|
|
|
|
|
is not a smashed property, an exception is thrown. |
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
=cut |
407
|
|
|
|
|
|
|
|
408
|
17
|
|
|
|
|
41
|
method prop ( $property ) |
|
17
|
|
|
|
|
30
|
|
|
17
|
|
|
|
|
23
|
|
409
|
17
|
|
|
17
|
1
|
1208
|
{ |
410
|
17
|
50
|
|
|
|
64
|
if( exists $_props{$property}->{cache} ) { |
411
|
17
|
|
|
|
|
115
|
return $_props{$property}->{cache}; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
|
414
|
0
|
|
|
|
|
0
|
croak "$self does not have a cached property '$property'"; |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
=head2 set_property |
418
|
|
|
|
|
|
|
|
419
|
|
|
|
|
|
|
await $proxy->set_property( $prop, $value ) |
420
|
|
|
|
|
|
|
|
421
|
|
|
|
|
|
|
Sets the value of the property in the server object. |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
=cut |
424
|
|
|
|
|
|
|
|
425
|
9
|
|
|
|
|
17
|
async method set_property ( $property, $value ) |
|
9
|
|
|
|
|
24
|
|
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
12
|
|
426
|
9
|
|
|
|
|
28
|
{ |
427
|
|
|
|
|
|
|
# Detect void-context legacy uses |
428
|
|
|
|
|
|
|
defined wantarray or |
429
|
9
|
50
|
|
|
|
28
|
croak "->set_property in void context no longer useful - it now returns a Future"; |
430
|
|
|
|
|
|
|
|
431
|
9
|
50
|
|
|
|
23
|
my $pdef = $self->can_property( $property ) |
432
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a property $property"; |
433
|
|
|
|
|
|
|
|
434
|
9
|
|
|
|
|
49
|
my $request = Tangence::Message->new( $_client, MSG_SETPROP ) |
435
|
|
|
|
|
|
|
->pack_int( $self->id ) |
436
|
|
|
|
|
|
|
->pack_str( $property ); |
437
|
9
|
|
|
|
|
79
|
$pdef->overall_type->pack_value( $request, $value ); |
438
|
|
|
|
|
|
|
|
439
|
9
|
|
|
|
|
31
|
my $message = await $_client->request( |
440
|
|
|
|
|
|
|
request => $request, |
441
|
|
|
|
|
|
|
); |
442
|
|
|
|
|
|
|
|
443
|
7
|
|
|
|
|
167
|
my $code = $message->code; |
444
|
|
|
|
|
|
|
|
445
|
7
|
50
|
|
|
|
19
|
if( $code == MSG_OK ) { |
446
|
7
|
|
|
|
|
43
|
return; |
447
|
|
|
|
|
|
|
} |
448
|
|
|
|
|
|
|
else { |
449
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
450
|
|
|
|
|
|
|
} |
451
|
9
|
|
|
9
|
1
|
4986
|
} |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
=head2 watch_property |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
await $proxy->watch_property( $property, %callbacks ) |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
=head2 watch_property_with_initial |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
await $proxy->watch_property_with_initial( $property, %callbacks ) |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
Watches the given property on the server object, installing callback functions |
462
|
|
|
|
|
|
|
which will be invoked whenever the property value changes. The latter form |
463
|
|
|
|
|
|
|
additionally ensures that the server will send the current value of the |
464
|
|
|
|
|
|
|
property as an initial update to the C event, atomically when it |
465
|
|
|
|
|
|
|
installs the update watches. |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
Takes the following named arguments: |
468
|
|
|
|
|
|
|
|
469
|
|
|
|
|
|
|
=over 8 |
470
|
|
|
|
|
|
|
|
471
|
|
|
|
|
|
|
=item on_updated => CODE |
472
|
|
|
|
|
|
|
|
473
|
|
|
|
|
|
|
Optional. Callback function to invoke whenever the property value changes. |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
$on_updated->( $new_value ) |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
If not provided, then individual handlers for individual change types must be |
478
|
|
|
|
|
|
|
provided. |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=back |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
The set of callback functions that are required depends on the type of the |
483
|
|
|
|
|
|
|
property. These are documented in the C method of |
484
|
|
|
|
|
|
|
L. |
485
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=cut |
487
|
|
|
|
|
|
|
|
488
|
24
|
|
|
|
|
45
|
sub _watchcbs_from_args ( $pdef, %args ) |
489
|
24
|
|
|
24
|
|
56
|
{ |
|
24
|
|
|
|
|
50
|
|
|
24
|
|
|
|
|
35
|
|
490
|
24
|
|
|
|
|
57
|
my $callbacks = {}; |
491
|
24
|
|
|
|
|
60
|
my $on_updated = delete $args{on_updated}; |
492
|
24
|
100
|
|
|
|
79
|
if( $on_updated ) { |
493
|
5
|
50
|
|
|
|
18
|
ref $on_updated eq "CODE" or croak "Expected 'on_updated' to be a CODE ref"; |
494
|
5
|
|
|
|
|
15
|
$callbacks->{on_updated} = $on_updated; |
495
|
|
|
|
|
|
|
} |
496
|
|
|
|
|
|
|
|
497
|
24
|
|
|
|
|
51
|
foreach my $name ( @{ CHANGETYPES->{$pdef->dimension} } ) { |
|
24
|
|
|
|
|
115
|
|
498
|
|
|
|
|
|
|
# All of these become optional if 'on_updated' is supplied |
499
|
52
|
100
|
66
|
|
|
152
|
next if $on_updated and not exists $args{$name}; |
500
|
|
|
|
|
|
|
|
501
|
37
|
50
|
|
|
|
141
|
ref( $callbacks->{$name} = delete $args{$name} ) eq "CODE" |
502
|
|
|
|
|
|
|
or croak "Expected '$name' as a CODE ref"; |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
|
505
|
24
|
|
|
|
|
61
|
return $callbacks; |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
|
508
|
5
|
|
|
5
|
1
|
1771
|
method watch_property { $self->_watch_property( shift, 0, @_ ) } |
|
5
|
|
|
|
|
25
|
|
509
|
13
|
|
|
13
|
1
|
8619
|
method watch_property_with_initial { $self->_watch_property( shift, 1, @_ ) } |
|
13
|
|
|
|
|
78
|
|
510
|
|
|
|
|
|
|
|
511
|
18
|
|
|
|
|
37
|
async method _watch_property ( $property, $want_initial, %args ) |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
77
|
|
|
18
|
|
|
|
|
62
|
|
|
18
|
|
|
|
|
24
|
|
512
|
18
|
|
|
|
|
57
|
{ |
513
|
|
|
|
|
|
|
# Detect void-context legacy uses |
514
|
|
|
|
|
|
|
defined wantarray or |
515
|
18
|
50
|
|
|
|
64
|
croak "->watch_property in void context no longer useful - it now returns a Future"; |
516
|
|
|
|
|
|
|
|
517
|
18
|
50
|
|
|
|
68
|
my $pdef = $self->can_property( $property ) |
518
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a property $property"; |
519
|
|
|
|
|
|
|
|
520
|
18
|
|
|
|
|
87
|
my $callbacks = _watchcbs_from_args( $pdef, %args ); |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
# Smashed properties behave differently |
523
|
18
|
|
|
|
|
92
|
my $smash = $pdef->smashed; |
524
|
|
|
|
|
|
|
|
525
|
18
|
100
|
|
|
|
90
|
if( my $cbs = $_props{$property}->{cbs} ) { |
526
|
3
|
50
|
33
|
|
|
21
|
if( $want_initial and !$smash ) { |
|
|
0
|
0
|
|
|
|
|
527
|
3
|
|
|
|
|
17
|
my $value = await $self->get_property( $property ); |
528
|
|
|
|
|
|
|
|
529
|
3
|
100
|
|
|
|
138
|
$callbacks->{on_set} and $callbacks->{on_set}->( $value ); |
530
|
3
|
100
|
|
|
|
19
|
$callbacks->{on_updated} and $callbacks->{on_updated}->( $value ); |
531
|
3
|
|
|
|
|
12
|
push @$cbs, $callbacks; |
532
|
3
|
|
|
|
|
15
|
return; |
533
|
|
|
|
|
|
|
} |
534
|
|
|
|
|
|
|
elsif( $want_initial and $smash ) { |
535
|
0
|
|
|
|
|
0
|
my $cache = $_props{$property}->{cache}; |
536
|
0
|
0
|
|
|
|
0
|
$callbacks->{on_set} and $callbacks->{on_set}->( $cache ); |
537
|
0
|
0
|
|
|
|
0
|
$callbacks->{on_updated} and $callbacks->{on_updated}->( $cache ); |
538
|
0
|
|
|
|
|
0
|
push @$cbs, $callbacks; |
539
|
0
|
|
|
|
|
0
|
return; |
540
|
|
|
|
|
|
|
} |
541
|
|
|
|
|
|
|
else { |
542
|
0
|
|
|
|
|
0
|
push @$cbs, $callbacks; |
543
|
0
|
|
|
|
|
0
|
return; |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
|
546
|
0
|
|
|
|
|
0
|
die "UNREACHED"; |
547
|
|
|
|
|
|
|
} |
548
|
|
|
|
|
|
|
|
549
|
15
|
|
|
|
|
57
|
$_props{$property}->{cbs} = [ $callbacks ]; |
550
|
|
|
|
|
|
|
|
551
|
15
|
100
|
|
|
|
48
|
if( $smash ) { |
552
|
2
|
50
|
|
|
|
7
|
if( $want_initial ) { |
553
|
2
|
|
|
|
|
6
|
my $cache = $_props{$property}->{cache}; |
554
|
2
|
50
|
|
|
|
12
|
$callbacks->{on_set} and $callbacks->{on_set}->( $cache ); |
555
|
2
|
50
|
|
|
|
8
|
$callbacks->{on_updated} and $callbacks->{on_updated}->( $cache ); |
556
|
|
|
|
|
|
|
} |
557
|
|
|
|
|
|
|
|
558
|
2
|
|
|
|
|
18
|
return; |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
13
|
|
|
|
|
100
|
my $request = Tangence::Message->new( $_client, MSG_WATCH ) |
562
|
|
|
|
|
|
|
->pack_int( $self->id ) |
563
|
|
|
|
|
|
|
->pack_str( $property ) |
564
|
|
|
|
|
|
|
->pack_bool( $want_initial ); |
565
|
|
|
|
|
|
|
|
566
|
13
|
|
|
|
|
62
|
my $message = await $_client->request( request => $request ); |
567
|
|
|
|
|
|
|
|
568
|
12
|
|
|
|
|
409
|
my $code = $message->code; |
569
|
|
|
|
|
|
|
|
570
|
12
|
50
|
|
|
|
48
|
if( $code == MSG_WATCHING ) { |
571
|
12
|
|
|
|
|
163
|
return; |
572
|
|
|
|
|
|
|
} |
573
|
|
|
|
|
|
|
else { |
574
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
575
|
|
|
|
|
|
|
} |
576
|
18
|
|
|
18
|
|
39
|
} |
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
=head2 watch_property_with_cursor |
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
( $cursor, $first_idx, $last_idx ) = |
581
|
|
|
|
|
|
|
await $proxy->watch_property_with_cursor( $property, $from, %callbacks ) |
582
|
|
|
|
|
|
|
|
583
|
|
|
|
|
|
|
A variant of C that installs a watch on the given property of |
584
|
|
|
|
|
|
|
the server object, and additionally returns an cursor object that can be used |
585
|
|
|
|
|
|
|
to lazily fetch the values stored in it. |
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
The C<$from> value indicates which end of the queue the cursor should start |
588
|
|
|
|
|
|
|
from; C to start at index 0, or C to start at the |
589
|
|
|
|
|
|
|
highest-numbered index. The cursor is created atomically with installing the |
590
|
|
|
|
|
|
|
watch. |
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
=cut |
593
|
|
|
|
|
|
|
|
594
|
|
|
|
|
|
|
method watch_property_with_iter |
595
|
0
|
|
|
0
|
0
|
0
|
{ |
596
|
|
|
|
|
|
|
# Detect void-context legacy uses |
597
|
|
|
|
|
|
|
defined wantarray or |
598
|
0
|
0
|
|
|
|
0
|
croak "->watch_property_with_iter in void context no longer useful - it now returns a Future"; |
599
|
|
|
|
|
|
|
|
600
|
0
|
|
|
|
|
0
|
return $self->watch_property_with_cursor( @_ ); |
601
|
|
|
|
|
|
|
} |
602
|
|
|
|
|
|
|
|
603
|
6
|
|
|
|
|
11
|
async method watch_property_with_cursor ( $property, $from, %args ) |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
7
|
|
604
|
6
|
|
|
|
|
19
|
{ |
605
|
|
|
|
|
|
|
match( $from : eq ) { |
606
|
5
|
|
|
|
|
10
|
case( "first" ) { $from = CUSR_FIRST } |
607
|
1
|
|
|
|
|
3
|
case( "last" ) { $from = CUSR_LAST } |
608
|
6
|
100
|
|
|
|
24
|
default { croak "Unrecognised 'from' value $from" } |
|
0
|
50
|
|
|
|
0
|
|
609
|
|
|
|
|
|
|
} |
610
|
|
|
|
|
|
|
|
611
|
6
|
50
|
|
|
|
19
|
my $pdef = $self->can_property( $property ) |
612
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a property $property"; |
613
|
|
|
|
|
|
|
|
614
|
6
|
|
|
|
|
26
|
my $callbacks = _watchcbs_from_args( $pdef, %args ); |
615
|
|
|
|
|
|
|
|
616
|
|
|
|
|
|
|
# Smashed properties behave differently |
617
|
6
|
|
|
|
|
22
|
my $smashed = $pdef->smashed; |
618
|
|
|
|
|
|
|
|
619
|
6
|
50
|
|
|
|
41
|
if( my $cbs = $_props{$property}->{cbs} ) { |
620
|
0
|
|
|
|
|
0
|
die "TODO: need to synthesize a second cursor for $self"; |
621
|
|
|
|
|
|
|
} |
622
|
|
|
|
|
|
|
|
623
|
6
|
|
|
|
|
31
|
$_props{$property}->{cbs} = [ $callbacks ]; |
624
|
|
|
|
|
|
|
|
625
|
6
|
50
|
|
|
|
21
|
if( $smashed ) { |
626
|
0
|
|
|
|
|
0
|
die "TODO: need to synthesize an cursor"; |
627
|
|
|
|
|
|
|
} |
628
|
|
|
|
|
|
|
|
629
|
6
|
50
|
|
|
|
20
|
$pdef->dimension == DIM_QUEUE or croak "Can only iterate on queue-dimension properties"; |
630
|
|
|
|
|
|
|
|
631
|
6
|
|
|
|
|
45
|
my $message = await $_client->request( |
632
|
|
|
|
|
|
|
request => Tangence::Message->new( $_client, MSG_WATCH_CUSR ) |
633
|
|
|
|
|
|
|
->pack_int( $self->id ) |
634
|
|
|
|
|
|
|
->pack_str( $property ) |
635
|
|
|
|
|
|
|
->pack_int( $from ), |
636
|
|
|
|
|
|
|
); |
637
|
|
|
|
|
|
|
|
638
|
6
|
|
|
|
|
174
|
my $code = $message->code; |
639
|
|
|
|
|
|
|
|
640
|
6
|
50
|
|
|
|
48
|
if( $code == MSG_WATCHING_CUSR ) { |
641
|
6
|
|
|
|
|
23
|
my $cursor_id = $message->unpack_int(); |
642
|
6
|
|
|
|
|
17
|
my $first_idx = $message->unpack_int(); |
643
|
6
|
|
|
|
|
17
|
my $last_idx = $message->unpack_int(); |
644
|
|
|
|
|
|
|
|
645
|
6
|
|
|
|
|
25
|
my $cursor = Tangence::ObjectProxy::_Cursor->new( $self, $cursor_id, $pdef->type ); |
646
|
6
|
|
|
|
|
55
|
return ( $cursor, $first_idx, $last_idx ); |
647
|
|
|
|
|
|
|
} |
648
|
|
|
|
|
|
|
else { |
649
|
0
|
|
|
|
|
0
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
650
|
|
|
|
|
|
|
} |
651
|
6
|
|
|
6
|
1
|
840
|
} |
652
|
|
|
|
|
|
|
|
653
|
47
|
|
|
|
|
75
|
method handle_request_UPDATE ( $message ) |
|
47
|
|
|
|
|
92
|
|
|
47
|
|
|
|
|
82
|
|
654
|
47
|
|
|
47
|
0
|
104
|
{ |
655
|
47
|
|
|
|
|
152
|
my $prop = $message->unpack_str(); |
656
|
47
|
|
|
|
|
1176
|
my $how = TYPE_U8->unpack_value( $message ); |
657
|
|
|
|
|
|
|
|
658
|
47
|
50
|
|
|
|
171
|
my $pdef = $self->can_property( $prop ) or return; |
659
|
47
|
|
|
|
|
177
|
my $type = $pdef->type; |
660
|
47
|
|
|
|
|
136
|
my $dim = $pdef->dimension; |
661
|
|
|
|
|
|
|
|
662
|
47
|
|
50
|
|
|
179
|
my $p = $_props{$prop} ||= {}; |
663
|
|
|
|
|
|
|
|
664
|
47
|
|
|
|
|
97
|
my $dimname = DIMNAMES->[$dim]; |
665
|
47
|
50
|
|
|
|
299
|
if( my $code = $self->can( "_update_property_$dimname" ) ) { |
666
|
47
|
|
|
|
|
199
|
$code->( $self, $p, $type, $how, $message ); |
667
|
|
|
|
|
|
|
} |
668
|
|
|
|
|
|
|
else { |
669
|
0
|
|
|
|
|
0
|
croak "Unrecognised property dimension $dim for $prop"; |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
|
672
|
47
|
|
66
|
|
|
204
|
$_->{on_updated} and $_->{on_updated}->( $p->{cache} ) for @{ $p->{cbs} }; |
|
47
|
|
|
|
|
410
|
|
673
|
|
|
|
|
|
|
} |
674
|
|
|
|
|
|
|
|
675
|
15
|
|
|
|
|
25
|
method _update_property_scalar ( $p, $type, $how, $message ) |
|
15
|
|
|
|
|
24
|
|
|
15
|
|
|
|
|
25
|
|
|
15
|
|
|
|
|
37
|
|
|
15
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
23
|
|
676
|
15
|
|
|
15
|
|
34
|
{ |
677
|
|
|
|
|
|
|
match( $how : == ) { |
678
|
|
|
|
|
|
|
case( CHANGE_SET ) { |
679
|
15
|
|
|
|
|
52
|
my $value = $type->unpack_value( $message ); |
680
|
15
|
|
|
|
|
40
|
$p->{cache} = $value; |
681
|
15
|
|
33
|
|
|
27
|
$_->{on_set} and $_->{on_set}->( $p->{cache} ) for @{ $p->{cbs} }; |
|
15
|
|
|
|
|
99
|
|
682
|
|
|
|
|
|
|
} |
683
|
15
|
50
|
|
|
|
43
|
default { |
684
|
0
|
|
|
|
|
0
|
croak "Change type $how is not valid for a scalar property"; |
685
|
|
|
|
|
|
|
} |
686
|
|
|
|
|
|
|
} |
687
|
|
|
|
|
|
|
} |
688
|
|
|
|
|
|
|
|
689
|
8
|
|
|
|
|
25
|
method _update_property_hash ( $p, $type, $how, $message ) |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
14
|
|
690
|
8
|
|
|
8
|
|
14
|
{ |
691
|
|
|
|
|
|
|
match( $how : == ) { |
692
|
|
|
|
|
|
|
case( CHANGE_SET ) { |
693
|
2
|
|
|
|
|
9
|
my $value = Tangence::Type->make( dict => $type )->unpack_value( $message ); |
694
|
2
|
|
|
|
|
6
|
$p->{cache} = $value; |
695
|
2
|
|
66
|
|
|
6
|
$_->{on_set} and $_->{on_set}->( $p->{cache} ) for @{ $p->{cbs} }; |
|
2
|
|
|
|
|
17
|
|
696
|
|
|
|
|
|
|
} |
697
|
|
|
|
|
|
|
case( CHANGE_ADD ) { |
698
|
4
|
|
|
|
|
15
|
my $key = $message->unpack_str(); |
699
|
4
|
|
|
|
|
80
|
my $value = $type->unpack_value( $message ); |
700
|
4
|
|
|
|
|
19
|
$p->{cache}->{$key} = $value; |
701
|
4
|
|
66
|
|
|
8
|
$_->{on_add} and $_->{on_add}->( $key, $value ) for @{ $p->{cbs} }; |
|
4
|
|
|
|
|
27
|
|
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
case( CHANGE_DEL ) { |
704
|
2
|
|
|
|
|
10
|
my $key = $message->unpack_str(); |
705
|
2
|
|
|
|
|
41
|
delete $p->{cache}->{$key}; |
706
|
2
|
|
66
|
|
|
5
|
$_->{on_del} and $_->{on_del}->( $key ) for @{ $p->{cbs} }; |
|
2
|
|
|
|
|
17
|
|
707
|
|
|
|
|
|
|
} |
708
|
8
|
100
|
|
|
|
43
|
default { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
709
|
0
|
|
|
|
|
0
|
croak "Change type $how is not valid for a hash property"; |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
|
714
|
7
|
|
|
|
|
13
|
method _update_property_queue ( $p, $type, $how, $message ) |
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
10
|
|
|
7
|
|
|
|
|
10
|
|
715
|
7
|
|
|
7
|
|
13
|
{ |
716
|
|
|
|
|
|
|
match( $how : == ) { |
717
|
|
|
|
|
|
|
case( CHANGE_SET ) { |
718
|
1
|
|
|
|
|
5
|
my $value = Tangence::Type->make( list => $type )->unpack_value( $message ); |
719
|
1
|
|
|
|
|
4
|
$p->{cache} = $value; |
720
|
1
|
|
33
|
|
|
20
|
$_->{on_set} and $_->{on_set}->( $p->{cache} ) for @{ $p->{cbs} }; |
|
1
|
|
|
|
|
14
|
|
721
|
|
|
|
|
|
|
} |
722
|
|
|
|
|
|
|
case( CHANGE_PUSH ) { |
723
|
3
|
|
|
|
|
13
|
my @value = $message->unpack_all_sametype( $type ); |
724
|
3
|
|
|
|
|
7
|
push @{ $p->{cache} }, @value; |
|
3
|
|
|
|
|
8
|
|
725
|
3
|
|
33
|
|
|
5
|
$_->{on_push} and $_->{on_push}->( @value ) for @{ $p->{cbs} }; |
|
3
|
|
|
|
|
21
|
|
726
|
|
|
|
|
|
|
} |
727
|
|
|
|
|
|
|
case( CHANGE_SHIFT ) { |
728
|
3
|
|
|
|
|
10
|
my $count = $message->unpack_int(); |
729
|
3
|
|
|
|
|
5
|
splice @{ $p->{cache} }, 0, $count, (); |
|
3
|
|
|
|
|
9
|
|
730
|
3
|
|
33
|
|
|
5
|
$_->{on_shift} and $_->{on_shift}->( $count ) for @{ $p->{cbs} }; |
|
3
|
|
|
|
|
23
|
|
731
|
|
|
|
|
|
|
} |
732
|
7
|
100
|
|
|
|
35
|
default { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
733
|
0
|
|
|
|
|
0
|
croak "Change type $how is not valid for a queue property"; |
734
|
|
|
|
|
|
|
} |
735
|
|
|
|
|
|
|
} |
736
|
|
|
|
|
|
|
} |
737
|
|
|
|
|
|
|
|
738
|
13
|
|
|
|
|
23
|
method _update_property_array ( $p, $type, $how, $message ) |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
18
|
|
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
22
|
|
|
13
|
|
|
|
|
16
|
|
739
|
13
|
|
|
13
|
|
24
|
{ |
740
|
|
|
|
|
|
|
match( $how : == ) { |
741
|
|
|
|
|
|
|
case( CHANGE_SET ) { |
742
|
4
|
|
|
|
|
21
|
my $value = Tangence::Type->make( list => $type )->unpack_value( $message ); |
743
|
4
|
|
|
|
|
13
|
$p->{cache} = $value; |
744
|
4
|
|
66
|
|
|
18
|
$_->{on_set} and $_->{on_set}->( $p->{cache} ) for @{ $p->{cbs} }; |
|
4
|
|
|
|
|
34
|
|
745
|
|
|
|
|
|
|
} |
746
|
|
|
|
|
|
|
case( CHANGE_PUSH ) { |
747
|
3
|
|
|
|
|
17
|
my @value = $message->unpack_all_sametype( $type ); |
748
|
3
|
|
|
|
|
4
|
push @{ $p->{cache} }, @value; |
|
3
|
|
|
|
|
10
|
|
749
|
3
|
|
66
|
|
|
6
|
$_->{on_push} and $_->{on_push}->( @value ) for @{ $p->{cbs} }; |
|
3
|
|
|
|
|
21
|
|
750
|
|
|
|
|
|
|
} |
751
|
|
|
|
|
|
|
case( CHANGE_SHIFT ) { |
752
|
1
|
|
|
|
|
3
|
my $count = $message->unpack_int(); |
753
|
1
|
|
|
|
|
3
|
splice @{ $p->{cache} }, 0, $count, (); |
|
1
|
|
|
|
|
4
|
|
754
|
1
|
|
33
|
|
|
2
|
$_->{on_shift} and $_->{on_shift}->( $count ) for @{ $p->{cbs} }; |
|
1
|
|
|
|
|
9
|
|
755
|
|
|
|
|
|
|
} |
756
|
|
|
|
|
|
|
case( CHANGE_SPLICE ) { |
757
|
2
|
|
|
|
|
9
|
my $start = $message->unpack_int(); |
758
|
2
|
|
|
|
|
8
|
my $count = $message->unpack_int(); |
759
|
2
|
|
|
|
|
10
|
my @value = $message->unpack_all_sametype( $type ); |
760
|
2
|
|
|
|
|
6
|
splice @{ $p->{cache} }, $start, $count, @value; |
|
2
|
|
|
|
|
9
|
|
761
|
2
|
|
66
|
|
|
5
|
$_->{on_splice} and $_->{on_splice}->( $start, $count, @value ) for @{ $p->{cbs} }; |
|
2
|
|
|
|
|
18
|
|
762
|
|
|
|
|
|
|
} |
763
|
|
|
|
|
|
|
case( CHANGE_MOVE ) { |
764
|
3
|
|
|
|
|
12
|
my $index = $message->unpack_int(); |
765
|
3
|
|
|
|
|
11
|
my $delta = $message->unpack_int(); |
766
|
|
|
|
|
|
|
# it turns out that exchanging neighbours is quicker by list assignment, |
767
|
|
|
|
|
|
|
# but other times it's generally best to use splice() to extract then |
768
|
|
|
|
|
|
|
# insert |
769
|
3
|
50
|
|
|
|
10
|
if( abs($delta) == 1 ) { |
770
|
0
|
|
|
|
|
0
|
@{$p->{cache}}[$index,$index+$delta] = @{$p->{cache}}[$index+$delta,$index]; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
771
|
|
|
|
|
|
|
} |
772
|
|
|
|
|
|
|
else { |
773
|
3
|
|
|
|
|
6
|
my $elem = splice @{ $p->{cache} }, $index, 1, (); |
|
3
|
|
|
|
|
11
|
|
774
|
3
|
|
|
|
|
6
|
splice @{ $p->{cache} }, $index + $delta, 0, ( $elem ); |
|
3
|
|
|
|
|
11
|
|
775
|
|
|
|
|
|
|
} |
776
|
3
|
|
66
|
|
|
16
|
$_->{on_move} and $_->{on_move}->( $index, $delta ) for @{ $p->{cbs} }; |
|
3
|
|
|
|
|
22
|
|
777
|
|
|
|
|
|
|
} |
778
|
13
|
100
|
|
|
|
69
|
default { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
779
|
0
|
|
|
|
|
0
|
croak "Change type $how is not valid for an array property"; |
780
|
|
|
|
|
|
|
} |
781
|
|
|
|
|
|
|
} |
782
|
|
|
|
|
|
|
} |
783
|
|
|
|
|
|
|
|
784
|
4
|
|
|
|
|
148
|
method _update_property_objset ( $p, $type, $how, $message ) |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
7
|
|
785
|
4
|
|
|
4
|
|
9
|
{ |
786
|
|
|
|
|
|
|
match( $how : == ) { |
787
|
|
|
|
|
|
|
case( CHANGE_SET ) { |
788
|
|
|
|
|
|
|
# Comes across in a LIST. We need to map id => obj |
789
|
2
|
|
|
|
|
14
|
my $objects = Tangence::Type->make( list => $type )->unpack_value( $message ); |
790
|
2
|
|
|
|
|
9
|
$p->{cache} = { map { $_->id => $_ } @$objects }; |
|
1
|
|
|
|
|
7
|
|
791
|
2
|
|
33
|
|
|
5
|
$_->{on_set} and $_->{on_set}->( $p->{cache} ) for @{ $p->{cbs} }; |
|
2
|
|
|
|
|
23
|
|
792
|
|
|
|
|
|
|
} |
793
|
|
|
|
|
|
|
case( CHANGE_ADD ) { |
794
|
|
|
|
|
|
|
# Comes as object only |
795
|
1
|
|
|
|
|
7
|
my $obj = $type->unpack_value( $message ); |
796
|
1
|
|
|
|
|
8
|
$p->{cache}->{$obj->id} = $obj; |
797
|
1
|
|
33
|
|
|
2
|
$_->{on_add} and $_->{on_add}->( $obj ) for @{ $p->{cbs} }; |
|
1
|
|
|
|
|
10
|
|
798
|
|
|
|
|
|
|
} |
799
|
|
|
|
|
|
|
case( CHANGE_DEL ) { |
800
|
|
|
|
|
|
|
# Comes as ID number only |
801
|
1
|
|
|
|
|
7
|
my $id = $message->unpack_int(); |
802
|
1
|
|
|
|
|
5
|
delete $p->{cache}->{$id}; |
803
|
1
|
|
33
|
|
|
2
|
$_->{on_del} and $_->{on_del}->( $id ) for @{ $p->{cbs} }; |
|
1
|
|
|
|
|
12
|
|
804
|
|
|
|
|
|
|
} |
805
|
4
|
100
|
|
|
|
62
|
default { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
806
|
0
|
|
|
|
|
0
|
croak "Change type $how is not valid for an objset property"; |
807
|
|
|
|
|
|
|
} |
808
|
|
|
|
|
|
|
} |
809
|
|
|
|
|
|
|
} |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
=head2 unwatch_property |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
$proxy->unwatch_property( $property ) |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
Removes a property watches on the given property on the server object that was |
816
|
|
|
|
|
|
|
previously installed using C. |
817
|
|
|
|
|
|
|
|
818
|
|
|
|
|
|
|
=cut |
819
|
|
|
|
|
|
|
|
820
|
4
|
|
|
|
|
8
|
method unwatch_property ( $property ) |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
6
|
|
821
|
4
|
|
|
4
|
1
|
3318
|
{ |
822
|
4
|
50
|
|
|
|
12
|
$self->can_property( $property ) |
823
|
|
|
|
|
|
|
or croak "Class ".$self->classname." does not have a property $property"; |
824
|
|
|
|
|
|
|
|
825
|
|
|
|
|
|
|
# TODO: mark cursors as destroyed and invalid |
826
|
4
|
|
|
|
|
32
|
delete $_props{$property}; |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
$_client->request( |
829
|
|
|
|
|
|
|
request => Tangence::Message->new( $_client, MSG_UNWATCH ) |
830
|
|
|
|
|
|
|
->pack_int( $self->id ) |
831
|
|
|
|
|
|
|
->pack_str( $property ), |
832
|
|
|
|
|
|
|
|
833
|
|
|
|
4
|
|
|
on_response => sub {}, |
834
|
4
|
|
|
|
|
27
|
); |
835
|
|
|
|
|
|
|
} |
836
|
|
|
|
|
|
|
|
837
|
|
|
|
|
|
|
class Tangence::ObjectProxy::_Cursor |
838
|
|
|
|
|
|
|
{ |
839
|
9
|
|
|
9
|
|
80941
|
use Carp; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
605
|
|
840
|
9
|
|
|
9
|
|
53
|
use Tangence::Constants; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
10962
|
|
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
=head1 CURSOR METHODS |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
The following methods are availilable on the property cursor objects returned |
845
|
|
|
|
|
|
|
by the C method. |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
=cut |
848
|
|
|
|
|
|
|
|
849
|
0
|
|
|
0
|
|
0
|
has $obj :param :reader; |
|
0
|
|
|
|
|
0
|
|
850
|
0
|
|
|
0
|
|
0
|
has $id :param :reader; |
|
0
|
|
|
|
|
0
|
|
851
|
|
|
|
|
|
|
has $element_type :param; |
852
|
|
|
|
|
|
|
|
853
|
6
|
|
|
|
|
11
|
sub BUILDARGS ( $class, $obj, $id, $element_type ) |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
8
|
|
854
|
6
|
|
|
6
|
|
12
|
{ |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
10
|
|
855
|
6
|
|
|
|
|
50
|
return ( obj => $obj, id => $id, element_type => $element_type ); |
856
|
|
|
|
|
|
|
} |
857
|
|
|
|
|
|
|
|
858
|
18
|
|
|
18
|
|
34
|
method client { $obj->client } |
|
18
|
|
|
|
|
47
|
|
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
# TODO: Object::Pad probably should do this bit |
861
|
|
|
|
|
|
|
method DESTROY |
862
|
6
|
|
|
6
|
|
2087
|
{ |
863
|
6
|
50
|
33
|
|
|
62
|
return unless $obj and my $client = $self->client; |
864
|
|
|
|
|
|
|
|
865
|
|
|
|
|
|
|
$client->request( |
866
|
|
|
|
|
|
|
request => Tangence::Message->new( $client, MSG_CUSR_DESTROY ) |
867
|
|
|
|
|
|
|
->pack_int( $id ), |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
6
|
|
|
on_response => sub {}, |
870
|
6
|
|
|
|
|
39
|
); |
871
|
|
|
|
|
|
|
} |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
=head2 next_forward |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
( $index, @more ) = await $cursor->next_forward( $count ) |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
=head2 next_backward |
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
( $index, @more ) = await $cursor->next_backward( $count ) |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
Requests the next items from the cursor. C moves forwards |
882
|
|
|
|
|
|
|
towards higher-numbered indices, and C moves backwards towards |
883
|
|
|
|
|
|
|
lower-numbered indices. If C<$count> is unspecified, a default of 1 will |
884
|
|
|
|
|
|
|
apply. |
885
|
|
|
|
|
|
|
|
886
|
|
|
|
|
|
|
The returned future wil yield the index of the first element returned, and the |
887
|
|
|
|
|
|
|
new elements. Note that there may be fewer elements returned than were |
888
|
|
|
|
|
|
|
requested, if the end of the queue was reached. Specifically, there will be no |
889
|
|
|
|
|
|
|
new elements if the cursor is already at the end. |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
=cut |
892
|
|
|
|
|
|
|
|
893
|
|
|
|
|
|
|
method next_forward |
894
|
7
|
|
|
7
|
|
7243
|
{ |
895
|
7
|
|
|
|
|
27
|
$self->_next( CUSR_FWD, @_ ); |
896
|
|
|
|
|
|
|
} |
897
|
|
|
|
|
|
|
|
898
|
|
|
|
|
|
|
method next_backward |
899
|
5
|
|
|
5
|
|
3829
|
{ |
900
|
5
|
|
|
|
|
19
|
$self->_next( CUSR_BACK, @_ ); |
901
|
|
|
|
|
|
|
} |
902
|
|
|
|
|
|
|
|
903
|
12
|
|
|
|
|
15
|
async method _next ( $direction, $count = 1 ) |
|
12
|
|
|
|
|
21
|
|
|
12
|
|
|
|
|
15
|
|
|
12
|
|
|
|
|
13
|
|
904
|
12
|
|
|
|
|
25
|
{ |
905
|
|
|
|
|
|
|
# Detect void-context legacy uses |
906
|
|
|
|
|
|
|
defined wantarray or |
907
|
12
|
50
|
|
|
|
31
|
croak "->next_forward/backward in void context no longer useful - it now returns a Future"; |
908
|
|
|
|
|
|
|
|
909
|
12
|
|
|
|
|
30
|
my $client = $self->client; |
910
|
|
|
|
|
|
|
|
911
|
12
|
|
|
|
|
78
|
my $message = await $client->request( |
912
|
|
|
|
|
|
|
request => Tangence::Message->new( $client, MSG_CUSR_NEXT ) |
913
|
|
|
|
|
|
|
->pack_int( $id ) |
914
|
|
|
|
|
|
|
->pack_int( $direction ) |
915
|
|
|
|
|
|
|
->pack_int( $count || 1 ), |
916
|
|
|
|
|
|
|
); |
917
|
|
|
|
|
|
|
|
918
|
12
|
|
|
|
|
344
|
my $code = $message->code; |
919
|
|
|
|
|
|
|
|
920
|
12
|
50
|
|
|
|
28
|
if( $code == MSG_CUSR_RESULT ) { |
921
|
|
|
|
|
|
|
return ( |
922
|
12
|
|
|
|
|
38
|
$message->unpack_int(), |
923
|
|
|
|
|
|
|
$message->unpack_all_sametype( $element_type ), |
924
|
|
|
|
|
|
|
); |
925
|
|
|
|
|
|
|
} |
926
|
|
|
|
|
|
|
else { |
927
|
0
|
|
|
|
|
|
Future::Exception->throw( "Unexpected response code $code", tangence => ); |
928
|
|
|
|
|
|
|
} |
929
|
12
|
|
|
12
|
|
23
|
} |
930
|
|
|
|
|
|
|
} |
931
|
|
|
|
|
|
|
|
932
|
|
|
|
|
|
|
=head1 AUTHOR |
933
|
|
|
|
|
|
|
|
934
|
|
|
|
|
|
|
Paul Evans |
935
|
|
|
|
|
|
|
|
936
|
|
|
|
|
|
|
=cut |
937
|
|
|
|
|
|
|
|
938
|
|
|
|
|
|
|
0x55AA; |