--- AnyEvent-MP/MP.pm 2009/08/01 07:11:45 1.3 +++ AnyEvent-MP/MP.pm 2009/08/01 15:04:30 1.7 @@ -29,6 +29,10 @@ Despite its simplicity, you can securely message other processes running on the same or other hosts. +At the moment, this module family is severly brokena nd underdocumented, +so do not use. This was uploaded mainly to resreve the CPAN namespace - +stay tuned! + =head1 CONCEPTS =over 4 @@ -54,7 +58,7 @@ (connected to a master node only). Only when they epxlicitly "become public" can you send them messages from unrelated other nodes. -=item noderef - C, C +=item noderef - C, C, C A noderef is a string that either uniquely identifies a given node (for private and hidden nodes), or contains a recipe on how to reach a given @@ -83,7 +87,7 @@ use base "Exporter"; -our $VERSION = '0.0'; +our $VERSION = '0.01'; our @EXPORT = qw(NODE $NODE $PORT snd rcv _any_); our $DEFAULT_SECRET; @@ -113,6 +117,7 @@ =cut our $UNIQ = sprintf "%x.%x", $$, time; # per-process/node unique cookie +our $ID = "a0"; our $PUBLIC = 0; our $NODE; our $PORT; @@ -174,7 +179,7 @@ =cut -sub snd($@) { +sub snd(@) { my ($noderef, $port) = split /#/, shift, 2; add_node $noderef @@ -256,7 +261,7 @@ } for (@{ $port->{any} }) { - $_ && [@_[0..$#{$_->[1]}]] ~~ $_->[1] + $_ && [@_[0..$#{$_->[1]}]] ~~ $_->[1] && &{$_->[0]} && undef $_; } @@ -364,6 +369,19 @@ $PUBLIC = 1; } +=back + +=head1 NODE MESSAGES + +Nodes understand the following messages sent to them. Many of them take +arguments called C<@reply>, which will simply be used to compose a reply +message - C<$reply[0]> is the port to reply to, C<$reply[1]> the type and +the remaining arguments are simply the message data. + +=over 4 + +=cut + ############################################################################# # self node code @@ -381,7 +399,53 @@ $NODE{""} = new AnyEvent::MP::Node::Self noderef => $NODE; _new_port ""; -rcv "", relay => \&snd; +=item devnull => ... + +Generic data sink/CPU heat conversion. + +=cut + +rcv "", devnull => sub { () }; + +=item relay => $port, @msg + +Simply forwards the message to the given port. + +=cut + +rcv "", relay => sub { \&snd; () }; + +=item eval => $string[ @reply] + +Evaluates the given string. If C<@reply> is given, then a message of the +form C<@reply, $@, @evalres> is sent. + +Example: crash another node. + + snd $othernode, eval => "exit"; + +=cut + +rcv "", eval => sub { + my (undef, $string, @reply) = @_; + my @res = eval $string; + snd @reply, "$@", @res if @reply; + () +}; + +=item time => @reply + +Replies the the current node time to C<@reply>. + +Example: tell the current node to send the current time to C<$myport> in a +C message. + + snd $NODE, time => $myport, timereply => 1, 2; + # => snd $myport, timereply => 1, 2,