Test2:...stance(3perl)
๐ Test2:...stance โ manual page 3perl ๐
okay so bestie, we're reading Test2:...stance out of the Perl Programmers Reference Guide, and honestly? the title has literal dots in it, we love a mysterious icon โจ don't worry about it, let's go ๐ฆ
๐ NAME ๐
Test2::API::Instance โ bestie... it's the Object used by Test2::API under the hood ๐
๐ซถ DESCRIPTION ๐ซถ
okay so picture this: there's this โจobjectโจ and its whole job is to hold all the global shared state that Test2 keeps track of. A single global instance of this package gets stored โ and ngl, kind of obscured โ by the Test2::API package. it's giving โจ backstage crew energy โจ, you never see them, the show doesn't happen without them ๐ญ
and here's the thing bestie, listen: there is no reason to directly use this package. None. Zero. Zip ๐ It's documented purely for completeness, that's it. This package can change, or go away completely at any time. Directly using it, or monkeypatching it, is not supported in any way shape or form.
๐จ fr fr, do not touch. Not "be careful" โ not supported. not even a little. ๐จ
โจ SYNOPSIS โจ
the whole opening number, verbatim:
use Test2::API::Instance;
my $obj = Test2::API::Instance->new;
and now... the method menu ๐ every single one, no skips, no crumbs left behind:
$pid = $obj->pidโ the PID of this instance ๐ซ$obj->tidโ the Thread ID of this instance ๐งต$obj->reset()โ resets the object back to defaults, factory settings, clean slate ๐ซ$obj->load()โ sets the internal state to loaded, and runs & stores the post-load callbacks โ๏ธ$bool = $obj->loadedโ checks whether the state is set to loaded ๐$arrayref = $obj->post_load_callbacksโ gets the post-load callbacks ๐$obj->add_post_load_callback(sub { ... })โ adds a post-load callback. Ifload()has already been called, the callback gets executed immediately. Ifload()hasn't been called yet, the callback gets stored and executed later, whenload()is called ๐ฎ$hashref = $obj->contexts()โ gets a hashref of all the active contexts, keyed by hub id ๐๏ธ$arrayref = $obj->context_acquire_callbacksโ gets all the context acquire callbacks ๐ซด$arrayref = $obj->context_init_callbacksโ gets all the context init callbacks ๐ฑ$arrayref = $obj->context_release_callbacksโ gets all the context release callbacks ๐๏ธ$arrayref = $obj->pre_subtest_callbacksโ gets all the pre-subtest callbacks ๐ฌ$obj->add_context_init_callback(sub { ... })โ adds a context init callback. The subs get called every single time a context is created, and they receive the newly created context as their only argument ๐ผ$obj->add_context_release_callback(sub { ... })โ adds a context release callback. The subs get called every time a context is released, and they receive the released context as their only argument. ๐ซง these callbacks should not call release on the context โ no, bestie, don't do it ๐ โโ๏ธ$obj->add_pre_subtest_callback(sub { ... })โ adds a pre-subtest callback. The subs get called every time a subtest is going to be run, and they receive the subtest name, the coderef, and any arguments ๐โโ๏ธ$obj->set_exit()โ this one is intended to be called in an"END { ... }"block. It looks at the test state and sets$?. It also calls any end callbacks, and waits on child processes/threads ๐$obj->set_ipc_pending($val)โ tells other processes and threads that there's a pending event.$valshould be a unique value that no other thread/process will generate ๐
๐ Note: this will also make the current process see a pending event.
$pending = $obj->get_ipc_pending()โ here's the readout, three possible answers:- returns
-1if it's not possible to know ๐คทโโ๏ธ - returns
0if there are no pending events ๐ซ - returns
1if there are pending events ๐จ
- returns
$timeout = $obj->ipc_timeout;and$obj->set_ipc_timeout($timeout);โ how long to wait for child processes and threads before aborting โณ$drivers = $obj->ipc_driversโ gets the list of IPC drivers ๐$obj->add_ipc_driver($DRIVER_CLASS)โ adds an IPC driver to the list. The most recently added IPC driver becomes the global one during initialization. If a driver is added after initialization has already occurred, a warning gets generated ๐ฌ:
"IPC driver $driver loaded too late to be used as the global ipc driver"
$bool = $obj->ipc_pollingโ checks whether polling is enabled ๐$obj->enable_ipc_pollingโ turns polling on. This culls events from other processes and threads every time a context is created ๐งน$obj->disable_ipc_pollingโ turns IPC polling off ๐$bool = $obj->no_waitand$bool = $obj->set_no_wait($bool)โ get/setno_wait. This option is used to turn off process/thread waiting at exit ๐$arrayref = $obj->exit_callbacksโ gets the exit callbacks ๐ช$obj->add_exit_callback(sub { ... })โ adds an exit callback. This callback gets called byset_exit()๐$bool = $obj->finalizedโ checks whether the object is finalized. Finalization happens when eitheripc(),stack(), orformat()are called on the object. Once finalization happens, these fields are considered unchangeable โ and bestie, that's not enforced here, it's enforced by Test2 โ ๏ธ$ipc = $obj->ipcโ gets the one true IPC instance ๐$obj->ipc_disableโ turns IPC off ๐$bool = $obj->ipc_disabledโ checks whether IPC is disabled ๐ง$stack = $obj->stackโ gets the one true hub stack ๐ฅ$formatter = $obj->formatterโ gets the global formatter. By default this is the'Test2::Formatter::TAP'package ๐ This could be any package that implements thewrite()method, and it can also be an instantiated object ๐$bool = $obj->formatter_set()โ checks whether a formatter has been set โ$obj->add_formatter($class)and$obj->add_formatter($obj)โ adds a formatter. The most recently added formatter becomes the global one during initialization. If a formatter is added after initialization has occurred, a warning gets generated ๐ข:
"Formatter $formatter loaded too late to be used as the global formatter"
$obj->set_add_uuid_via(sub { ... })and$sub = $obj->add_uuid_via()โ this lets you provide a UUID generator ๐ If one is provided, UUIDs get attached to all events, hubs, and contexts. Super useful for storing, tracking, and linking these objects ๐
The sub you provide should always return a unique identifier. Most things will expect a proper UUID string, however nothing in Test2::API enforces this ๐ซ
The sub will receive exactly 1 argument: the type of thing being tagged โ 'context', 'hub', or 'event'. In the future, additional things may be tagged, in which case new strings will be passed in. These are purely informative โ you can (and usually should) ignore them ๐
๐ธ SOURCE ๐ธ
the source code repository for Test2 lives at <https://github.com/Test-More/test-more/> โ go be nosy, bestie ๐ต๏ธโโ๏ธ
๐ MAINTAINERS ๐
Chad Granum <exodist@cpan.org> ๐ซก
๐ AUTHORS ๐
Chad Granum <exodist@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/>
okay and that's the whole thing bestie, no cap ๐ this page shipped as part of perl v5.44.0 and it's dated 2026-10-17 โจ go forth and... not use this package directly, because again, we said not to ๐ mwah ๐ ๐๐ฆ
๐ฆ where this page comes from
- arch rolling: perl 5.44.0-1 ยท Artistic-1.0-Perl AND GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms