Test2::Util(3pm)
π Test2::Util β the group chat version π
ok so this is Test2::Util, straight out of the Perl Programmers Reference Guide (section 3pm for those keeping score π). She's the utility drawer that Test2 and all her friends keep raiding.
β¨ NAME β¨
Test2::Util β tools used by Test2 and friends. that's it, that's the vibe π«Ά
πΈ DESCRIPTION πΈ
literally just a collection of tools used by Test2 and friends. a little grab-bag of helpfulness. iconic behavior, no notes π
π¦ EXPORTS π¦
ok so all exports are optional β nothing jumps into your namespace uninvited, that's rude. you must specify which subs you want to import. consent first, always β¨
($success, $error) = try { ... }β evals the codeblock and gives you back success-or-failure plus the error message. bestie, this one protects$@and$!for you β they get restored by the end of the run. it also temporarily blocks$SIG{DIE}handlers. very protective, very demure πprotect { ... }β similar totry, except it does not catch exceptions. the whole point here is to shield$@and$!from changes.$@and$!get restored to whatever they were before the run, as long as the run is successful. if the run fails,$!still gets restored, but$@will contain the exception being thrown. so like, one of them's coming back either way, but$@snitches on failure πCAN_FORKβ true if this system is capable of true or pseudo-fork. slay π₯CAN_REALLY_FORKβ true if the system can really fork. this will be false for systems where fork is emulated. it's giving "fake it till you make it" but the test knows πCAN_THREADβ true if this system is capable of using threads. πUSE_THREADSβ returns true if threads are enabled, false if they are not. simple as that π§get_tidβ returns the id of the current thread when threads are enabled, otherwise it returns0. lowkey the most chill function here πmy $file = pkg_to_file($package)β converts a package name to a filename. glow-up for your strings β¨$string = ipc_separator()β gets the IPC separator. currently this is always the string'~'. that's her whole personality and we respect it π$string = gen_uid()β generates a unique id (NOT A UUID, she said what she said). this will typically be the process id, the thread id, the time, and an incrementing integer, all joined with theipc_separator().
these ID's are unique enough for most purposes. for identical ids to be generated you must have 2 processes with the same PID generate IDs at the same time with the same current state of the incrementing integer. this is a perfectly reasonable thing to expect to happen across multiple machines, but it's quite unlikely to happen on one machine.
β οΈ heads up bestie, this can fail to be unique if a process generates an id, callsexec, and does it again after theexecand it all happens in less than a second. it can also happen if the systems process id's cycle in less than a second, allowing 2 different programs that use this generator to run with the same PID in less than a second. both these cases are sufficiently unlikely. if you need universally unique ids, or ids that are unique in these conditions, look atData::UUID. periodt π
($ok, $err) = do_rename($old_name, $new_name)β renames a file. this wrapsrename()in a way that makes it more reliable cross-platform when you're trying to rename files you recently altered. she's got your back on every OS π«Ά($ok, $err) = do_unlink($filename)β unlinks a file. this wrapsunlink()in a way that makes it more reliable cross-platform when you're trying to unlink files you recently altered. same energy, different syscall π¦
π NOTES && CAVEATS π
5.10.0
Perl 5.10.0 has a bug when compiled with newer gcc versions. this bug causes a segfault whenever a new thread is launched π. Test2 will attempt to detect this, and note that the system is not capable of forking when it's detected. not me debugging a segfault at 3am π
Devel::Cover
Devel::Cover does not support threads. CAN_THREAD will return false if Devel::Cover is loaded before the check is first run. so like, load order matters, bestie π
π SOURCE π
the source code repository for Test2 can be found at <https://github.com/Test-More/test-more/>. go star it, she deserves it β
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
- Chad Granum
<exodist@cpan.org> - Kent Fredric
<kentnl@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
see <https://dev.perl.org/licenses/> πΈ
and that's the whole page, bestie β brought to you by perl v5.42.3, dated 2026-11-03, which is the version and date of this little masterpiece. mwah π slay and happy testing π
π¦ where this page comes from
- alpine 3.24: perl-doc 5.42.3-r0 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms