1Test2::Harness::Util::IUPsCe(r3)Contributed Perl DocumenTteastti2o:n:Harness::Util::IPC(3)
2
3
4

NAME

6       Test2::Harness::Util::IPC - Utilities for IPC management.
7

DESCRIPTION

9       This package provides low-level IPC tools for Test2::Harness.
10

EXPORTS

12       All exports are optional and must be specified at import time.
13
14       $bool = USE_P_GROUPS()
15           This is a shortcut for:
16
17               use Config qw/%Config/;
18               $Config{'d_setpgrp'};
19
20       swap_io($from, $to)
21       swap_io($from, $to, \&die)
22           This will close and re-open the file handle designated by $from so
23           that it redirects to the handle specified in $to. It preserves the
24           file descriptor in the process, and throws an exception if it fails
25           to do so.
26
27               swap_io(\*STDOUT, $fh);
28               # STDOUT now points to wherever $fh did, but maintains the file descriptor number '2'.
29
30           As long as the file descriptor is greater than 0 it will open for
31           writing. If the descriptor is 0 it will open for reading, allowing
32           for a swap of "STDIN" as well.
33
34           Extra effort is made to insure errors go to the real "STDERR",
35           specially when trying to swap out "STDERR". If you have trouble
36           with this, or do not trust it, you can provide a custom coderef as
37           a third argument, this coderef will be used instead of "die()" to
38           throw exceptions.
39
40           Note that the custom die logic when you do not provide your own
41           bypasses the exception catching mechanism and will exit your
42           program. If this is not desirable then you should provide a custom
43           die subref.
44
45       $pid = run_cmd(command => [...], %params)
46           This function will run the specified command and return a pid to
47           you. When possible this will be done via "fork()" and "exec()".
48           When that is not possible it uses the "system(1, ...)" trick to
49           spawn a new process. Some parameters do not work in the second
50           case, and are silently ignored.
51
52           Parameters:
53
54           command => [$command, sub { ... }, @args]
55           command => sub { return ($command, @args) }
56               This parameter is required. This should either be an arrayref
57               of arguments for "exec()", or a coderef that returns a list of
58               arguments for "exec()". On systems without fork/exec the
59               arguments will be passed to "system(1, $command, @args)"
60               instead.
61
62               If the command arrayref has a coderef in it, the coderef will
63               be run and its return value(s) will be inserted in its place.
64               This replacement happens post-chroot
65
66           run_in_parent => [sub { ... }, sub { ... }]
67               An arrayref of callbacks to be run in the parent process
68               immedietly after the child process is started.
69
70           run_in_child => [sub { ... }, sub { ... }]
71               An arrayref of callbacks to be run in the child process
72               immedietly after fork.  This parameter is silently ignored on
73               systems without fork/exec.
74
75           env => { ENVVAR => $VAL, ... }
76               A hashref of custom environment variables to set in the child
77               process. In the fork/exec model this is done post-fork, in the
78               spawn model this is done via local prior to the spawn.
79
80           no_set_pgrp => $bool,
81               Normall "setpgrp(0,0)" is called on systems where it is
82               supported. You can use this parameter to override the normal
83               behavior. setpgrp() is not called in the spawn model, so this
84               parameter is silently ignored there.
85
86           chdir => 'path/to/dir'
87           ch_dir => 'path/to/dir'
88               chdir() to the specified directory for the new process. In the
89               fork/exec model this is done post-fork in the child. In the
90               spawn model this is done before the spawn, then a second
91               chdir() puts the parent process back to its original dir after
92               the spawn.
93
94           stdout => $handle
95           stderr => $handle
96           stdin  => $handle
97               Thise can be used to provide custom STDERR, STDOUT, and STDIN.
98               In the fork/exec model these are swapped into place post-fork
99               in the child. In the spawn model the swap occurs pre-spawn,
100               then the old handles are swapped back post-spawn.
101

SOURCE

103       The source code repository for Test2-Harness can be found at
104       http://github.com/Test-More/Test2-Harness/.
105

MAINTAINERS

107       Chad Granum <exodist@cpan.org>
108

AUTHORS

110       Chad Granum <exodist@cpan.org>
111
113       Copyright 2020 Chad Granum <exodist7@gmail.com>.
114
115       This program is free software; you can redistribute it and/or modify it
116       under the same terms as Perl itself.
117
118       See http://dev.perl.org/licenses/
119
120
121
122perl v5.34.0                      2021-11-05      Test2::Harness::Util::IPC(3)
Impressum