File Coverage

blib/lib/Sys/Async/Virt/Connection/Process.pm
Criterion Covered Total %
statement 32 66 48.4
branch 0 6 0.0
condition n/a
subroutine 11 16 68.7
pod 1 3 33.3
total 44 91 48.3


line stmt bran cond sub pod time code
1             ####################################################################
2             #
3             # This file was generated using XDR::Parse version v1.0.1
4             # and LibVirt version v12.5.0
5             #
6             # Don't edit this file, use the source template instead
7             #
8             # ANY CHANGES HERE WILL BE LOST !
9             #
10             ####################################################################
11              
12              
13 1     1   1230 use v5.26;
  1         4  
14 1     1   4 use warnings;
  1         2  
  1         48  
15 1     1   4 use experimental 'signatures';
  1         2  
  1         5  
16 1     1   111 use Future::AsyncAwait;
  1         1  
  1         6  
17 1     1   43 use Object::Pad ':experimental(inherit_field)';
  1         2  
  1         7  
18              
19             class Sys::Async::Virt::Connection::Process v0.6.5;
20              
21             inherit Sys::Async::Virt::Connection '$_in', '$_out';
22              
23 1     1   297 use Carp qw(croak);
  1         1  
  1         46  
24 1     1   4 use Future::IO;
  1         2  
  1         27  
25 1     1   4 use IO::Handle;
  1         2  
  1         35  
26 1     1   584 use IPC::Open2;
  1         4392  
  1         289  
27 1     1   7 use Log::Any qw($log);
  1         2  
  1         6  
28              
29 1     1   193 use Protocol::Sys::Virt::URI v12.5.0; # imports parse_url
  1         15  
  1         1009  
30              
31 0     0 0   field $_url :param :reader;
  0            
32             field $_pid;
33             field $_exit_f;
34              
35 0     0 0   async method close() {
  0            
  0            
  0            
36 0 0         unless ($_exit_f->is_ready) {
37 0           kill 'TERM', $_pid;
38             }
39             ### TODO: log exit status
40 0           await $_exit_f;
41             }
42              
43 0     0     method _command( $url ) {
  0            
  0            
  0            
44 0           my %c = parse_url( $url );
45 0           my @rv;
46 0 0         if (exists $c{query}->{argv}) {
47 0           @rv = ( $c{query}->{command}, $c{query}->{argv}->@* );
48             }
49             else {
50 0           @rv = ( $c{query}->{command} );
51             }
52 0           return @rv;
53             }
54              
55 0     0 1   async method connect() {
  0            
  0            
  0            
56 0           my @cmd = $self->_command( $_url );
57 0           $log->trace('Connection process command: ' . join(' ', @cmd));
58              
59 0 0         $_pid = open2( $_in, $_out, @cmd )
60             or die "Unable to open external command: $!";
61 0           $_out->autoflush( 1 );
62 0           $_out->blocking( 0 );
63 0           $_in->autoflush( 1 );
64 0           $_in->blocking( 0 );
65 0           $_exit_f = Future::IO->waitpid( $_pid );
66 0     0     $_exit_f->on_ready(sub { $self->_finalize_io });
  0            
67              
68 0           return;
69             }
70              
71             1;
72              
73              
74             __END__