… | |
… | |
247 | |
247 | |
248 | IF true, then the values specified in the C<configure> will take |
248 | IF true, then the values specified in the C<configure> will take |
249 | precedence over any values configured via the rc file. The default is for |
249 | precedence over any values configured via the rc file. The default is for |
250 | the rc file to override any options specified in the program. |
250 | the rc file to override any options specified in the program. |
251 | |
251 | |
252 | =item secure => $pass->($nodeid) |
252 | =item secure => $pass->(@msg) |
253 | |
253 | |
254 | In addition to specifying a boolean, you can specify a code reference that |
254 | In addition to specifying a boolean, you can specify a code reference that |
255 | is called for every remote execution attempt - the execution request is |
255 | is called for every code execution attempt - the execution request is |
256 | granted iff the callback returns a true value. |
256 | granted iff the callback returns a true value. |
|
|
257 | |
|
|
258 | Most of the time the callback should look only at |
|
|
259 | C<$AnyEvent::MP::Kernel::SRCNODE> to make a decision, and not at the |
|
|
260 | actual message (which can be about anything, and is mostly provided for |
|
|
261 | diagnostic purposes). |
257 | |
262 | |
258 | See F<semp setsecure> for more info. |
263 | See F<semp setsecure> for more info. |
259 | |
264 | |
260 | =back |
265 | =back |
261 | |
266 | |
… | |
… | |
399 | =cut |
404 | =cut |
400 | |
405 | |
401 | sub rcv($@); |
406 | sub rcv($@); |
402 | |
407 | |
403 | my $KILME = sub { |
408 | my $KILME = sub { |
404 | die "received message on port without callback"; |
409 | (my $tag = substr $_[0], 0, 30) =~ s/([\x20-\x7e])/./g; |
|
|
410 | kil $SELF, unhandled_message => "no callback found for message '$tag'"; |
405 | }; |
411 | }; |
406 | |
412 | |
407 | sub port(;&) { |
413 | sub port(;&) { |
408 | my $id = $UNIQ . ++$ID; |
414 | my $id = $UNIQ . ++$ID; |
409 | my $port = "$NODE#$id"; |
415 | my $port = "$NODE#$id"; |
… | |
… | |
421 | |
427 | |
422 | The global C<$SELF> (exported by this module) contains C<$port> while |
428 | The global C<$SELF> (exported by this module) contains C<$port> while |
423 | executing the callback. Runtime errors during callback execution will |
429 | executing the callback. Runtime errors during callback execution will |
424 | result in the port being C<kil>ed. |
430 | result in the port being C<kil>ed. |
425 | |
431 | |
426 | The default callback received all messages not matched by a more specific |
432 | The default callback receives all messages not matched by a more specific |
427 | C<tag> match. |
433 | C<tag> match. |
428 | |
434 | |
429 | =item rcv $local_port, tag => $callback->(@msg_without_tag), ... |
435 | =item rcv $local_port, tag => $callback->(@msg_without_tag), ... |
430 | |
436 | |
431 | Register (or replace) callbacks to be called on messages starting with the |
437 | Register (or replace) callbacks to be called on messages starting with the |
… | |
… | |
732 | will be reported as reason C<< die => $@ >>. |
738 | will be reported as reason C<< die => $@ >>. |
733 | |
739 | |
734 | Transport/communication errors are reported as C<< transport_error => |
740 | Transport/communication errors are reported as C<< transport_error => |
735 | $message >>. |
741 | $message >>. |
736 | |
742 | |
737 | =cut |
743 | Common idioms: |
|
|
744 | |
|
|
745 | # silently remove yourself, do not kill linked ports |
|
|
746 | kil $SELF; |
|
|
747 | |
|
|
748 | # report a failure in some detail |
|
|
749 | kil $SELF, failure_mode_1 => "it failed with too high temperature"; |
|
|
750 | |
|
|
751 | # do not waste much time with killing, just die when something goes wrong |
|
|
752 | open my $fh, "<file" |
|
|
753 | or die "file: $!"; |
738 | |
754 | |
739 | =item $port = spawn $node, $initfunc[, @initdata] |
755 | =item $port = spawn $node, $initfunc[, @initdata] |
740 | |
756 | |
741 | Creates a port on the node C<$node> (which can also be a port ID, in which |
757 | Creates a port on the node C<$node> (which can also be a port ID, in which |
742 | case it's the node where that port resides). |
758 | case it's the node where that port resides). |