File Coverage

blib/lib/Shell/Carapace/Shell.pm
Criterion Covered Total %
statement 23 23 100.0
branch 4 4 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 35 36 97.2


line stmt bran cond sub pod time code
1             package Shell::Carapace::Shell;
2 2     2   1024 use Moo;
  2         14  
  2         15  
3              
4 2     2   2022 use String::ShellQuote;
  2         1687  
  2         126  
5 2     2   10 use Carp;
  2         3  
  2         633  
6              
7             has callback => (is => 'rw', required => 1);
8             has ipc => (is => 'rw', lazy => 1, builder => 1);
9              
10             sub _build_ipc {
11 1     1   426 my $self = shift;
12 1         854 require IPC::Open3::Simple;
13             return IPC::Open3::Simple->new(
14 2     2   36521 out => sub { $self->callback->('local-output', $_[0], 'localhost') },
15 1     1   49928 err => sub { $self->callback->('local-output', $_[0], 'localhost') },
16 1         61570 );
17             }
18              
19             sub run {
20 3     3 0 5387 my ($self, @cmd) = @_;
21              
22 3         12 $self->callback->('command', $self->_stringify(@cmd), 'localhost');
23              
24 3         6983 $self->ipc->run(@cmd);
25              
26 3 100       6104 if ($? != 0) {
27 1         32 $self->callback->("error", $self->_stringify(@cmd), 'localhost');
28 1         1518 croak "cmd failed";
29             }
30             };
31              
32             sub _stringify {
33 4     4   22 my ($self, @cmd) = @_;
34 4 100       33 return $cmd[0] if @cmd == 1;
35 3         21 return join(" ", shell_quote @cmd);
36             }
37              
38             1;