… | |
… | |
183 | |
183 | |
184 | package AnyEvent::MP; |
184 | package AnyEvent::MP; |
185 | |
185 | |
186 | use AnyEvent::MP::Config (); |
186 | use AnyEvent::MP::Config (); |
187 | use AnyEvent::MP::Kernel; |
187 | use AnyEvent::MP::Kernel; |
188 | use AnyEvent::MP::Kernel qw(%NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID); |
188 | use AnyEvent::MP::Kernel qw( |
|
|
189 | %NODE %PORT %PORT_DATA $UNIQ $RUNIQ $ID |
|
|
190 | add_node load_func |
|
|
191 | |
|
|
192 | NODE $NODE |
|
|
193 | configure |
|
|
194 | node_of port_is_local |
|
|
195 | snd kil |
|
|
196 | db_set db_del |
|
|
197 | db_mon db_family db_keys db_values |
|
|
198 | ); |
189 | |
199 | |
190 | use common::sense; |
200 | use common::sense; |
191 | |
201 | |
192 | use Carp (); |
202 | use Carp (); |
193 | |
203 | |
… | |
… | |
197 | use base "Exporter"; |
207 | use base "Exporter"; |
198 | |
208 | |
199 | our $VERSION = $AnyEvent::MP::Config::VERSION; |
209 | our $VERSION = $AnyEvent::MP::Config::VERSION; |
200 | |
210 | |
201 | our @EXPORT = qw( |
211 | our @EXPORT = qw( |
202 | NODE $NODE *SELF node_of after |
212 | NODE $NODE |
203 | configure |
213 | configure |
|
|
214 | node_of port_is_local |
|
|
215 | snd kil |
|
|
216 | db_set db_del |
|
|
217 | db_mon db_family db_keys db_values |
|
|
218 | |
|
|
219 | *SELF |
|
|
220 | |
204 | snd rcv mon mon_guard kil psub peval spawn cal |
221 | port rcv mon mon_guard psub peval spawn cal |
205 | port |
|
|
206 | db_set db_del db_reg |
222 | db_set db_del db_reg |
207 | db_mon db_family db_keys db_values |
223 | db_mon db_family db_keys db_values |
|
|
224 | |
|
|
225 | after |
208 | ); |
226 | ); |
209 | |
227 | |
210 | our $SELF; |
228 | our $SELF; |
211 | |
229 | |
212 | sub _self_die() { |
230 | sub _self_die() { |
… | |
… | |
223 | |
241 | |
224 | =item $nodeid = node_of $port |
242 | =item $nodeid = node_of $port |
225 | |
243 | |
226 | Extracts and returns the node ID from a port ID or a node ID. |
244 | Extracts and returns the node ID from a port ID or a node ID. |
227 | |
245 | |
|
|
246 | =item $is_local = port_is_local $port |
|
|
247 | |
|
|
248 | Returns true iff the port is a local port. |
|
|
249 | |
228 | =item configure $profile, key => value... |
250 | =item configure $profile, key => value... |
229 | |
251 | |
230 | =item configure key => value... |
252 | =item configure key => value... |
231 | |
253 | |
232 | Before a node can talk to other nodes on the network (i.e. enter |
254 | Before a node can talk to other nodes on the network (i.e. enter |
… | |
… | |
243 | =over 4 |
265 | =over 4 |
244 | |
266 | |
245 | =item norc => $boolean (default false) |
267 | =item norc => $boolean (default false) |
246 | |
268 | |
247 | If true, then the rc file (e.g. F<~/.perl-anyevent-mp>) will I<not> |
269 | If true, then the rc file (e.g. F<~/.perl-anyevent-mp>) will I<not> |
248 | be consulted - all configuraiton options must be specified in the |
270 | be consulted - all configuration options must be specified in the |
249 | C<configure> call. |
271 | C<configure> call. |
250 | |
272 | |
251 | =item force => $boolean (default false) |
273 | =item force => $boolean (default false) |
252 | |
274 | |
253 | IF true, then the values specified in the C<configure> will take |
275 | IF true, then the values specified in the C<configure> will take |
… | |
… | |
464 | |
486 | |
465 | sub rcv($@) { |
487 | sub rcv($@) { |
466 | my $port = shift; |
488 | my $port = shift; |
467 | my ($nodeid, $portid) = split /#/, $port, 2; |
489 | my ($nodeid, $portid) = split /#/, $port, 2; |
468 | |
490 | |
469 | $NODE{$nodeid} == $NODE{""} |
491 | $nodeid eq $NODE |
470 | or Carp::croak "$port: rcv can only be called on local ports, caught"; |
492 | or Carp::croak "$port: rcv can only be called on local ports, caught"; |
471 | |
493 | |
472 | while (@_) { |
494 | while (@_) { |
473 | if (ref $_[0]) { |
495 | if (ref $_[0]) { |
474 | if (my $self = $PORT_DATA{$portid}) { |
496 | if (my $self = $PORT_DATA{$portid}) { |
… | |
… | |
518 | } |
540 | } |
519 | |
541 | |
520 | =item peval $port, $coderef[, @args] |
542 | =item peval $port, $coderef[, @args] |
521 | |
543 | |
522 | Evaluates the given C<$codref> within the contetx of C<$port>, that is, |
544 | Evaluates the given C<$codref> within the contetx of C<$port>, that is, |
523 | when the code throews an exception the C<$port> will be killed. |
545 | when the code throws an exception the C<$port> will be killed. |
524 | |
546 | |
525 | Any remaining args will be passed to the callback. Any return values will |
547 | Any remaining args will be passed to the callback. Any return values will |
526 | be returned to the caller. |
548 | be returned to the caller. |
527 | |
549 | |
528 | This is useful when you temporarily want to execute code in the context of |
550 | This is useful when you temporarily want to execute code in the context of |