Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit fb9f0ac

Browse files
committed
IPC::Cmd Udpate to 0.98
Enhancements: Added wait_loop_callback for run_forked() Bug fixes: Only search in curdir in can_run() when on Win32 RT#105601
1 parent d51f78c commit fb9f0ac

File tree

6 files changed

+67
-39
lines changed

6 files changed

+67
-39
lines changed

Porting/Maintainers.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ package Maintainers;
869869
},
870870

871871
'IPC::Cmd' => {
872-
'DISTRIBUTION' => 'BINGOS/IPC-Cmd-0.96.tar.gz',
872+
'DISTRIBUTION' => 'BINGOS/IPC-Cmd-0.98.tar.gz',
873873
'FILES' => q[cpan/IPC-Cmd],
874874
},
875875

cpan/IPC-Cmd/lib/IPC/Cmd.pm

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ BEGIN {
1818
$HAVE_MONOTONIC
1919
];
2020

21-
$VERSION = '0.96';
21+
$VERSION = '0.98';
2222
$VERBOSE = 0;
2323
$DEBUG = 0;
2424
$WARN = 1;
@@ -242,7 +242,7 @@ sub can_run {
242242
} else {
243243
for my $dir (
244244
File::Spec->path,
245-
File::Spec->curdir
245+
( IS_WIN32 ? File::Spec->curdir : () )
246246
) {
247247
next if ! $dir || ! -d $dir;
248248
my $abs = File::Spec->catfile( IS_WIN32 ? Win32::GetShortPathName( $dir ) : $dir, $command);
@@ -742,6 +742,29 @@ STDOUT from the executing program.
742742
Coderef of a subroutine to call when a portion of data is received on
743743
STDERR from the executing program.
744744
745+
=item C<wait_loop_callback>
746+
747+
Coderef of a subroutine to call inside of the main waiting loop
748+
(while C<run_forked> waits for the external to finish or fail).
749+
It is useful to stop running external process before it ends
750+
by itself, e.g.
751+
752+
my $r = run_forked("some external command", {
753+
'wait_loop_callback' => sub {
754+
if (condition) {
755+
kill(1, $$);
756+
}
757+
},
758+
'terminate_on_signal' => 'HUP',
759+
});
760+
761+
Combined with C<stdout_handler> and C<stderr_handler> allows terminating
762+
external command based on its output. Could also be used as a timer
763+
without engaging with L<alarm> (signals).
764+
765+
Remember that this code could be called every millisecond (depending
766+
on the output which external command generates), so try to make it
767+
as lightweight as possible.
745768
746769
=item C<discard_output>
747770
@@ -1075,6 +1098,10 @@ sub run_forked {
10751098
push @{$ready_fds}, $select->can_read(1/100) if $child_finished;
10761099
}
10771100

1101+
if ($opts->{'wait_loop_callback'} && ref($opts->{'wait_loop_callback'}) eq 'CODE') {
1102+
$opts->{'wait_loop_callback'}->();
1103+
}
1104+
10781105
Time::HiRes::usleep(1);
10791106
}
10801107

cpan/IPC-Cmd/t/01_IPC-Cmd.t

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ local $IPC::Cmd::DEBUG = $Verbose;
3232

3333
### run tests in various configurations, based on what modules we have
3434
my @Prefs = ( );
35-
push @Prefs, [ $Have_IPC_Run, $Have_IPC_Open3 ] if $Have_IPC_Run;
35+
push @Prefs, [ $Have_IPC_Run, $Have_IPC_Open3 ] if $Have_IPC_Run;
3636

3737
### run this config twice to ensure FD restores work properly
38-
push @Prefs, [ 0, $Have_IPC_Open3 ],
38+
push @Prefs, [ 0, $Have_IPC_Open3 ],
3939
[ 0, $Have_IPC_Open3 ] if $Have_IPC_Open3;
4040

4141
### run this config twice to ensure FD restores work properly
4242
### these are the system() tests;
43-
push @Prefs, [ 0, 0 ], [ 0, 0 ];
43+
push @Prefs, [ 0, 0 ], [ 0, 0 ];
4444

4545

4646
### can_run tests
@@ -49,7 +49,7 @@ push @Prefs, [ 0, 0 ], [ 0, 0 ];
4949
ok( !can_run('10283lkjfdalskfjaf'), q[Not found non-existent binary] );
5050
}
5151

