| 1 | package AnyEvent::Subprocess::Job::Delegate::MonitorHandle; | ||||||||||
| 2 | 48 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 48 | $AnyEvent::Subprocess::Job::Delegate::MonitorHandle::VERSION = '1.102912'; | |||||||||
| 4 | } | ||||||||||
| 5 | # ABSTRACT: monitor a handle for input and invoke callbacks with that input | ||||||||||
| 6 | 48 | ▶ | use AnyEvent::Subprocess::Running::Delegate::MonitorHandle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 48 | ▶ | use AnyEvent::Subprocess::Types qw(CodeList WhenToCallBack); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 48 | ▶ | use MooseX::Types::Moose qw(Str); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 48 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 48 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 47 | with 'AnyEvent::Subprocess::Job::Delegate'; | |||||||||
| 14 | |||||||||||
| 15 | 47 | has 'handle' => ( | |||||||||
| 16 | is => 'ro', | ||||||||||
| 17 | isa => Str, | ||||||||||
| 18 | required => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 47 | has 'callbacks' => ( | |||||||||
| 22 | traits => ['Array'], | ||||||||||
| 23 | is => 'ro', | ||||||||||
| 24 | isa => CodeList, | ||||||||||
| 25 | required => 1, | ||||||||||
| 26 | coerce => 1, | ||||||||||
| 27 | auto_deref => 1, | ||||||||||
| 28 | handles => { | ||||||||||
| 29 | add_callback => 'push', | ||||||||||
| 30 | }, | ||||||||||
| 31 | ); | ||||||||||
| 32 | |||||||||||
| 33 | has 'when' => ( | ||||||||||
| 34 | is => 'ro', | ||||||||||
| 35 | isa => WhenToCallBack, | ||||||||||
| 36 | required => 1, | ||||||||||
| 37 | 4 | ▶ | default => sub { 'Line' }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 47 | ); | |||||||||
| 39 | |||||||||||
| 40 | 2 | ▶ | sub parent_setup_hook { | ||||||||
|
Subroutine
parent_setup_hook: called CC=2 SCAR=7.5
Pod
undocumented
| |||||||||||
| 41 | 2 | my ($self, $job, $run) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 2 | my $handle = $run->delegate($self->handle)->handle; | |||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | if($self->when eq 'Line'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 2 | ▶ | my $reader; $reader = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 2 | my ($h, $l, $eol) = @_; | |||||||||
| 48 | 2 | $self->_run_callbacks($l, $eol); | |||||||||
| 49 | 2 | $h->push_read(line => $reader); | |||||||||
| 50 | 2 | }; | |||||||||
| 51 | 2 | $handle->push_read(line => $reader); | |||||||||
| 52 | } | ||||||||||
| 53 | else { | ||||||||||
| 54 | 0 | ▶ | $handle->on_read( sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 55 | 0 | my $h = shift; | |||||||||
| 56 | 0 | $self->_run_callbacks( delete $h->{rbuf} ); | |||||||||
| 57 | 0 | return; | |||||||||
| 58 | 0 | }); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 2 | return; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 3 | ▶ | sub _run_callbacks { | ||||||||
|
Subroutine
_run_callbacks: called CC=2 SCAR=6.9
| |||||||||||
| 65 | 3 | my $self = shift; | |||||||||
| 66 | |||||||||||
| 67 | 3 | for my $cb ($self->callbacks){ | |||||||||
| 68 | 3 | $cb->(@_); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 3 | return; | |||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 2 | ▶ | sub build_run_delegates { | ||||||||
|
Subroutine
build_run_delegates: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 75 | 2 | my $self = shift; | |||||||||
| 76 | 2 | return AnyEvent::Subprocess::Running::Delegate::MonitorHandle->new( | |||||||||
| 77 | name => $self->name, | ||||||||||
| 78 | _job_delegate => $self, | ||||||||||
| 79 | ); | ||||||||||
| 80 | } | ||||||||||
| 81 | |||||||||||
| 82 | 1 | ▶ | sub child_setup_hook {} | ||||||||
|
Subroutine
child_setup_hook: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 83 | 1 | ▶ | sub child_finalize_hook {} | ||||||||
|
Subroutine
child_finalize_hook: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 84 | 1 | ▶ | sub parent_finalize_hook {} | ||||||||
|
Subroutine
parent_finalize_hook: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 85 | 1 | ▶ | sub build_code_args {} | ||||||||
|
Subroutine
build_code_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 86 | 1 | ▶ | sub receive_child_result {} | ||||||||
|
Subroutine
receive_child_result: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 87 | 0 | ▶ | sub receive_child_error {} | ||||||||
|
Subroutine
receive_child_error: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 88 | |||||||||||
| 89 | 47 | __PACKAGE__->meta->make_immutable; | |||||||||
| 90 | |||||||||||
| 91 | 47 | 1; | |||||||||
| 92 | |||||||||||
| 93 | |||||||||||
| 94 | |||||||||||
| 95 | =pod | ||||||||||
| 96 | |||||||||||
| 97 | =head1 NAME | ||||||||||
| 98 | |||||||||||
| 99 | AnyEvent::Subprocess::Job::Delegate::MonitorHandle - monitor a handle for input and invoke callbacks with that input | ||||||||||
| 100 | |||||||||||
| 101 | =head1 VERSION | ||||||||||
| 102 | |||||||||||
| 103 | version 1.102912 | ||||||||||
| 104 | |||||||||||
| 105 | =head1 DESCRIPTION | ||||||||||
| 106 | |||||||||||
| 107 | Monitors a handle for input, and calls a list of coderefs when there is input. The coderefs get the input. | ||||||||||
| 108 | |||||||||||
| 109 | =head1 INITARGS | ||||||||||
| 110 | |||||||||||
| 111 | =head2 name | ||||||||||
| 112 | |||||||||||
| 113 | The name of the delegate that has the filehandle you want to monitor. | ||||||||||
| 114 | |||||||||||
| 115 | =head2 callbacks | ||||||||||
| 116 | |||||||||||
| 117 | ArrayRef[CodeRef]s to call with input. | ||||||||||
| 118 | |||||||||||
| 119 | =head2 when | ||||||||||
| 120 | |||||||||||
| 121 | 'Line' to be called with each line, something else to be called | ||||||||||
| 122 | whenever there is data in the read buffer. | ||||||||||
| 123 | |||||||||||
| 124 | =head1 METHODS | ||||||||||
| 125 | |||||||||||
| 126 | Don't call us, we'll call you. | ||||||||||
| 127 | |||||||||||
| 128 | =head1 AUTHOR | ||||||||||
| 129 | |||||||||||
| 130 | Jonathan Rockway <jrockway@cpan.org> | ||||||||||
| 131 | |||||||||||
| 132 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 133 | |||||||||||
| 134 | This software is copyright (c) 2011 by Jonathan Rockway. | ||||||||||
| 135 | |||||||||||
| 136 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 137 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 138 | |||||||||||
| 139 | =cut | ||||||||||
| 140 | |||||||||||
| 141 | |||||||||||
| 142 | __END__ | ||||||||||