Test2::...nstance(3pm)
β¨ NAME β¨
okay so this page is Test2::...nstance(3pm) from the Perl Programmers Reference Guide, and the package itβs actually about is Test2::API::Instance β aka the object used by Test2::API under the hood π
π DESCRIPTION π
This object is the cozy little wrapper around the global shared state that Test2 tracks. A single global instance of this package is stored (and obscured) by the Test2::API package.
There is no reason to directly use this package. It is documented for completeness. This package can change, or go away completely at any time. Directly using, or monkeypatching this package is not supported in any way shape or form. no cap, do not touch π
π§ SYNOPSIS π§
use Test2::API::Instance;
my $obj = Test2::API::Instance->new;
The method roll call π β every single one, no skips:
$pid = $obj->pidβ PID of this instance.$obj->tidβ Thread ID of this instance.$obj->reset()β Reset the object to defaults.$obj->load()β Set the internal state to loaded, and run and stored post-load callbacks.$bool = $obj->loadedβ Check if the state is set to loaded.$arrayref = $obj->post_load_callbacksβ Get the post-load callbacks.$obj->add_post_load_callback(sub { ... })β Add a post-load callback. Ifload()has already been called then the callback will be immediately executed. Ifload()has not been called then the callback will be stored and executed later whenload()is called.$hashref = $obj->contexts()β Get a hashref of all active contexts keyed byhub id.$arrayref = $obj->context_acquire_callbacksβ Get all context acquire callbacks.$arrayref = $obj->context_init_callbacksβ Get all context init callbacks.$arrayref = $obj->context_release_callbacksβ Get all context release callbacks.$arrayref = $obj->pre_subtest_callbacksβ Get all pre-subtest callbacks.$obj->add_context_init_callback(sub { ... })β Add a context init callback. Subs are called every time a context is created. Subs get the newly created context as their only argument.$obj->add_context_release_callback(sub { ... })β Add a context release callback. Subs are called every time a context is released. Subs get the released context as their only argument. These callbacks should not call release on the context.$obj->add_pre_subtest_callback(sub { ... })β Add a pre-subtest callback. Subs are called every time a subtest is going to be run. Subs get the subtest name, coderef, and any arguments.$obj->set_exit()β This is intended to be called in anEND { ... }block. This will look at test state and set$?. This will also call any end callbacks, and wait on child processes/threads.$obj->set_ipc_pending($val)β Tell other processes and threads there is a pending event.$valshould be a unique value no other thread/process will generate. Note: This will also make the current process see a pending event.$pending = $obj->get_ipc_pending()β This returns-1if it is not possible to know. This returns0if there are no pending events. This returns1if there are pending events.$timeout = $obj->ipc_timeout;/$obj->set_ipc_timeout($timeout);β How long to wait for child processes and threads before aborting.$drivers = $obj->ipc_driversβ Get the list of IPC drivers.$obj->add_ipc_driver($DRIVER_CLASS)β Add an IPC driver to the list. The most recently added IPC driver will become the global one during initialization. If a driver is added after initialization has occurred a warning will be generated:"IPC driver $driver loaded too late to be used as the global ipc driver"$bool = $obj->ipc_pollingβ Check if polling is enabled.$obj->enable_ipc_pollingβ Turn on polling. This will cull events from other processes and threads every time a context is created.$obj->disable_ipc_pollingβ Turn off IPC polling.$bool = $obj->no_wait/$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β Get the exit callbacks.$obj->add_exit_callback(sub { ... })β Add an exit callback. This callback will be called byset_exit().$bool = $obj->finalizedβ Check if the object is finalized. Finalization happens when eitheripc(),stack(), orformat()are called on the object. Once finalization happens these fields are considered unchangeable (not enforced here, enforced by Test2).$ipc = $obj->ipcβ Get the one true IPC instance.$obj->ipc_disableβ Turn IPC off.$bool = $obj->ipc_disabledβ Check if IPC is disabled.$stack = $obj->stackβ Get the one true hub stack.$formatter = $obj->formatterβ Get the global formatter. By default this is the'Test2::Formatter::TAP'package. This could be any package that implements thewrite()method. This can also be an instantiated object.$bool = $obj->formatter_set()β Check if a formatter has been set.$obj->add_formatter($class)/$obj->add_formatter($obj)β Add a formatter. The most recently added formatter will become the global one during initialization. If a formatter is added after initialization has occurred a warning will be generated:"Formatter $formatter loaded too late to be used as the global formatter"$obj->set_add_uuid_via(sub { ... })/$sub = $obj->add_uuid_via()β This allows you to provide a UUID generator. If provided UUIDs will be attached to all events, hubs, and contexts. This is 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 inTest2::APIenforces 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 can be found at <https://github.com/Test-More/test-more/>.
π 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 bestie, thatβs the whole page, fr fr. The footer vibes are perl v5.42.3, dated 2026-11-03, and the page tag is Test2::...nstance(3pm) β bye π«Άβ¨
π¦ 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