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   1004 use Moo;
  2         16  
  2         13  
3              
4 2     2   2050 use String::ShellQuote;
  2         1704  
  2         122  
5 2     2   10 use Carp;
  2         4  
  2         647  
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   439 my $self = shift;
12 1         821 require IPC::Open3::Simple;
13             return IPC::Open3::Simple->new(
14 2     2   19810 out => sub { $self->callback->('local-output', $_[0], 'localhost') },
15 1     1   54845 err => sub { $self->callback->('local-output', $_[0], 'localhost') },
16 1         15355 );
17             }
18              
19             sub run {
20 3     3 0 4267 my ($self, @cmd) = @_;
21              
22 3         12 $self->callback->('command', $self->_stringify(@cmd), 'localhost');
23              
24 3         6612 $self->ipc->run(@cmd);
25              
26 3 100       5164 if ($? != 0) {
27 1         25 $self->callback->("error", $self->_stringify(@cmd), 'localhost');
28 1         890 croak "cmd failed";
29             }
30             };
31              
32             sub _stringify {
33 4     4   14 my ($self, @cmd) = @_;
34 4 100       26 return $cmd[0] if @cmd == 1;
35 3         19 return join(" ", shell_quote @cmd);
36             }
37              
38             1;