5 our $VERSION = '1.302164';
8 use Test2::API::Instance;
9 use Test2::Util qw/get_tid/;
15 test2_ipc_enable_polling
22 # Make sure stuff is finalized before anyone tried to fork or start a new thread.
24 # Avoid warnings if things are loaded at run-time
28 context()->release() unless test2_in_preload();
34 our @EXPORT_OK = qw/cull/;
35 BEGIN { require Exporter; our @ISA = qw(Exporter) }
37 sub unimport { Test2::API::test2_ipc_disable() }
40 goto &Exporter::import if test2_has_ipc || !test2_init_done();
42 confess "IPC is disabled" if Test2::API::test2_ipc_disabled();
43 confess "Cannot add IPC in a child process (" . test2_pid() . " vs $$)" if test2_pid() != $$;
44 confess "Cannot add IPC in a child thread (" . test2_tid() . " vs " . get_tid() . ")" if test2_tid() != get_tid();
46 Test2::API::_set_ipc(_make_ipc());
47 apply_ipc(test2_stack());
49 goto &Exporter::import;
54 my ($driver) = Test2::API::test2_ipc_drivers();
56 require Test2::IPC::Driver::Files;
57 $driver = 'Test2::IPC::Driver::Files';
60 return $driver->new();
70 confess "Cannot add IPC in a child process" if $root->pid != $$;
71 confess "Cannot add IPC in a child thread" if $root->tid != get_tid();
73 my $ipc = $root->ipc || test2_ipc() || _make_ipc();
75 # Add the IPC to all hubs
76 for my $hub (@$stack) {
78 confess "IPC Mismatch!" if $has && $has != $ipc;
81 $ipc->add_hub($hub->hid);
84 test2_ipc_enable_polling();
105 Test2::IPC - Turn on IPC for threading or forking support.
109 You should C<use Test2::IPC;> as early as possible in your test file. If you
110 import this module after API initialization it will attempt to retrofit IPC
111 onto the existing hubs.
115 You can use C<no Test2::IPC;> to disable IPC for good. You can also use the
120 All exports are optional.
126 Cull allows you to collect results from other processes or threads on demand.
132 The source code repository for Test2 can be found at
133 F<http://github.com/Test-More/test-more/>.
139 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
147 =item Chad Granum E<lt>exodist@cpan.orgE<gt>
153 Copyright 2019 Chad Granum E<lt>exodist@cpan.orgE<gt>.
155 This program is free software; you can redistribute it and/or
156 modify it under the same terms as Perl itself.
158 See F<http://dev.perl.org/licenses/>