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. If load() has already been called, the callback gets executed immediately. If load() hasn't been called yet, the callback gets stored and executed later, when load() 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. $val should 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 -1 if it's not possible to know ๐Ÿคทโ€โ™€๏ธ
    • returns 0 if there are no pending events ๐Ÿšซ
    • returns 1 if there are pending events ๐Ÿšจ
  • $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_wait and $bool = $obj->set_no_wait($bool) โ€” get/set no_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 by set_exit() ๐Ÿ“ž
  • $bool = $obj->finalized โ€” checks whether the object is finalized. Finalization happens when either ipc(), stack(), or format() 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 the write() 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 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