… | |
… | |
172 | that Storable can serialise and deserialise is allowed, and for the local |
172 | that Storable can serialise and deserialise is allowed, and for the local |
173 | node, anything can be passed. |
173 | node, anything can be passed. |
174 | |
174 | |
175 | =cut |
175 | =cut |
176 | |
176 | |
177 | sub snd($@) { |
177 | sub snd(@) { |
178 | my ($noderef, $port) = split /#/, shift, 2; |
178 | my ($noderef, $port) = split /#/, shift, 2; |
179 | |
179 | |
180 | add_node $noderef |
180 | add_node $noderef |
181 | unless exists $NODE{$noderef}; |
181 | unless exists $NODE{$noderef}; |
182 | |
182 | |
… | |
… | |
362 | } |
362 | } |
363 | |
363 | |
364 | $PUBLIC = 1; |
364 | $PUBLIC = 1; |
365 | } |
365 | } |
366 | |
366 | |
|
|
367 | =back |
|
|
368 | |
|
|
369 | =head1 NODE MESSAGES |
|
|
370 | |
|
|
371 | Nodes understand the following messages sent to them: |
|
|
372 | |
|
|
373 | =over 4 |
|
|
374 | |
|
|
375 | =cut |
|
|
376 | |
367 | ############################################################################# |
377 | ############################################################################# |
368 | # self node code |
378 | # self node code |
369 | |
379 | |
370 | sub _new_port($) { |
380 | sub _new_port($) { |
371 | my ($name) = @_; |
381 | my ($name) = @_; |
… | |
… | |
379 | } |
389 | } |
380 | |
390 | |
381 | $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; |
391 | $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; |
382 | _new_port ""; |
392 | _new_port ""; |
383 | |
393 | |
|
|
394 | =item relay => $port, @msg |
|
|
395 | |
|
|
396 | Simply forwards the message to the given port. |
|
|
397 | |
|
|
398 | =cut |
|
|
399 | |
384 | rcv "", relay => \&snd; |
400 | rcv "", relay => \&snd; |
|
|
401 | |
|
|
402 | =item eval => $string[ @reply] |
|
|
403 | |
|
|
404 | Evaluates the given string. If C<@reply> is given, then a message of the |
|
|
405 | form C<@reply, $@, @evalres> is sent (C<$reply[0]> is the port to reply to). |
|
|
406 | |
|
|
407 | =cut |
|
|
408 | |
|
|
409 | rcv "", eval => sub { |
|
|
410 | my (undef, $string, @reply) = @_; |
|
|
411 | my @res = eval $string; |
|
|
412 | snd @reply, "$@", @res if @reply; |
|
|
413 | }; |
|
|
414 | |
|
|
415 | =item time => @reply |
|
|
416 | |
|
|
417 | Replies the the current node time to C<@reply>. |
|
|
418 | |
|
|
419 | =cut |
|
|
420 | |
|
|
421 | rcv "", time => sub { shift; snd @_, AE::time }; |
385 | |
422 | |
386 | =back |
423 | =back |
387 | |
424 | |
388 | =head1 SEE ALSO |
425 | =head1 SEE ALSO |
389 | |
426 | |