| 1 | package Net::CLI::Interact::Transport::Wrapper::IPC_Run; | ||
| 2 | { | ||
| 3 | $Net::CLI::Interact::Transport::Wrapper::IPC_Run::VERSION = '2.143070'; | ||
| 4 | } | ||
| 5 | |||
| 6 | use Moo; | ||
| 7 | use Sub::Quote; | ||
| 8 | use MooX::Types::MooseLike::Base qw(ScalarRef InstanceOf); | ||
| 9 | |||
| 10 | extends 'Net::CLI::Interact::Transport::Wrapper::Base'; | ||
| 11 | |||
| 12 | { | ||
| 13 | package # hide from pause | ||
| 14 | Net::CLI::Interact::Transport::Wrapper::Options; | ||
| 15 | use Moo; | ||
| 16 | extends 'Net::CLI::Interact::Transport::Wrapper::Base::Options'; | ||
| 17 | } | ||
| 18 | |||
| 19 | use IPC::Run (); | ||
| 20 | |||
| 21 | has '_in' => ( | ||
| 22 | is => 'rw', | ||
| 23 | isa => ScalarRef, | ||
| 24 | default => sub { \eval "''" }, | ||
| 25 | ); | ||
| 26 | |||
| 27 | # writer for the _in slot | ||
| 28 | sub put { ${ (shift)->_in } .= join '', @_ } | ||
| 29 | |||
| 30 | has '_out' => ( | ||
| 31 | is => 'ro', | ||
| 32 | isa => ScalarRef, | ||
| 33 | default => sub { \eval "''" }, | ||
| 34 | ); | ||
| 35 | |||
| 36 | sub buffer { | ||
| 37 | my $self = shift; | ||
| 38 | return ${ $self->_out } if scalar(@_) == 0; | ||
| 39 | return ${ $self->_out } = shift; | ||
| 40 | } | ||
| 41 | |||
| 42 | # clearer for the _out slot | ||
| 43 | has '_err' => ( | ||
| 44 | is => 'ro', | ||
| 45 | isa => ScalarRef, | ||
| 46 | default => sub { \eval "''" }, | ||
| 47 | ); | ||
| 48 | |||
| 49 | has '_timeout_obj' => ( | ||
| 50 | is => 'lazy', | ||
| 51 | isa => InstanceOf['IPC::Run::Timer'], | ||
| 52 | ); | ||
| 53 | |||
| 54 | sub _build__timeout_obj { return IPC::Run::timeout((shift)->timeout) } | ||
| 55 | |||
| 56 | has '+timeout' => ( | ||
| 57 | trigger => quote_sub(q{(shift)->_timeout_obj->start(shift) if scalar @_ > 1}), | ||
| 58 | ); | ||
| 59 | |||
| 60 | has '+wrapper' => ( | ||
| 61 | isa => InstanceOf['IPC::Run'], | ||
| 62 | handles => ['pump'], | ||
| 63 | ); | ||
| 64 | |||
| 65 | around '_build_wrapper' => sub { | ||
| 66 | my ($orig, $self) = (shift, shift); | ||
| 67 | |||
| 68 | $self->logger->log('transport', 'notice', 'booting IPC::Run harness for', $self->app); | ||
| 69 | $self->$orig(@_); | ||
| 70 | |||
| 71 | return IPC::Run::harness( | ||
| 72 | [$self->app, $self->runtime_options], | ||
| 73 | $self->_in, | ||
| 74 | $self->_out, | ||
| 75 | $self->_err, | ||
| 76 | $self->_timeout_obj, | ||
| 77 | ); | ||
| 78 | }; | ||
| 79 | |||
| 80 | before 'disconnect' => sub { | ||
| 81 | my $self = shift; | ||
| 82 | $self->wrapper->kill_kill(grace => 1); | ||
| 83 | }; | ||
| 84 | |||
| 85 | 1; |