File Coverage

blib/lib/BeamerReveal/IPC/Run.pm
Criterion Covered Total %
statement 12 40 30.0
branch 0 14 0.0
condition n/a
subroutine 4 6 66.6
pod 1 2 50.0
total 17 62 27.4


line stmt bran cond sub pod time code
1             # -*- cperl -*-
2             # ABSTRACT: IPC::Run
3              
4              
5             package BeamerReveal::IPC::Run;
6             our $VERSION = '20260208.1851'; # VERSION
7              
8 1     1   7 use strict;
  1         2  
  1         40  
9 1     1   5 use warnings;
  1         3  
  1         59  
10              
11 1     1   1140 use IPC::Run qw(harness start pump finish);
  1         59553  
  1         92  
12              
13 1     1   642 use File::chdir;
  1         4255  
  1         642  
14              
15              
16             sub run {
17 0     0 1   my ( $cmd, $coreId, $indent, $dir, $errormessage ) = @_;
18 0           my ( $out, $err );
19              
20 0           my $logger = $BeamerReveal::Log::logger;
21            
22 0           my $r;
23 0           eval {
24 0 0         if( defined $dir ) {
25 0           local $CWD = $dir;
26 0           $r = IPC::Run::run( $cmd, \undef, \$out, \$err );
27             }
28             else {
29 0           $r = IPC::Run::run( $cmd, \undef, \$out, \$err );
30             }
31             };
32            
33 0 0         if ( !defined( $r ) ) {
34 0           $logger->fatal( "Error: $@\n" );
35             }
36             else {
37 0 0         if ( $r ) {
38 0           $logger->log( $indent, "- $cmd->[0] run in thread no $coreId finished" );
39             }
40             else {
41 0           $logger->fatal( $errormessage );
42             }
43             }
44             }
45              
46             sub runsmart {
47 0     0 0   my ( $cmd, $mode, $regexp, $subroutine, $coreId, $indent, $dir, $errormessage ) = @_;
48 0           my ( $in, $out, $err ) = ( '', undef, undef );
49              
50             # the stream to read the progress info from is set by $mode
51 0 0         my $progress = ( $mode == 2 ) ? \$err : \$out;
52              
53             # get the logger
54 0           my $logger = $BeamerReveal::Log::logger;
55              
56             # run the process until finish
57 0 0         local $CWD = $dir if defined( $dir );
58 0           my $h = harness $cmd, \$in, \$out, \$err;
59 0           start $h;
60 0           while( $h->pumpable ) {
61 0           pump $h;
62 0           my @matches = $$progress =~ $regexp;
63 0 0         if ( scalar @matches ) {
64 0           $subroutine->( @matches );
65 0           $$progress = '';
66             }
67             }
68 0 0         finish $h or $logger->fatal( $errormessage );
69             }
70              
71             1;
72              
73             __END__