| 1 | package IO::Concurrent::Context; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | sub new { | ||
| 6 | my ($class, $handler, $actors) = @_; | ||
| 7 | return bless { | ||
| 8 | handler => $handler, | ||
| 9 | phase => 0, | ||
| 10 | actors => $actors, | ||
| 11 | error => undef, | ||
| 12 | }, $class; | ||
| 13 | } | ||
| 14 | |||
| 15 | sub handler { shift->{handler} } | ||
| 16 | sub error { shift->{error} } | ||
| 17 | |||
| 18 | sub complete { shift->{completed} = 1 } | ||
| 19 | sub is_completed { shift->{completed} } | ||
| 20 | |||
| 21 | sub abort { | ||
| 22 | my ($self, $err) = @_; | ||
| 23 | $self->{error} = $err; | ||
| 24 | $self->{completed} = 1; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub next :method { shift->{phase}++ } | ||
| 28 | sub back { shift->{phase}-- } | ||
| 29 | |||
| 30 | sub current_actor { $_[0]->{actors}->[$_[0]->{phase}] } | ||
| 31 | |||
| 32 | 1; | ||
| 33 | __END__ |