1Test2::API::Instance(3)User Contributed Perl DocumentatioTnest2::API::Instance(3)
2
3
4

NAME

6       Test2::API::Instance - Object used by Test2::API under the hood
7

DESCRIPTION

9       This object encapsulates the global shared state tracked by Test2. A
10       single global instance of this package is stored (and obscured) by the
11       Test2::API package.
12
13       There is no reason to directly use this package. This package is
14       documented for completeness. This package can change, or go away
15       completely at any time.  Directly using, or monkeypatching this package
16       is not supported in any way shape or form.
17

SYNOPSIS

19           use Test2::API::Instance;
20
21           my $obj = Test2::API::Instance->new;
22
23       $pid = $obj->pid
24           PID of this instance.
25
26       $obj->tid
27           Thread ID of this instance.
28
29       $obj->reset()
30           Reset the object to defaults.
31
32       $obj->load()
33           Set the internal state to loaded, and run and stored post-load
34           callbacks.
35
36       $bool = $obj->loaded
37           Check if the state is set to loaded.
38
39       $arrayref = $obj->post_load_callbacks
40           Get the post-load callbacks.
41
42       $obj->add_post_load_callback(sub { ... })
43           Add a post-load callback. If "load()" has already been called then
44           the callback will be immediately executed. If "load()" has not been
45           called then the callback will be stored and executed later when
46           "load()" is called.
47
48       $hashref = $obj->contexts()
49           Get a hashref of all active contexts keyed by hub id.
50
51       $arrayref = $obj->context_acquire_callbacks
52           Get all context acquire callbacks.
53
54       $arrayref = $obj->context_init_callbacks
55           Get all context init callbacks.
56
57       $arrayref = $obj->context_release_callbacks
58           Get all context release callbacks.
59
60       $arrayref = $obj->pre_subtest_callbacks
61           Get all pre-subtest callbacks.
62
63       $obj->add_context_init_callback(sub { ... })
64           Add a context init callback. Subs are called every time a context
65           is created. Subs get the newly created context as their only
66           argument.
67
68       $obj->add_context_release_callback(sub { ... })
69           Add a context release callback. Subs are called every time a
70           context is released. Subs get the released context as their only
71           argument. These callbacks should not call release on the context.
72
73       $obj->add_pre_subtest_callback(sub { ... })
74           Add a pre-subtest callback. Subs are called every time a subtest is
75           going to be run. Subs get the subtest name, coderef, and any
76           arguments.
77
78       $obj->set_exit()
79           This is intended to be called in an "END { ... }" block. This will
80           look at test state and set $?. This will also call any end
81           callbacks, and wait on child processes/threads.
82
83       $obj->set_ipc_pending($val)
84           Tell other processes and threads there is a pending event. $val
85           should be a unique value no other thread/process will generate.
86
87           Note: This will also make the current process see a pending event.
88
89       $pending = $obj->get_ipc_pending()
90           This returns -1 if it is not possible to know.
91
92           This returns 0 if there are no pending events.
93
94           This returns 1 if there are pending events.
95
96       $timeout = $obj->ipc_timeout;
97       $obj->set_ipc_timeout($timeout);
98           How long to wait for child processes and threads before aborting.
99
100       $drivers = $obj->ipc_drivers
101           Get the list of IPC drivers.
102
103       $obj->add_ipc_driver($DRIVER_CLASS)
104           Add an IPC driver to the list. The most recently added IPC driver
105           will become the global one during initialization. If a driver is
106           added after initialization has occurred a warning will be
107           generated:
108
109               "IPC driver $driver loaded too late to be used as the global ipc driver"
110
111       $bool = $obj->ipc_polling
112           Check if polling is enabled.
113
114       $obj->enable_ipc_polling
115           Turn on polling. This will cull events from other processes and
116           threads every time a context is created.
117
118       $obj->disable_ipc_polling
119           Turn off IPC polling.
120
121       $bool = $obj->no_wait
122       $bool = $obj->set_no_wait($bool)
123           Get/Set no_wait. This option is used to turn off process/thread
124           waiting at exit.
125
126       $arrayref = $obj->exit_callbacks
127           Get the exit callbacks.
128
129       $obj->add_exit_callback(sub { ... })
130           Add an exit callback. This callback will be called by "set_exit()".
131
132       $bool = $obj->finalized
133           Check if the object is finalized. Finalization happens when either
134           "ipc()", "stack()", or "format()" are called on the object. Once
135           finalization happens these fields are considered unchangeable (not
136           enforced here, enforced by Test2).
137
138       $ipc = $obj->ipc
139           Get the one true IPC instance.
140
141       $obj->ipc_disable
142           Turn IPC off
143
144       $bool = $obj->ipc_disabled
145           Check if IPC is disabled
146
147       $stack = $obj->stack
148           Get the one true hub stack.
149
150       $formatter = $obj->formatter
151           Get the global formatter. By default this is the
152           'Test2::Formatter::TAP' package. This could be any package that
153           implements the "write()" method. This can also be an instantiated
154           object.
155
156       $bool = $obj->formatter_set()
157           Check if a formatter has been set.
158
159       $obj->add_formatter($class)
160       $obj->add_formatter($obj)
161           Add a formatter. The most recently added formatter will become the
162           global one during initialization. If a formatter is added after
163           initialization has occurred a warning will be generated:
164
165               "Formatter $formatter loaded too late to be used as the global formatter"
166
167       $obj->set_add_uuid_via(sub { ... })
168       $sub = $obj->add_uuid_via()
169           This allows you to provide a UUID generator. If provided UUIDs will
170           be attached to all events, hubs, and contexts. This is useful for
171           storing, tracking, and linking these objects.
172
173           The sub you provide should always return a unique identifier. Most
174           things will expect a proper UUID string, however nothing in
175           Test2::API enforces this.
176
177           The sub will receive exactly 1 argument, the type of thing being
178           tagged 'context', 'hub', or 'event'. In the future additional
179           things may be tagged, in which case new strings will be passed in.
180           These are purely informative, you can (and usually should) ignore
181           them.
182

SOURCE

184       The source code repository for Test2 can be found at
185       http://github.com/Test-More/test-more/.
186

MAINTAINERS

188       Chad Granum <exodist@cpan.org>
189

AUTHORS

191       Chad Granum <exodist@cpan.org>
192
194       Copyright 2020 Chad Granum <exodist@cpan.org>.
195
196       This program is free software; you can redistribute it and/or modify it
197       under the same terms as Perl itself.
198
199       See http://dev.perl.org/licenses/
200
201
202
203perl v5.32.0                      2020-10-15           Test2::API::Instance(3)
Impressum