| 1 | package Shell::Carapace::Shell; | ||||||||||
| 2 | 2 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 2 | ▶ | use String::ShellQuote; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | has callback => (is => 'rw', required => 1); | |||||||||
| 8 | 2 | has ipc => (is => 'rw', lazy => 1, builder => 1); | |||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | sub _build_ipc { | ||||||||
|
Subroutine
_build_ipc: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | my $self = shift; | |||||||||
| 12 | 1 | require IPC::Open3::Simple; | |||||||||
| 13 | return IPC::Open3::Simple->new( | ||||||||||
| 14 | 2 | ▶ | out => sub { $self->callback->('local-output', $_[0], 'localhost') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | err => sub { $self->callback->('local-output', $_[0], 'localhost') }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ); | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 3 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 20 | 3 | my ($self, @cmd) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 3 | $self->callback->('command', $self->_stringify(@cmd), 'localhost'); | |||||||||
| 23 | |||||||||||
| 24 | 3 | $self->ipc->run(@cmd); | |||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | if ($? != 0) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 1 | $self->callback->("error", $self->_stringify(@cmd), 'localhost'); | |||||||||
| 28 | 1 | croak "cmd failed"; | |||||||||
| 29 | } | ||||||||||
| 30 | }; | ||||||||||
| 31 | |||||||||||
| 32 | 4 | ▶ | sub _stringify { | ||||||||
|
Subroutine
_stringify: called CC=2 SCAR=6.9
| |||||||||||
| 33 | 4 | my ($self, @cmd) = @_; | |||||||||
| 34 | 4 | ▶ | return $cmd[0] if @cmd == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 35 | 3 | return join(" ", shell_quote @cmd); | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | 2 | 1; | |||||||||