52-
{ ### list of commands and regexes matching output
52+
{ ### list of commands and regexes matching output
5353
### XXX use " everywhere when using literal strings as commands for
5454
### portability, especially on win32
5555
my $map = [
@@ -61,7 +61,7 @@ push @Prefs, [ 0, 0 ], [ 0, 0 ];
6161

6262
### pipes
6363
[ "$^X -eprint+424 | $^X -neprint+split+2", qr/44/, 3, ],
64-
[ [$^X,qw[-eprint+424 |], $^X, qw|-neprint+split+2|],
64+
[ [$^X,qw[-eprint+424 |], $^X, qw|-neprint+split+2|],
6565
qr/44/, 3, ],
6666
### whitespace
6767
[ [$^X, '-eprint+shift', q|a b a|], qr/a b a/, 3, ],
@@ -80,16 +80,16 @@ push @Prefs, [ 0, 0 ], [ 0, 0 ];
8080

8181
### extended test in developer mode
8282
### test if gzip | tar works
83-
if( $Verbose ) {
83+
if( $Verbose ) {
8484
my $gzip = can_run('gzip');
8585
my $tar = can_run('tar');
86-
86+
8787
if( $gzip and $tar ) {
8888
push @$map,
89-
[ [$gzip, qw[-cdf src/x.tgz |], $tar, qw[-tf -]],
89+
[ [$gzip, qw[-cdf src/x.tgz |], $tar, qw[-tf -]],
9090
qr/a/, 3, ];
9191
}
92-
}
92+
}
9393

9494
### for each configuration
9595
for my $pref ( @Prefs ) {
@@ -109,27 +109,23 @@ push @Prefs, [ 0, 0 ], [ 0, 0 ];
109109
$pp_cmd .= " (IPC::Run: $pref->[0] IPC::Open3: $pref->[1])";
110110

111111
diag( "Running '$pp_cmd'") if $Verbose;
112-
sleep(0.3) if $^O eq 'MSWin32';
113-
sleep(2) if $ENV{APPVEYOR};
114112

115113
### in scalar mode
116114
{ my $buffer;
117115
my $ok = run( command => $cmd, buffer => \$buffer );
118116

119117
ok( $ok, "Ran '$pp_cmd' command successfully" );
120-
118+
121119
SKIP: {
122-
skip "No buffers available", 1
123-
unless $Class->can_capture_buffer;
124-
skip "Appveyor failure", 1
125-
if $^O eq 'MSWin32' and $ENV{APPVEYOR} and $buffer !~ $regex;
126-
127-
like( $buffer, $regex,
120+
skip "No buffers available", 1
121+
unless $Class->can_capture_buffer;
122+
123+
like( $buffer, $regex,
128124
" Buffer matches $regex -- ($pp_cmd)" );
129125
}
130126
}
131-
132-
### in list mode
127+
128+
### in list mode
133129
{ diag( "Running list mode" ) if $Verbose;
134130
my @list = run( command => $cmd );
135131

@@ -141,22 +137,17 @@ push @Prefs, [ 0, 0 ], [ 0, 0 ];
141137
" Output list has $list_length entries -- ($pp_cmd)" );
142138

143139
SKIP: {
144-
skip "No buffers available", 6
140+
skip "No buffers available", 6
145141
unless $Class->can_capture_buffer;
146-
142+
147143
### the last 3 entries from the RV, are they array refs?
148144
isa_ok( $list[$_], 'ARRAY' ) for 2..4;
149-
# flapping tests on Appveyor CI (~20%)
150-
if ($ENV{APPVEYOR} and "@{$list[2]}" !~ $regex) {
151-
ok(1, "SKIP empty pp_cmd APPVEYOR (too short sleep)");
152-
ok(1, "SKIP empty pp_cmd APPVEYOR");
153-
} else {
154-
like( "@{$list[2]}", $regex,
145+
146+
like( "@{$list[2]}", $regex,
155147
" Combined buffer matches $regex -- ($pp_cmd)" );
156148

157-
like( "@{$list[$index]}", qr/$regex/,
158-
" Proper buffer($index) matches $regex -- ($pp_cmd)" );
159-
}
149+
like( "@{$list[$index]}", qr/$regex/,
150+
" Proper buffer($index) matches $regex -- ($pp_cmd)" );
160151
is( scalar( @{$list[ $index==3 ? 4 : 3 ]} ), 0,
161152
" Other buffer empty -- ($pp_cmd)" );
162153
}
@@ -199,6 +190,7 @@ unless ( IPC::Cmd->can_use_run_forked ) {
199190
ok($out =~ m/err/, "stderr handled");
200191
}
201192

193+
202194
__END__
203195
### special call to check that output is interleaved properly
204196
{ my $cmd = [$^X, File::Spec->catfile( qw[src output.pl] ) ];
@@ -223,10 +215,10 @@ __END__
223215
is( "@{$list[2]}",'1 2 3 4'," Combined output as expected" );
224216
is( "@{$list[3]}", '1 3', " STDOUT as expected" );
225217
is( "@{$list[4]}", '2 4', " STDERR as expected" );
226-
218+
227219
}
228220
}
229-
}
221+
}
230222
}
231223
232224
@@ -244,7 +236,7 @@ __END__
244236
ok( !$ok, "Non-zero exit caught" );
245237
ok( $err, " Error '$err'" );
246238
}
247-
}
239+
}
248240
249241
### timeout tests
250242
{ my $timeout = 1;
@@ -262,5 +254,5 @@ __END__
262254
ok( not(ref($err)), " Error string is not a reference" );
263255
like( $err,qr/^$AClass/," Error '$err' mentions $AClass" );
264256
}
265-
}
257+
}
266258

