--- AnyEvent-MP/MP.pm 2009/08/04 23:16:57 1.29 +++ AnyEvent-MP/MP.pm 2009/08/05 19:55:58 1.31 @@ -55,7 +55,7 @@ A port id is normaly the concatenation of a noderef, a hash-mark (C<#>) as separator, and a port name (a printable string of unspecified format). An -exception is the the node port, whose ID is identical to it's node +exception is the the node port, whose ID is identical to its node reference. =item node @@ -105,8 +105,7 @@ our $VERSION = '0.1'; our @EXPORT = qw( NODE $NODE *SELF node_of _any_ - resolve_node - become_slave become_public + resolve_node initialise_node snd rcv mon kil reg psub port ); @@ -242,12 +241,13 @@ =cut sub mon { - my ($noderef, $port, $cb) = ((split /#/, shift, 2), shift); + my ($noderef, $port) = split /#/, shift, 2; my $node = $NODE{$noderef} || add_node $noderef; - #TODO: ports must not be references - if (!ref $cb or "AnyEvent::MP::Port" eq ref $cb) { + my $cb = shift; + + unless (ref $cb) { if (@_) { # send a kill info message my (@msg) = ($cb, @_); @@ -301,7 +301,9 @@ =item $local_port = port -Create a new local port object that supports message matching. +Create a new local port object that can be used either as a pattern +matching port ("full port") or a single-callback port ("miniport"), +depending on how C callbacks are bound to the object. =item $portid = port { my @msg = @_; $finished } @@ -317,7 +319,7 @@ If you need the local port id in the callback, this works nicely: - my $port; $port = miniport { + my $port; $port = port { snd $otherport, reply => $port; }; @@ -388,6 +390,11 @@ $REG{$name} = $portid; } +=item rcv $portid, $callback->(@msg) + +Replaces the callback on the specified miniport (or newly created port +object, see C). Full ports are configured with the following calls: + =item rcv $portid, tagstring => $callback->(@msg), ... =item rcv $portid, $smartmatch => $callback->(@msg), ... @@ -420,7 +427,8 @@ =cut sub rcv($@) { - my ($noderef, $port) = split /#/, shift, 2; + my $portid = shift; + my ($noderef, $port) = split /#/, $port, 2; ($NODE{$noderef} || add_node $noderef) == $NODE{""} or Carp::croak "$noderef#$port: rcv can only be called on local ports, caught"; @@ -445,6 +453,8 @@ push @{ $self->{any} }, [$cb, $match]; } } + + $portid } =item $closure = psub { BLOCK }