| 1 | # -*- cperl -*- | ||||||||||
| 2 | # ABSTRACT: IPC::Run | ||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | package BeamerReveal::IPC::Run; | ||||||||||
| 6 | 1 | our $VERSION = '20261115.1249'; # VERSION | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use IPC::Run qw(harness start pump finish); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use File::chdir; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 17 | 0 | 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 | ▶ | if( defined $dir ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | if ( !defined( $r ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $logger->fatal( "Error: $@\n" ); | |||||||||
| 35 | } | ||||||||||
| 36 | else { | ||||||||||
| 37 | 0 | ▶ | if ( $r ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | 0 | ▶ | sub runsmart { | ||||||||
|
Subroutine
runsmart: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||
| 47 | 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 | ▶ | my $progress = ( $mode == 2 ) ? \$err : \$out; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | |||||||||||
| 53 | # get the logger | ||||||||||
| 54 | 0 | my $logger = $BeamerReveal::Log::logger; | |||||||||
| 55 | |||||||||||
| 56 | # run the process until finish | ||||||||||
| 57 | 0 | ▶ | local $CWD = $dir if defined( $dir ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | my $h = harness $cmd, \$in, \$out, \$err; | |||||||||
| 59 | 0 | start $h; | |||||||||
| 60 | 0 | ▶ | while( $h->pumpable ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | pump $h; | |||||||||
| 62 | 0 | my @matches = $$progress =~ $regexp; | |||||||||
| 63 | 0 | ▶ | if ( scalar @matches ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 0 | $subroutine->( @matches ); | |||||||||
| 65 | 0 | $$progress = ''; | |||||||||
| 66 | } | ||||||||||
| 67 | } | ||||||||||
| 68 | 0 | ▶ | finish $h or $logger->fatal( $errormessage ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 1 | 1; | |||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||