| 1 | package IO::Concurrent::Actor; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | use Carp (); | ||
| 6 | |||
| 7 | use constant { | ||
| 8 | WRITABLE => 'writable', | ||
| 9 | READABLE => 'readable', | ||
| 10 | }; | ||
| 11 | |||
| 12 | sub new { | ||
| 13 | my ($class, $event_type, $callback) = @_; | ||
| 14 | if ($event_type ne WRITABLE && $event_type ne READABLE) { | ||
| 15 | Carp::croak("invalid event type: $event_type"); | ||
| 16 | } | ||
| 17 | |||
| 18 | return bless { | ||
| 19 | event_type => $event_type, | ||
| 20 | callback => $callback, | ||
| 21 | } => $class; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub is_waiting_for_writable { shift->{event_type} eq WRITABLE } | ||
| 25 | sub is_waiting_for_readable { shift->{event_type} eq READABLE } | ||
| 26 | |||
| 27 | sub callback { shift->{callback} } | ||
| 28 | |||
| 29 | 1; | ||
| 30 | __END__ |