dist/Module-CoreList/lib/Module/CoreList.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14909,6 +14909,7 @@ our %delta = (
1490914909
'Devel::PPPort' => '3.35_03',
1491014910
'Encode' => '2.89',
1491114911
'ExtUtils::Install' => '2.08',
14912+
'IPC::Cmd' => '0.98',
1491214913
'File::Spec' => '4.68c',
1491314914
'File::Spec::Unix' => '4.68c',
1491414915
'File::Spec::Win32' => '4.68c',

pod/perlcdelta.pod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ Optimisations:
136136

137137
Keep our make -s support
138138

139+
=item L<IPC::Cmd> 0.98
140+
141+
Enhancements:
142+
Added wait_loop_callback for run_forked()
143+
144+
Bug fixes:
145+
Only search in curdir in can_run() when on Win32 RT#105601
146+
139147
=item PathTools 4.68c
140148

141149
getcwd, getdcwd and abs_path have now long path support.

t/porting/customized.dat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Math::BigInt cpan/Math-BigInt/t/sub_mif.t e87738bd15116665c38d9f41b310cfe7fbf6da
9292
Math::BigInt cpan/Math-BigInt/t/upgrade.t 7c15cac7f321ca396648ec45da6389a1283e1546
9393
Math::BigInt cpan/Math-BigInt/t/upgradef.t 06610e9883ce805bcd6543ab959a9826f598eb40
9494
Math::BigInt cpan/Math-BigInt/t/with_sub.t c040328e223df6f56250f5d67dcb2c9a2f23c110
95-
Module::CoreList dist/Module-CoreList/lib/Module/CoreList.pm a29fba440c06e6458a8148447261a841db974849
95+
Module::CoreList dist/Module-CoreList/lib/Module/CoreList.pm 36b3825354d771b949bb764f9ee94c8b04e6d896
9696
Module::CoreList dist/Module-CoreList/lib/Module/CoreList/Utils.pm 988e528336a48333ff9a28fe1197a56a640e3792
9797
Module::Metadata cpan/Module-Metadata/t/lib/GeneratePackage.pm 502ffbe2609947430e6aa1a3df8064b3fef3e086
9898
Net::Domain cpan/libnet/lib/Net/Cmd.pm 70a007c38833667ad47ea8059c37c1b7d1c77b6c

0 commit comments

Comments
 (0)