… | |
… | |
84 | |
84 | |
85 | use base "Exporter"; |
85 | use base "Exporter"; |
86 | |
86 | |
87 | our $VERSION = '0.02'; |
87 | our $VERSION = '0.02'; |
88 | our @EXPORT = qw( |
88 | our @EXPORT = qw( |
89 | NODE $NODE $PORT snd rcv _any_ |
89 | NODE $NODE $PORT snd rcv mon del _any_ |
90 | create_port create_port_on |
90 | create_port create_port_on |
91 | create_miniport |
91 | create_miniport |
92 | become_slave become_public |
92 | become_slave become_public |
93 | ); |
93 | ); |
94 | |
94 | |
… | |
… | |
117 | The type of data you can transfer depends on the transport protocol: when |
117 | The type of data you can transfer depends on the transport protocol: when |
118 | JSON is used, then only strings, numbers and arrays and hashes consisting |
118 | JSON is used, then only strings, numbers and arrays and hashes consisting |
119 | of those are allowed (no objects). When Storable is used, then anything |
119 | of those are allowed (no objects). When Storable is used, then anything |
120 | that Storable can serialise and deserialise is allowed, and for the local |
120 | that Storable can serialise and deserialise is allowed, and for the local |
121 | node, anything can be passed. |
121 | node, anything can be passed. |
|
|
122 | |
|
|
123 | =item mon $portid, sub { } |
|
|
124 | |
|
|
125 | #TODO monitor the given port |
|
|
126 | |
|
|
127 | =cut |
|
|
128 | |
|
|
129 | sub mon { |
|
|
130 | my ($noderef, $port) = split /#/, shift, 2; |
|
|
131 | |
|
|
132 | my $node = AnyEvent::MP::Base::add_node $noderef; |
|
|
133 | |
|
|
134 | my $cb = shift; |
|
|
135 | |
|
|
136 | $node->monitor ($port, $cb); |
|
|
137 | |
|
|
138 | defined wantarray |
|
|
139 | and AnyEvent::Util::guard { $node->unmonitor ($port, $cb) } |
|
|
140 | } |
122 | |
141 | |
123 | =item $local_port = create_port |
142 | =item $local_port = create_port |
124 | |
143 | |
125 | Create a new local port object. See the next section for allowed methods. |
144 | Create a new local port object. See the next section for allowed methods. |
126 | |
145 | |
… | |
… | |
206 | =cut |
225 | =cut |
207 | |
226 | |
208 | use overload |
227 | use overload |
209 | '""' => sub { $_[0]{id} }, |
228 | '""' => sub { $_[0]{id} }, |
210 | fallback => 1; |
229 | fallback => 1; |
|
|
230 | |
|
|
231 | sub TO_JSON { $_[0]{id} } |
211 | |
232 | |
212 | =item $port->rcv (type => $callback->($port, @msg)) |
233 | =item $port->rcv (type => $callback->($port, @msg)) |
213 | |
234 | |
214 | =item $port->rcv ($smartmatch => $callback->($port, @msg)) |
235 | =item $port->rcv ($smartmatch => $callback->($port, @msg)) |
215 | |
236 | |
… | |
… | |
275 | =cut |
296 | =cut |
276 | |
297 | |
277 | sub destroy { |
298 | sub destroy { |
278 | my ($self) = @_; |
299 | my ($self) = @_; |
279 | |
300 | |
|
|
301 | AnyEvent::MP::Base::del $self->{id}; |
|
|
302 | |
280 | delete $AnyEvent::MP::Base::WKP{ $self->{wkname} }; |
303 | delete $AnyEvent::MP::Base::WKP{ $self->{wkname} }; |
281 | |
304 | |
282 | delete $AnyEvent::MP::Base::PORT{$_} |
305 | delete $AnyEvent::MP::Base::PORT{$_} |
283 | for @{ $self->{names} }; |
306 | for @{ $self->{names} }; |
284 | } |
307 | } |