Debian Codegraph @

upstream/debian-unstable/man3/Test2::Util.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Test2::Util 3perl"
58 .TH Test2::Util 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Test2::Util \- Tools used by Test2 and friends.
65 .SH DESCRIPTION
66 .IX Header "DESCRIPTION"
67 Collection of tools used by Test2 and friends.
68 .SH EXPORTS
69 .IX Header "EXPORTS"
70 All exports are optional. You must specify subs to import.
71 .ie n .IP "($success, $error) = try { ... }" 4
72 .el .IP "($success, \f(CW$error\fR) = try { ... }" 4
73 .IX Item "($success, $error) = try { ... }"
74 Eval the codeblock, return success or failure, and the error message. This code
75 protects $@ and $!, they will be restored by the end of the run. This code also
76 temporarily blocks \f(CW$SIG\fR{DIE} handlers.
77 .IP "protect { ... }" 4
78 .IX Item "protect { ... }"
79 Similar to try, except that it does not catch exceptions. The idea here is to
80 protect $@ and $! from changes. $@ and $! will be restored to whatever they
81 were before the run so long as it is successful. If the run fails $! will still
82 be restored, but $@ will contain the exception being thrown.
83 .IP CAN_FORK 4
84 .IX Item "CAN_FORK"
85 True if this system is capable of true or pseudo-fork.
86 .IP CAN_REALLY_FORK 4
87 .IX Item "CAN_REALLY_FORK"
88 True if the system can really fork. This will be false for systems where fork
89 is emulated.
90 .IP CAN_THREAD 4
91 .IX Item "CAN_THREAD"
92 True if this system is capable of using threads.
93 .IP USE_THREADS 4
94 .IX Item "USE_THREADS"
95 Returns true if threads are enabled, false if they are not.
96 .IP get_tid 4
97 .IX Item "get_tid"
98 This will return the id of the current thread when threads are enabled,
99 otherwise it returns 0.
100 .ie n .IP "my $file = pkg_to_file($package)" 4
101 .el .IP "my \f(CW$file\fR = pkg_to_file($package)" 4
102 .IX Item "my $file = pkg_to_file($package)"
103 Convert a package name to a filename.
104 .ie n .IP "$string = \fBipc_separator()\fR" 4
105 .el .IP "\f(CW$string\fR = \fBipc_separator()\fR" 4
106 .IX Item "$string = ipc_separator()"
107 Get the IPC separator. Currently this is always the string \f(CW\*(Aq~\*(Aq\fR.
108 .ie n .IP "$string = \fBgen_uid()\fR" 4
109 .el .IP "\f(CW$string\fR = \fBgen_uid()\fR" 4
110 .IX Item "$string = gen_uid()"
111 Generate a unique id (NOT A UUID). This will typically be the process id, the
112 thread id, the time, and an incrementing integer all joined with the
113 \&\f(CWipc_separator()\fR.
114 .Sp
115 These ID's are unique enough for most purposes. For identical ids to be
116 generated you must have 2 processes with the same PID generate IDs at the same
117 time with the same current state of the incrementing integer. This is a
118 perfectly reasonable thing to expect to happen across multiple machines, but is
119 quite unlikely to happen on one machine.
120 .Sp
121 This can fail to be unique if a process generates an id, calls exec, and does
122 it again after the exec and it all happens in less than a second. It can also
123 happen if the systems process id's cycle in less than a second allowing 2
124 different programs that use this generator to run with the same PID in less
125 than a second. Both these cases are sufficiently unlikely. If you need
126 universally unique ids, or ids that are unique in these conditions, look at
127 Data::UUID.
128 .ie n .IP "($ok, $err) = do_rename($old_name, $new_name)" 4
129 .el .IP "($ok, \f(CW$err\fR) = do_rename($old_name, \f(CW$new_name\fR)" 4
130 .IX Item "($ok, $err) = do_rename($old_name, $new_name)"
131 Rename a file, this wraps \f(CWrename()\fR in a way that makes it more reliable
132 cross-platform when trying to rename files you recently altered.
133 .ie n .IP "($ok, $err) = do_unlink($filename)" 4
134 .el .IP "($ok, \f(CW$err\fR) = do_unlink($filename)" 4
135 .IX Item "($ok, $err) = do_unlink($filename)"
136 Unlink a file, this wraps \f(CWunlink()\fR in a way that makes it more reliable
137 cross-platform when trying to unlink files you recently altered.
138 .ie n .IP "($ok, $err) = try_sig_mask { ... }" 4
139 .el .IP "($ok, \f(CW$err\fR) = try_sig_mask { ... }" 4
140 .IX Item "($ok, $err) = try_sig_mask { ... }"
141 Complete an action with several signals masked, they will be unmasked at the
142 end allowing any signals that were intercepted to get handled.
143 .Sp
144 This is primarily used when you need to make several actions atomic (against
145 some signals anyway).
146 .Sp
147 Signals that are intercepted:
148 .RS 4
149 .IP SIGINT 4
150 .IX Item "SIGINT"
151 .PD 0
152 .IP SIGALRM 4
153 .IX Item "SIGALRM"
154 .IP SIGHUP 4
155 .IX Item "SIGHUP"
156 .IP SIGTERM 4
157 .IX Item "SIGTERM"
158 .IP SIGUSR1 4
159 .IX Item "SIGUSR1"
160 .IP SIGUSR2 4
161 .IX Item "SIGUSR2"
162 .RE
163 .RS 4
164 .RE
165 .PD
166 .SH "NOTES && CAVEATS"
167 .IX Header "NOTES && CAVEATS"
168 .IP 5.10.0 4
169 .IX Item "5.10.0"
170 Perl 5.10.0 has a bug when compiled with newer gcc versions. This bug causes a
171 segfault whenever a new thread is launched. Test2 will attempt to detect
172 this, and note that the system is not capable of forking when it is detected.
173 .IP Devel::Cover 4
174 .IX Item "Devel::Cover"
175 Devel::Cover does not support threads. CAN_THREAD will return false if
176 Devel::Cover is loaded before the check is first run.
177 .SH SOURCE
178 .IX Header "SOURCE"
179 The source code repository for Test2 can be found at
180 <https://github.com/Test\-More/test\-more/>.
181 .SH MAINTAINERS
182 .IX Header "MAINTAINERS"
183 .IP "Chad Granum <[email protected]>" 4
184 .IX Item "Chad Granum <[email protected]>"
185 .SH AUTHORS
186 .IX Header "AUTHORS"
187 .PD 0
188 .IP "Chad Granum <[email protected]>" 4
189 .IX Item "Chad Granum <[email protected]>"
190 .IP "Kent Fredric <[email protected]>" 4
191 .IX Item "Kent Fredric <[email protected]>"
192 .PD
193 .SH COPYRIGHT
194 .IX Header "COPYRIGHT"
195 Copyright 2020 Chad Granum <[email protected]>.
196 .PP
197 This program is free software; you can redistribute it and/or
198 modify it under the same terms as Perl itself.
199 .PP
200 See <https://dev.perl.org/licenses/>