Debian Codegraph @

upstream/opensuse-tumbleweed/man3/Test2::Util.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Test2::Util 3pm"
61 .TH Test2::Util 3pm 2026-03-09 "perl v5.42.1" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Test2::Util \- Tools used by Test2 and friends.
68 .SH DESCRIPTION
69 .IX Header "DESCRIPTION"
70 Collection of tools used by Test2 and friends.
71 .SH EXPORTS
72 .IX Header "EXPORTS"
73 All exports are optional. You must specify subs to import.
74 .ie n .IP "($success, $error) = try { ... }" 4
75 .el .IP "($success, \f(CW$error\fR) = try { ... }" 4
76 .IX Item "($success, $error) = try { ... }"
77 Eval the codeblock, return success or failure, and the error message. This code
78 protects $@ and $!, they will be restored by the end of the run. This code also
79 temporarily blocks \f(CW$SIG\fR{DIE} handlers.
80 .IP "protect { ... }" 4
81 .IX Item "protect { ... }"
82 Similar to try, except that it does not catch exceptions. The idea here is to
83 protect $@ and $! from changes. $@ and $! will be restored to whatever they
84 were before the run so long as it is successful. If the run fails $! will still
85 be restored, but $@ will contain the exception being thrown.
86 .IP CAN_FORK 4
87 .IX Item "CAN_FORK"
88 True if this system is capable of true or pseudo\-fork.
89 .IP CAN_REALLY_FORK 4
90 .IX Item "CAN_REALLY_FORK"
91 True if the system can really fork. This will be false for systems where fork
92 is emulated.
93 .IP CAN_THREAD 4
94 .IX Item "CAN_THREAD"
95 True if this system is capable of using threads.
96 .IP USE_THREADS 4
97 .IX Item "USE_THREADS"
98 Returns true if threads are enabled, false if they are not.
99 .IP get_tid 4
100 .IX Item "get_tid"
101 This will return the id of the current thread when threads are enabled,
102 otherwise it returns 0.
103 .ie n .IP "my $file = pkg_to_file($package)" 4
104 .el .IP "my \f(CW$file\fR = pkg_to_file($package)" 4
105 .IX Item "my $file = pkg_to_file($package)"
106 Convert a package name to a filename.
107 .ie n .IP "$string = \fBipc_separator()\fR" 4
108 .el .IP "\f(CW$string\fR = \fBipc_separator()\fR" 4
109 .IX Item "$string = ipc_separator()"
110 Get the IPC separator. Currently this is always the string \f(CW\*(Aq~\*(Aq\fR.
111 .ie n .IP "$string = \fBgen_uid()\fR" 4
112 .el .IP "\f(CW$string\fR = \fBgen_uid()\fR" 4
113 .IX Item "$string = gen_uid()"
114 Generate a unique id (NOT A UUID). This will typically be the process id, the
115 thread id, the time, and an incrementing integer all joined with the
116 \&\f(CWipc_separator()\fR.
117 .Sp
118 These ID\*(Aqs are unique enough for most purposes. For identical ids to be
119 generated you must have 2 processes with the same PID generate IDs at the same
120 time with the same current state of the incrementing integer. This is a
121 perfectly reasonable thing to expect to happen across multiple machines, but is
122 quite unlikely to happen on one machine.
123 .Sp
124 This can fail to be unique if a process generates an id, calls exec, and does
125 it again after the exec and it all happens in less than a second. It can also
126 happen if the systems process id\*(Aqs cycle in less than a second allowing 2
127 different programs that use this generator to run with the same PID in less
128 than a second. Both these cases are sufficiently unlikely. If you need
129 universally unique ids, or ids that are unique in these conditions, look at
130 Data::UUID.
131 .ie n .IP "($ok, $err) = do_rename($old_name, $new_name)" 4
132 .el .IP "($ok, \f(CW$err\fR) = do_rename($old_name, \f(CW$new_name\fR)" 4
133 .IX Item "($ok, $err) = do_rename($old_name, $new_name)"
134 Rename a file, this wraps \f(CWrename()\fR in a way that makes it more reliable
135 cross\-platform when trying to rename files you recently altered.
136 .ie n .IP "($ok, $err) = do_unlink($filename)" 4
137 .el .IP "($ok, \f(CW$err\fR) = do_unlink($filename)" 4
138 .IX Item "($ok, $err) = do_unlink($filename)"
139 Unlink a file, this wraps \f(CWunlink()\fR in a way that makes it more reliable
140 cross\-platform when trying to unlink files you recently altered.
141 .SH "NOTES && CAVEATS"
142 .IX Header "NOTES && CAVEATS"
143 .IP 5.10.0 4
144 .IX Item "5.10.0"
145 Perl 5.10.0 has a bug when compiled with newer gcc versions. This bug causes a
146 segfault whenever a new thread is launched. Test2 will attempt to detect
147 this, and note that the system is not capable of forking when it is detected.
148 .IP Devel::Cover 4
149 .IX Item "Devel::Cover"
150 Devel::Cover does not support threads. CAN_THREAD will return false if
151 Devel::Cover is loaded before the check is first run.
152 .SH SOURCE
153 .IX Header "SOURCE"
154 The source code repository for Test2 can be found at
155 <https://github.com/Test\-More/test\-more/>.
156 .SH MAINTAINERS
157 .IX Header "MAINTAINERS"
158 .IP "Chad Granum <[email protected]>" 4
159 .IX Item "Chad Granum <[email protected]>"
160 .SH AUTHORS
161 .IX Header "AUTHORS"
162 .IP "Chad Granum <[email protected]>" 4
163 .IX Item "Chad Granum <[email protected]>"
164 .PD 0
165 .IP "Kent Fredric <[email protected]>" 4
166 .IX Item "Kent Fredric <[email protected]>"
167 .PD
168 .SH COPYRIGHT
169 .IX Header "COPYRIGHT"
170 Copyright Chad Granum <[email protected]>.
171 .PP
172 This program is free software; you can redistribute it and/or
173 modify it under the same terms as Perl itself.
174 .PP
175 See <https://dev.perl.org/licenses/>