AnyEvent::Subprocess::Running::Delegate - delegate on the running process class


AnyEvent-Subprocess documentation Contained in the AnyEvent-Subprocess distribution.

Index


Code Index:

NAME

Top

AnyEvent::Subprocess::Running::Delegate - delegate on the running process class

VERSION

Top

version 1.102912

REQUIRED METHODS

Top

Delegates must implement these methods:

build_events

Return a list of events that need to be sent before the run will be considered complete

build_done_delegates

Return a list of delegates to be passed to the "done" instance.

completion_hook

Called after all events are received but before calling the final on_complete method.

METHODS

Top

event_sender_for($name)

Returns the event sender coderef for the event named $name. $name should have been returned by build_events, otherwise this will break.

send_event($name, $value)

Method that works like calling the coderef returned by event_sender_for($name).

AUTHOR

Top

Jonathan Rockway <jrockway@cpan.org>

COPYRIGHT AND LICENSE

Top


AnyEvent-Subprocess documentation Contained in the AnyEvent-Subprocess distribution.

package AnyEvent::Subprocess::Running::Delegate;
BEGIN {
  $AnyEvent::Subprocess::Running::Delegate::VERSION = '1.102912';
}
# ABSTRACT: delegate on the running process class
use Moose::Role;

with 'AnyEvent::Subprocess::Delegate';

has 'event_senders' => (
    is        => 'rw',
    isa       => 'HashRef',
    predicate => 'has_event_senders',
);

# you can call this before event_senders are vivified
sub event_sender_for {
    my ($self, $event) = @_;
    return sub {
        my $val = shift;
        $self->send_event($event, $val);
    }
}

sub send_event {
    my ($self, $event, $value) = @_;
    confess "No event senders set yet!"
      unless $self->has_event_senders;
    my $sender = $self->event_senders->{$event};
    confess "No event sender '$event' found"
      unless $sender && ref $sender;

    $sender->($value);
    return;
}

requires 'build_events';
requires 'build_done_delegates';
requires 'completion_hook';

1;




__END__