AnyEvent-Subprocess

 view release on metacpan or  search on metacpan

lib/AnyEvent/Subprocess/DefaultDelegates.pm  view on Meta::CPAN

    my $args = shift || {};
    confess 'need handle' unless $args->{handle};
    $args->{name} ||= $args->{handle} . '_capture';

    return AnyEvent::Subprocess::Job::Delegate::CaptureHandle->new(%$args);
});

register_delegate( 'MonitorHandle' => sub {
    my $args = shift || {};
    confess 'need handle' unless $args->{handle};
    confess 'need callbacks' unless $args->{callbacks} || $args->{callback};

    my $handle = $args->{handle};
    $args->{name} ||= $handle . '_monitor';

    $args->{callbacks} ||= $args->{callback};
    delete $args->{callback};

    return AnyEvent::Subprocess::Job::Delegate::MonitorHandle->new(%$args);
});

register_delegate('PrintError' => sub {
    my $args = shift || {};
    $args->{name} ||= 'error_printer';

    return AnyEvent::Subprocess::Job::Delegate::PrintError->new(%$args);

lib/AnyEvent/Subprocess/Job/Delegate/Callback.pm  view on Meta::CPAN

package AnyEvent::Subprocess::Job::Delegate::Callback;
BEGIN {
  $AnyEvent::Subprocess::Job::Delegate::Callback::VERSION = '1.102912';
}
# ABSTRACT: call callbacks for each job/run/done step
use AnyEvent::Subprocess::Running::Delegate::Callback;
use Moose;
use MooseX::StrictConstructor;

with 'AnyEvent::Subprocess::Job::Delegate';

for my $a (qw/child_setup_hook child_finalize_hook
              parent_setup_hook parent_finalize_hook
              completion_hook build_code_args receive_child_result
              receive_child_error/) {

lib/AnyEvent/Subprocess/Job/Delegate/Callback.pm  view on Meta::CPAN


1;

__PACKAGE__->meta->make_immutable;

__END__
=pod

=head1 NAME

AnyEvent::Subprocess::Job::Delegate::Callback - call callbacks for each job/run/done step

=head1 VERSION

version 1.102912

=head1 AUTHOR

Jonathan Rockway <jrockway@cpan.org>

=head1 COPYRIGHT AND LICENSE

lib/AnyEvent/Subprocess/Job/Delegate/MonitorHandle.pm  view on Meta::CPAN

package AnyEvent::Subprocess::Job::Delegate::MonitorHandle;
BEGIN {
  $AnyEvent::Subprocess::Job::Delegate::MonitorHandle::VERSION = '1.102912';
}
# ABSTRACT: monitor a handle for input and invoke callbacks with that input
use AnyEvent::Subprocess::Running::Delegate::MonitorHandle;
use AnyEvent::Subprocess::Types qw(CodeList WhenToCallBack);
use MooseX::Types::Moose qw(Str);

use Moose;
use namespace::autoclean;

with 'AnyEvent::Subprocess::Job::Delegate';

has 'handle' => (
    is       => 'ro',
    isa      => Str,
    required => 1,
);

has 'callbacks' => (
    traits     => ['Array'],
    is         => 'ro',
    isa        => CodeList,
    required   => 1,
    coerce     => 1,
    auto_deref => 1,
    handles    => {
        add_callback => 'push',
    },
);

lib/AnyEvent/Subprocess/Job/Delegate/MonitorHandle.pm  view on Meta::CPAN

);

sub parent_setup_hook {
    my ($self, $job, $run) = @_;

    my $handle = $run->delegate($self->handle)->handle;

    if($self->when eq 'Line'){
        my $reader; $reader = sub {
            my ($h, $l, $eol) = @_;
            $self->_run_callbacks($l, $eol);
            $h->push_read(line => $reader);
        };
        $handle->push_read(line => $reader);
    }
    else {
        $handle->on_read( sub {
            my $h = shift;
            $self->_run_callbacks( delete $h->{rbuf} );
            return;
        });
    }

    return;
}

sub _run_callbacks {
    my $self = shift;

    for my $cb ($self->callbacks){
        $cb->(@_);
    }

    return;
}

sub build_run_delegates {
    my $self = shift;
    return AnyEvent::Subprocess::Running::Delegate::MonitorHandle->new(
        name          => $self->name,

lib/AnyEvent/Subprocess/Job/Delegate/MonitorHandle.pm  view on Meta::CPAN

__PACKAGE__->meta->make_immutable;

1;



=pod

=head1 NAME

AnyEvent::Subprocess::Job::Delegate::MonitorHandle - monitor a handle for input and invoke callbacks with that input

=head1 VERSION

version 1.102912

=head1 DESCRIPTION

Monitors a handle for input, and calls a list of coderefs when there is input.  The coderefs get the input.

=head1 INITARGS

=head2 name

The name of the delegate that has the filehandle you want to monitor.

=head2 callbacks

ArrayRef[CodeRef]s to call with input.

=head2 when

'Line' to be called with each line, something else to be called
whenever there is data in the read buffer.

=head1 METHODS

lib/AnyEvent/Subprocess/Running/Delegate/MonitorHandle.pm  view on Meta::CPAN

}
# ABSTRACT: Running part of the MonitorHandle delegate
use Moose;
use namespace::clean;

with 'AnyEvent::Subprocess::Running::Delegate';

has '_job_delegate' => (
    is       => 'ro',
    isa      => 'AnyEvent::Subprocess::Job::Delegate::MonitorHandle',
    handles  => ['_run_callbacks'],
    required => 1,
);

sub build_events {}
sub build_done_delegates {}

sub completion_hook {
    my ($self, $running, $args) = @_;

    my $leftover =
      delete $args->{run}->delegate($self->_job_delegate->handle)->handle->{rbuf};

    $self->_run_callbacks( $leftover ) if $leftover;
}

__PACKAGE__->meta->make_immutable;

1;

__END__
=pod

=head1 NAME



( run in 0.698 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )