… | |
… | |
621 | the package, then the package above the package and so on (e.g. |
621 | the package, then the package above the package and so on (e.g. |
622 | C<MyApp::Chat::Server>, C<MyApp::Chat>, C<MyApp>) until the function |
622 | C<MyApp::Chat::Server>, C<MyApp::Chat>, C<MyApp>) until the function |
623 | exists or it runs out of package names. |
623 | exists or it runs out of package names. |
624 | |
624 | |
625 | The init function is then called with the newly-created port as context |
625 | The init function is then called with the newly-created port as context |
626 | object (C<$SELF>) and the C<@initdata> values as arguments. |
626 | object (C<$SELF>) and the C<@initdata> values as arguments. It I<must> |
|
|
627 | call one of the C<rcv> functions to set callbacks on C<$SELF>, otherwise |
|
|
628 | the port might not get created. |
627 | |
629 | |
628 | A common idiom is to pass a local port, immediately monitor the spawned |
630 | A common idiom is to pass a local port, immediately monitor the spawned |
629 | port, and in the remote init function, immediately monitor the passed |
631 | port, and in the remote init function, immediately monitor the passed |
630 | local port. This two-way monitoring ensures that both ports get cleaned up |
632 | local port. This two-way monitoring ensures that both ports get cleaned up |
631 | when there is a problem. |
633 | when there is a problem. |
… | |
… | |
655 | |
657 | |
656 | sub _spawn { |
658 | sub _spawn { |
657 | my $port = shift; |
659 | my $port = shift; |
658 | my $init = shift; |
660 | my $init = shift; |
659 | |
661 | |
|
|
662 | # rcv will create the actual port |
660 | local $SELF = "$NODE#$port"; |
663 | local $SELF = "$NODE#$port"; |
661 | eval { |
664 | eval { |
662 | &{ load_func $init } |
665 | &{ load_func $init } |
663 | }; |
666 | }; |
664 | _self_die if $@; |
667 | _self_die if $@; |