{
    "mode": "perldoc",
    "parameter": "Test2::API::Instance",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Test2%3A%3AAPI%3A%3AInstance/json",
    "generated": "2026-06-11T01:38:04Z",
    "synopsis": "use Test2::API::Instance;\nmy $obj = Test2::API::Instance->new;\n$pid = $obj->pid\nPID of this instance.\n$obj->tid\nThread ID of this instance.\n$obj->reset()\nReset the object to defaults.\n$obj->load()\nSet the internal state to loaded, and run and stored post-load callbacks.\n$bool = $obj->loaded\nCheck if the state is set to loaded.\n$arrayref = $obj->postloadcallbacks\nGet the post-load callbacks.\n$obj->addpostloadcallback(sub { ... })\nAdd a post-load callback. If \"load()\" has already been called then the callback will be\nimmediately executed. If \"load()\" has not been called then the callback will be stored and\nexecuted later when \"load()\" is called.\n$hashref = $obj->contexts()\nGet a hashref of all active contexts keyed by hub id.\n$arrayref = $obj->contextacquirecallbacks\nGet all context acquire callbacks.\n$arrayref = $obj->contextinitcallbacks\nGet all context init callbacks.\n$arrayref = $obj->contextreleasecallbacks\nGet all context release callbacks.\n$arrayref = $obj->presubtestcallbacks\nGet all pre-subtest callbacks.\n$obj->addcontextinitcallback(sub { ... })\nAdd a context init callback. Subs are called every time a context is created. Subs get the\nnewly created context as their only argument.\n$obj->addcontextreleasecallback(sub { ... })\nAdd a context release callback. Subs are called every time a context is released. Subs get\nthe released context as their only argument. These callbacks should not call release on the\ncontext.\n$obj->addpresubtestcallback(sub { ... })\nAdd a pre-subtest callback. Subs are called every time a subtest is going to be run. Subs\nget the subtest name, coderef, and any arguments.\n$obj->setexit()\nThis is intended to be called in an \"END { ... }\" block. This will look at test state and\nset $?. This will also call any end callbacks, and wait on child processes/threads.\n$obj->setipcpending($val)\nTell other processes and threads there is a pending event. $val should be a unique value no\nother thread/process will generate.\nNote: This will also make the current process see a pending event.\n$pending = $obj->getipcpending()\nThis returns -1 if it is not possible to know.\nThis returns 0 if there are no pending events.\nThis returns 1 if there are pending events.\n$timeout = $obj->ipctimeout;\n$obj->setipctimeout($timeout);\nHow long to wait for child processes and threads before aborting.\n$drivers = $obj->ipcdrivers\nGet the list of IPC drivers.\n$obj->addipcdriver($DRIVERCLASS)\nAdd an IPC driver to the list. The most recently added IPC driver will become the global one\nduring initialization. If a driver is added after initialization has occurred a warning will\nbe generated:\n\"IPC driver $driver loaded too late to be used as the global ipc driver\"\n$bool = $obj->ipcpolling\nCheck if polling is enabled.\n$obj->enableipcpolling\nTurn on polling. This will cull events from other processes and threads every time a context\nis created.\n$obj->disableipcpolling\nTurn off IPC polling.\n$bool = $obj->nowait\n$bool = $obj->setnowait($bool)\nGet/Set nowait. This option is used to turn off process/thread waiting at exit.\n$arrayref = $obj->exitcallbacks\nGet the exit callbacks.\n$obj->addexitcallback(sub { ... })\nAdd an exit callback. This callback will be called by \"setexit()\".\n$bool = $obj->finalized\nCheck if the object is finalized. Finalization happens when either \"ipc()\", \"stack()\", or\n\"format()\" are called on the object. Once finalization happens these fields are considered\nunchangeable (not enforced here, enforced by Test2).\n$ipc = $obj->ipc\nGet the one true IPC instance.\n$obj->ipcdisable\nTurn IPC off\n$bool = $obj->ipcdisabled\nCheck if IPC is disabled\n$stack = $obj->stack\nGet the one true hub stack.\n$formatter = $obj->formatter\nGet the global formatter. By default this is the 'Test2::Formatter::TAP' package. This could\nbe any package that implements the \"write()\" method. This can also be an instantiated\nobject.\n$bool = $obj->formatterset()\nCheck if a formatter has been set.\n$obj->addformatter($class)\n$obj->addformatter($obj)\nAdd a formatter. The most recently added formatter will become the global one during\ninitialization. If a formatter is added after initialization has occurred a warning will be\ngenerated:\n\"Formatter $formatter loaded too late to be used as the global formatter\"\n$obj->setadduuidvia(sub { ... })\n$sub = $obj->adduuidvia()\nThis allows you to provide a UUID generator. If provided UUIDs will be attached to all\nevents, hubs, and contexts. This is useful for storing, tracking, and linking these objects.\nThe sub you provide should always return a unique identifier. Most things will expect a\nproper UUID string, however nothing in Test2::API enforces this.\nThe sub will receive exactly 1 argument, the type of thing being tagged 'context', 'hub', or\n'event'. In the future additional things may be tagged, in which case new strings will be\npassed in. These are purely informative, you can (and usually should) ignore them.",
    "sections": {
        "NAME": {
            "content": "Test2::API::Instance - Object used by Test2::API under the hood\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This object encapsulates the global shared state tracked by Test2. A single global instance of\nthis package is stored (and obscured) by the Test2::API package.\n\nThere is no reason to directly use this package. This package is documented for completeness.\nThis package can change, or go away completely at any time. Directly using, or monkeypatching\nthis package is not supported in any way shape or form.\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Test2::API::Instance;\n\nmy $obj = Test2::API::Instance->new;\n\n$pid = $obj->pid\nPID of this instance.\n\n$obj->tid\nThread ID of this instance.\n\n$obj->reset()\nReset the object to defaults.\n\n$obj->load()\nSet the internal state to loaded, and run and stored post-load callbacks.\n\n$bool = $obj->loaded\nCheck if the state is set to loaded.\n\n$arrayref = $obj->postloadcallbacks\nGet the post-load callbacks.\n\n$obj->addpostloadcallback(sub { ... })\nAdd a post-load callback. If \"load()\" has already been called then the callback will be\nimmediately executed. If \"load()\" has not been called then the callback will be stored and\nexecuted later when \"load()\" is called.\n\n$hashref = $obj->contexts()\nGet a hashref of all active contexts keyed by hub id.\n\n$arrayref = $obj->contextacquirecallbacks\nGet all context acquire callbacks.\n\n$arrayref = $obj->contextinitcallbacks\nGet all context init callbacks.\n\n$arrayref = $obj->contextreleasecallbacks\nGet all context release callbacks.\n\n$arrayref = $obj->presubtestcallbacks\nGet all pre-subtest callbacks.\n\n$obj->addcontextinitcallback(sub { ... })\nAdd a context init callback. Subs are called every time a context is created. Subs get the\nnewly created context as their only argument.\n\n$obj->addcontextreleasecallback(sub { ... })\nAdd a context release callback. Subs are called every time a context is released. Subs get\nthe released context as their only argument. These callbacks should not call release on the\ncontext.\n\n$obj->addpresubtestcallback(sub { ... })\nAdd a pre-subtest callback. Subs are called every time a subtest is going to be run. Subs\nget the subtest name, coderef, and any arguments.\n\n$obj->setexit()\nThis is intended to be called in an \"END { ... }\" block. This will look at test state and\nset $?. This will also call any end callbacks, and wait on child processes/threads.\n\n$obj->setipcpending($val)\nTell other processes and threads there is a pending event. $val should be a unique value no\nother thread/process will generate.\n\nNote: This will also make the current process see a pending event.\n\n$pending = $obj->getipcpending()\nThis returns -1 if it is not possible to know.\n\nThis returns 0 if there are no pending events.\n\nThis returns 1 if there are pending events.\n\n$timeout = $obj->ipctimeout;\n$obj->setipctimeout($timeout);\nHow long to wait for child processes and threads before aborting.\n\n$drivers = $obj->ipcdrivers\nGet the list of IPC drivers.\n\n$obj->addipcdriver($DRIVERCLASS)\nAdd an IPC driver to the list. The most recently added IPC driver will become the global one\nduring initialization. If a driver is added after initialization has occurred a warning will\nbe generated:\n\n\"IPC driver $driver loaded too late to be used as the global ipc driver\"\n\n$bool = $obj->ipcpolling\nCheck if polling is enabled.\n\n$obj->enableipcpolling\nTurn on polling. This will cull events from other processes and threads every time a context\nis created.\n\n$obj->disableipcpolling\nTurn off IPC polling.\n\n$bool = $obj->nowait\n$bool = $obj->setnowait($bool)\nGet/Set nowait. This option is used to turn off process/thread waiting at exit.\n\n$arrayref = $obj->exitcallbacks\nGet the exit callbacks.\n\n$obj->addexitcallback(sub { ... })\nAdd an exit callback. This callback will be called by \"setexit()\".\n\n$bool = $obj->finalized\nCheck if the object is finalized. Finalization happens when either \"ipc()\", \"stack()\", or\n\"format()\" are called on the object. Once finalization happens these fields are considered\nunchangeable (not enforced here, enforced by Test2).\n\n$ipc = $obj->ipc\nGet the one true IPC instance.\n\n$obj->ipcdisable\nTurn IPC off\n\n$bool = $obj->ipcdisabled\nCheck if IPC is disabled\n\n$stack = $obj->stack\nGet the one true hub stack.\n\n$formatter = $obj->formatter\nGet the global formatter. By default this is the 'Test2::Formatter::TAP' package. This could\nbe any package that implements the \"write()\" method. This can also be an instantiated\nobject.\n\n$bool = $obj->formatterset()\nCheck if a formatter has been set.\n\n$obj->addformatter($class)\n$obj->addformatter($obj)\nAdd a formatter. The most recently added formatter will become the global one during\ninitialization. If a formatter is added after initialization has occurred a warning will be\ngenerated:\n\n\"Formatter $formatter loaded too late to be used as the global formatter\"\n\n$obj->setadduuidvia(sub { ... })\n$sub = $obj->adduuidvia()\nThis allows you to provide a UUID generator. If provided UUIDs will be attached to all\nevents, hubs, and contexts. This is useful for storing, tracking, and linking these objects.\n\nThe sub you provide should always return a unique identifier. Most things will expect a\nproper UUID string, however nothing in Test2::API enforces this.\n\nThe sub will receive exactly 1 argument, the type of thing being tagged 'context', 'hub', or\n'event'. In the future additional things may be tagged, in which case new strings will be\npassed in. These are purely informative, you can (and usually should) ignore them.\n",
            "subsections": []
        },
        "SOURCE": {
            "content": "The source code repository for Test2 can be found at http://github.com/Test-More/test-more/.\n",
            "subsections": []
        },
        "MAINTAINERS": {
            "content": "Chad Granum <exodist@cpan.org>\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Chad Granum <exodist@cpan.org>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright 2020 Chad Granum <exodist@cpan.org>.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee http://dev.perl.org/licenses/\n",
            "subsections": []
        }
    },
    "summary": "Test2::API::Instance - Object used by Test2::API under the hood",
    "flags": [],
    "examples": [],
    "see_also": []
}