1Proc::Guard(3) User Contributed Perl Documentation Proc::Guard(3)
2
3
4
6 Proc::Guard - process runner with RAII pattern
7
9 use Test::TCP qw/empty_port wait_port/;
10 use File::Which qw/which/;
11 use Proc::Guard;
12
13 my $port = empty_port();
14 my $proc = proc_guard(scalar(which('memcached')), '-p', $port);
15 wait_port($port);
16
17 # your code here
18
19 # --------------
20 # or, use perl code
21 my $proc = proc_guard(sub {
22 ... # run this code in child process
23 });
24 ...
25
27 Proc::Guard runs process, and destroys it when the perl script exits.
28
29 This is useful for testing code working with server process.
30
32 proc_guard(@cmdline|\&code)
33 This is shorthand for:
34
35 Proc::Guard->new(
36 command => \@cmdline,
37 );
38
39 or
40
41 Proc::Guard->new(
42 code => \&code,
43 );
44
46 my $proc = Proc::Guard->new(%args);
47 Create and run a process. The process is terminated when the
48 returned object is being DESTROYed.
49
50 command
51 Proc::Guard->new(command => '/path/to/memcached');
52 # or
53 Proc::Guard->new(command => ['/path/to/memcached', '-p', '11211']);
54
55 The command line.
56
57 code
58 Proc::Guard->new(code => sub { ... });
59
60 'code' or 'command' is required.
61
62 auto_start
63 Proc::Guard->new(auto_start => 0);
64
65 Start child process automatically or not(default: 1).
66
67 pid Returns process id (or undef if not running).
68
69 start
70 Starts process.
71
72 stop
73 Stops process.
74
76 $Proc::Guard::EXIT_STATUS
77 The last exit status code by "$proc->stop". If "waitpid" failed
78 with an error, this will be set to "undef".
79
81 Tokuhiro Matsuno <tokuhirom AAJKLFJEF GMAIL COM>
82
84 Copyright (C) Tokuhiro Matsuno
85
86 This library is free software; you can redistribute it and/or modify it
87 under the same terms as Perl itself.
88
89
90
91perl v5.32.0 2020-07-28 Proc::Guard(3)