… | |
… | |
27 | This module (-family) implements a simple message passing framework. |
27 | This module (-family) implements a simple message passing framework. |
28 | |
28 | |
29 | Despite its simplicity, you can securely message other processes running |
29 | Despite its simplicity, you can securely message other processes running |
30 | on the same or other hosts. |
30 | on the same or other hosts. |
31 | |
31 | |
|
|
32 | At the moment, this module family is severly brokena nd underdocumented, |
|
|
33 | so do not use. This was uploaded mainly to resreve the CPAN namespace - |
|
|
34 | stay tuned! |
|
|
35 | |
32 | =head1 CONCEPTS |
36 | =head1 CONCEPTS |
33 | |
37 | |
34 | =over 4 |
38 | =over 4 |
35 | |
39 | |
36 | =item port |
40 | =item port |
… | |
… | |
81 | |
85 | |
82 | use AE (); |
86 | use AE (); |
83 | |
87 | |
84 | use base "Exporter"; |
88 | use base "Exporter"; |
85 | |
89 | |
86 | our $VERSION = '0.0'; |
90 | our $VERSION = '0.01'; |
87 | our @EXPORT = qw(NODE $NODE $PORT snd rcv _any_); |
91 | our @EXPORT = qw(NODE $NODE $PORT snd rcv _any_); |
88 | |
92 | |
89 | our $DEFAULT_SECRET; |
93 | our $DEFAULT_SECRET; |
90 | our $DEFAULT_PORT = "4040"; |
94 | our $DEFAULT_PORT = "4040"; |
91 | |
95 | |
… | |
… | |
111 | C<become_slave>, after which all local port identifiers become invalid. |
115 | C<become_slave>, after which all local port identifiers become invalid. |
112 | |
116 | |
113 | =cut |
117 | =cut |
114 | |
118 | |
115 | our $UNIQ = sprintf "%x.%x", $$, time; # per-process/node unique cookie |
119 | our $UNIQ = sprintf "%x.%x", $$, time; # per-process/node unique cookie |
|
|
120 | our $ID = "a0"; |
116 | our $PUBLIC = 0; |
121 | our $PUBLIC = 0; |
117 | our $NODE; |
122 | our $NODE; |
118 | our $PORT; |
123 | our $PORT; |
119 | |
124 | |
120 | our %NODE; # node id to transport mapping, or "undef", for local node |
125 | our %NODE; # node id to transport mapping, or "undef", for local node |
… | |
… | |
254 | && &{$_->[0]} |
259 | && &{$_->[0]} |
255 | && undef $_; |
260 | && undef $_; |
256 | } |
261 | } |
257 | |
262 | |
258 | for (@{ $port->{any} }) { |
263 | for (@{ $port->{any} }) { |
259 | $_ && [@_[0..$#{$_->[1]}]] ~~ $_->[1] |
264 | $_ && [@_[0..$#{$_->[1]}]] ~~ $_->[1] |
260 | && &{$_->[0]} |
265 | && &{$_->[0]} |
261 | && undef $_; |
266 | && undef $_; |
262 | } |
267 | } |
263 | } |
268 | } |
264 | |
269 | |
… | |
… | |
392 | } |
397 | } |
393 | |
398 | |
394 | $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; |
399 | $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; |
395 | _new_port ""; |
400 | _new_port ""; |
396 | |
401 | |
|
|
402 | =item devnull => ... |
|
|
403 | |
|
|
404 | Generic data sink/CPU heat conversion. |
|
|
405 | |
|
|
406 | =cut |
|
|
407 | |
|
|
408 | rcv "", devnull => sub { () }; |
|
|
409 | |
397 | =item relay => $port, @msg |
410 | =item relay => $port, @msg |
398 | |
411 | |
399 | Simply forwards the message to the given port. |
412 | Simply forwards the message to the given port. |
400 | |
413 | |
401 | =cut |
414 | =cut |
402 | |
415 | |
403 | rcv "", relay => \&snd; |
416 | rcv "", relay => sub { \&snd; () }; |
404 | |
417 | |
405 | =item eval => $string[ @reply] |
418 | =item eval => $string[ @reply] |
406 | |
419 | |
407 | Evaluates the given string. If C<@reply> is given, then a message of the |
420 | Evaluates the given string. If C<@reply> is given, then a message of the |
408 | form C<@reply, $@, @evalres> is sent. |
421 | form C<@reply, $@, @evalres> is sent. |
… | |
… | |
415 | |
428 | |
416 | rcv "", eval => sub { |
429 | rcv "", eval => sub { |
417 | my (undef, $string, @reply) = @_; |
430 | my (undef, $string, @reply) = @_; |
418 | my @res = eval $string; |
431 | my @res = eval $string; |
419 | snd @reply, "$@", @res if @reply; |
432 | snd @reply, "$@", @res if @reply; |
|
|
433 | () |
420 | }; |
434 | }; |
421 | |
435 | |
422 | =item time => @reply |
436 | =item time => @reply |
423 | |
437 | |
424 | Replies the the current node time to C<@reply>. |
438 | Replies the the current node time to C<@reply>. |
… | |
… | |
429 | snd $NODE, time => $myport, timereply => 1, 2; |
443 | snd $NODE, time => $myport, timereply => 1, 2; |
430 | # => snd $myport, timereply => 1, 2, <time> |
444 | # => snd $myport, timereply => 1, 2, <time> |
431 | |
445 | |
432 | =cut |
446 | =cut |
433 | |
447 | |
434 | rcv "", time => sub { shift; snd @_, AE::time }; |
448 | rcv "", time => sub { shift; snd @_, AE::time; () }; |
435 | |
449 | |
436 | =back |
450 | =back |
437 | |
451 | |
438 | =head1 SEE ALSO |
452 | =head1 SEE ALSO |
439 | |
453 | |