<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package Test2::API;
use strict;
use warnings;

use Test2::Util qw/USE_THREADS/;

BEGIN {
    $ENV{TEST_ACTIVE} ||= 1;
    $ENV{TEST2_ACTIVE} = 1;
}

our $VERSION = '1.302183';


my $INST;
my $ENDING = 0;
sub test2_unset_is_end { $ENDING = 0 }
sub test2_get_is_end { $ENDING }

sub test2_set_is_end {
    my $before = $ENDING;
    ($ENDING) = @_ ? @_ : (1);

    # Only send the event in a transition from false to true
    return if $before;
    return unless $ENDING;

    return unless $INST;
    my $stack = $INST-&gt;stack or return;
    my $root = $stack-&gt;root or return;

    return unless $root-&gt;count;

    return unless $$ == $INST-&gt;pid;
    return unless get_tid() == $INST-&gt;tid;

    my $trace = Test2::EventFacet::Trace-&gt;new(
        frame  =&gt; [__PACKAGE__, __FILE__, __LINE__, __PACKAGE__ . '::test2_set_is_end'],
    );
    my $ctx = Test2::API::Context-&gt;new(
        trace =&gt; $trace,
        hub   =&gt; $root,
    );

    $ctx-&gt;send_ev2(control =&gt; { phase =&gt; 'END', details =&gt; 'Transition to END phase' });

    1;
}

use Test2::API::Instance(\$INST);

# Set the exit status
END {
    test2_set_is_end(); # See gh #16
    $INST-&gt;set_exit();
}

sub CLONE {
    my $init = test2_init_done();
    my $load = test2_load_done();

    return if $init &amp;&amp; $load;

    require Carp;
    Carp::croak "Test2 must be fully loaded before you start a new thread!\n";
}

# See gh #16
{
    no warnings;
    INIT { eval 'END { test2_set_is_end() }; 1' or die $@ }
}

BEGIN {
    no warnings 'once';
    if($] ge '5.014' || $ENV{T2_CHECK_DEPTH} || $Test2::API::DO_DEPTH_CHECK) {
        *DO_DEPTH_CHECK = sub() { 1 };
    }
    else {
        *DO_DEPTH_CHECK = sub() { 0 };
    }
}

use Test2::EventFacet::Trace();
use Test2::Util::Trace(); # Legacy

use Test2::Hub::Subtest();
use Test2::Hub::Interceptor();
use Test2::Hub::Interceptor::Terminator();

use Test2::Event::Ok();
use Test2::Event::Diag();
use Test2::Event::Note();
use Test2::Event::Plan();
use Test2::Event::Bail();
use Test2::Event::Exception();
use Test2::Event::Waiting();
use Test2::Event::Skip();
use Test2::Event::Subtest();

use Carp qw/carp croak confess/;
use Scalar::Util qw/blessed weaken/;
use Test2::Util qw/get_tid clone_io pkg_to_file gen_uid/;

our @EXPORT_OK = qw{
    context release
    context_do
    no_context
    intercept intercept_deep
    run_subtest

    test2_init_done
    test2_load_done
    test2_load
    test2_start_preload
    test2_stop_preload
    test2_in_preload
    test2_is_testing_done

    test2_set_is_end
    test2_unset_is_end
    test2_get_is_end

    test2_pid
    test2_tid
    test2_stack
    test2_no_wait
    test2_ipc_wait_enable
    test2_ipc_wait_disable
    test2_ipc_wait_enabled

    test2_add_uuid_via

    test2_add_callback_testing_done

    test2_add_callback_context_aquire
    test2_add_callback_context_acquire
    test2_add_callback_context_init
    test2_add_callback_context_release
    test2_add_callback_exit
    test2_add_callback_post_load
    test2_add_callback_pre_subtest
    test2_list_context_aquire_callbacks
    test2_list_context_acquire_callbacks
    test2_list_context_init_callbacks
    test2_list_context_release_callbacks
    test2_list_exit_callbacks
    test2_list_post_load_callbacks
    test2_list_pre_subtest_callbacks

    test2_ipc
    test2_has_ipc
    test2_ipc_disable
    test2_ipc_disabled
    test2_ipc_drivers
    test2_ipc_add_driver
    test2_ipc_polling
    test2_ipc_disable_polling
    test2_ipc_enable_polling
    test2_ipc_get_pending
    test2_ipc_set_pending
    test2_ipc_get_timeout
    test2_ipc_set_timeout

    test2_formatter
    test2_formatters
    test2_formatter_add
    test2_formatter_set

    test2_stdout
    test2_stderr
    test2_reset_io
};
BEGIN { require Exporter; our @ISA = qw(Exporter) }

my $STACK       = $INST-&gt;stack;
my $CONTEXTS    = $INST-&gt;contexts;
my $INIT_CBS    = $INST-&gt;context_init_callbacks;
my $ACQUIRE_CBS = $INST-&gt;context_acquire_callbacks;

my $STDOUT = clone_io(\*STDOUT);
my $STDERR = clone_io(\*STDERR);
sub test2_stdout { $STDOUT ||= clone_io(\*STDOUT) }
sub test2_stderr { $STDERR ||= clone_io(\*STDERR) }

sub test2_post_preload_reset {
    test2_reset_io();
    $INST-&gt;post_preload_reset;
}

sub test2_reset_io {
    $STDOUT = clone_io(\*STDOUT);
    $STDERR = clone_io(\*STDERR);
}

sub test2_init_done { $INST-&gt;finalized }
sub test2_load_done { $INST-&gt;loaded }

sub test2_load          { $INST-&gt;load }
sub test2_start_preload { $ENV{T2_IN_PRELOAD} = 1; $INST-&gt;start_preload }
sub test2_stop_preload  { $ENV{T2_IN_PRELOAD} = 0; $INST-&gt;stop_preload }
sub test2_in_preload    { $INST-&gt;preload }

sub test2_pid              { $INST-&gt;pid }
sub test2_tid              { $INST-&gt;tid }
sub test2_stack            { $INST-&gt;stack }
sub test2_ipc_wait_enable  { $INST-&gt;set_no_wait(0) }
sub test2_ipc_wait_disable { $INST-&gt;set_no_wait(1) }
sub test2_ipc_wait_enabled { !$INST-&gt;no_wait }

sub test2_is_testing_done {
    # No instance? VERY DONE!
    return 1 unless $INST;

    # No stack? tests must be done, it is created pretty early
    my $stack = $INST-&gt;stack or return 1;

    # Nothing on the stack, no root hub yet, likely have not started testing
    return 0 unless @$stack;

    # Stack has a slot for the root hub (see above) but it is undefined, likely
    # garbage collected, test is done
    my $root_hub = $stack-&gt;[0] or return 1;

    # If the root hub is ended than testing is done.
    return 1 if $root_hub-&gt;ended;

    # Looks like we are still testing!
    return 0;
}

sub test2_no_wait {
    $INST-&gt;set_no_wait(@_) if @_;
    $INST-&gt;no_wait;
}

sub test2_add_callback_testing_done {
    my $cb = shift;

    test2_add_callback_post_load(sub {
        my $stack = test2_stack();
        $stack-&gt;top; # Insure we have a hub
        my ($hub) = Test2::API::test2_stack-&gt;all;

        $hub-&gt;set_active(1);

        $hub-&gt;follow_up($cb);
    });

    return;
}

sub test2_add_callback_context_acquire   { $INST-&gt;add_context_acquire_callback(@_) }
sub test2_add_callback_context_aquire    { $INST-&gt;add_context_acquire_callback(@_) }
sub test2_add_callback_context_init      { $INST-&gt;add_context_init_callback(@_) }
sub test2_add_callback_context_release   { $INST-&gt;add_context_release_callback(@_) }
sub test2_add_callback_exit              { $INST-&gt;add_exit_callback(@_) }
sub test2_add_callback_post_load         { $INST-&gt;add_post_load_callback(@_) }
sub test2_add_callback_pre_subtest       { $INST-&gt;add_pre_subtest_callback(@_) }
sub test2_list_context_aquire_callbacks  { @{$INST-&gt;context_acquire_callbacks} }
sub test2_list_context_acquire_callbacks { @{$INST-&gt;context_acquire_callbacks} }
sub test2_list_context_init_callbacks    { @{$INST-&gt;context_init_callbacks} }
sub test2_list_context_release_callbacks { @{$INST-&gt;context_release_callbacks} }
sub test2_list_exit_callbacks            { @{$INST-&gt;exit_callbacks} }
sub test2_list_post_load_callbacks       { @{$INST-&gt;post_load_callbacks} }
sub test2_list_pre_subtest_callbacks     { @{$INST-&gt;pre_subtest_callbacks} }

sub test2_add_uuid_via {
    $INST-&gt;set_add_uuid_via(@_) if @_;
    $INST-&gt;add_uuid_via();
}

sub test2_ipc                 { $INST-&gt;ipc }
sub test2_has_ipc             { $INST-&gt;has_ipc }
sub test2_ipc_disable         { $INST-&gt;ipc_disable }
sub test2_ipc_disabled        { $INST-&gt;ipc_disabled }
sub test2_ipc_add_driver      { $INST-&gt;add_ipc_driver(@_) }
sub test2_ipc_drivers         { @{$INST-&gt;ipc_drivers} }
sub test2_ipc_polling         { $INST-&gt;ipc_polling }
sub test2_ipc_enable_polling  { $INST-&gt;enable_ipc_polling }
sub test2_ipc_disable_polling { $INST-&gt;disable_ipc_polling }
sub test2_ipc_get_pending     { $INST-&gt;get_ipc_pending }
sub test2_ipc_set_pending     { $INST-&gt;set_ipc_pending(@_) }
sub test2_ipc_set_timeout     { $INST-&gt;set_ipc_timeout(@_) }
sub test2_ipc_get_timeout     { $INST-&gt;ipc_timeout() }
sub test2_ipc_enable_shm      { 0 }

sub test2_formatter     {
    if ($ENV{T2_FORMATTER} &amp;&amp; $ENV{T2_FORMATTER} =~ m/^(\+)?(.*)$/) {
        my $formatter = $1 ? $2 : "Test2::Formatter::$2";
        my $file = pkg_to_file($formatter);
        require $file;
        return $formatter;
    }

    return $INST-&gt;formatter;
}

sub test2_formatters    { @{$INST-&gt;formatters} }
sub test2_formatter_add { $INST-&gt;add_formatter(@_) }
sub test2_formatter_set {
    my ($formatter) = @_;
    croak "No formatter specified" unless $formatter;
    croak "Global Formatter already set" if $INST-&gt;formatter_set;
    $INST-&gt;set_formatter($formatter);
}

# Private, for use in Test2::API::Context
sub _contexts_ref                  { $INST-&gt;contexts }
sub _context_acquire_callbacks_ref { $INST-&gt;context_acquire_callbacks }
sub _context_init_callbacks_ref    { $INST-&gt;context_init_callbacks }
sub _context_release_callbacks_ref { $INST-&gt;context_release_callbacks }
sub _add_uuid_via_ref              { \($INST-&gt;{Test2::API::Instance::ADD_UUID_VIA()}) }

# Private, for use in Test2::IPC
sub _set_ipc { $INST-&gt;set_ipc(@_) }

sub context_do(&amp;;@) {
    my $code = shift;
    my @args = @_;

    my $ctx = context(level =&gt; 1);

    my $want = wantarray;

    my @out;
    my $ok = eval {
        $want          ? @out    = $code-&gt;($ctx, @args) :
        defined($want) ? $out[0] = $code-&gt;($ctx, @args) :
                                   $code-&gt;($ctx, @args) ;
        1;
    };
    my $err = $@;

    $ctx-&gt;release;

    die $err unless $ok;

    return @out    if $want;
    return $out[0] if defined $want;
    return;
}

sub no_context(&amp;;$) {
    my ($code, $hid) = @_;
    $hid ||= $STACK-&gt;top-&gt;hid;

    my $ctx = $CONTEXTS-&gt;{$hid};
    delete $CONTEXTS-&gt;{$hid};
    my $ok = eval { $code-&gt;(); 1 };
    my $err = $@;

    $CONTEXTS-&gt;{$hid} = $ctx;
    weaken($CONTEXTS-&gt;{$hid});

    die $err unless $ok;

    return;
};

my $UUID_VIA = _add_uuid_via_ref();
sub context {
    # We need to grab these before anything else to ensure they are not
    # changed.
    my ($errno, $eval_error, $child_error, $extended_error) = (0 + $!, $@, $?, $^E);

    my %params = (level =&gt; 0, wrapped =&gt; 0, @_);

    # If something is getting a context then the sync system needs to be
    # considered loaded...
    $INST-&gt;load unless $INST-&gt;{loaded};

    croak "context() called, but return value is ignored"
        unless defined wantarray;

    my $stack   = $params{stack} || $STACK;
    my $hub     = $params{hub}   || (@$stack ? $stack-&gt;[-1] : $stack-&gt;top);

    # Catch an edge case where we try to get context after the root hub has
    # been garbage collected resulting in a stack that has a single undef
    # hub
    if (!$hub &amp;&amp; !exists($params{hub}) &amp;&amp; @$stack) {
        my $msg = Carp::longmess("Attempt to get Test2 context after testing has completed (did you attempt a testing event after done_testing?)");

        # The error message is usually masked by the global destruction, so we have to print to STDER
        print STDERR $msg;

        # Make sure this is a failure, we are probably already in END, so set $? to change the exit code
        $? = 1;

        # Now we actually die to interrupt the program flow and avoid undefined his warnings
        die $msg;
    }

    my $hid     = $hub-&gt;{hid};
    my $current = $CONTEXTS-&gt;{$hid};

    $_-&gt;(\%params) for @$ACQUIRE_CBS;
    map $_-&gt;(\%params), @{$hub-&gt;{_context_acquire}} if $hub-&gt;{_context_acquire};

    # This is for https://github.com/Test-More/test-more/issues/16
    # and https://rt.perl.org/Public/Bug/Display.html?id=127774
    my $phase = ${^GLOBAL_PHASE} || 'NA';
    my $end_phase = $ENDING || $phase eq 'END' || $phase eq 'DESTRUCT';

    my $level = 1 + $params{level};
    my ($pkg, $file, $line, $sub, @other) = $end_phase ? caller(0) : caller($level);
    unless ($pkg || $end_phase) {
        confess "Could not find context at depth $level" unless $params{fudge};
        ($pkg, $file, $line, $sub, @other) = caller(--$level) while ($level &gt;= 0 &amp;&amp; !$pkg);
    }

    my $depth = $level;
    $depth++ while DO_DEPTH_CHECK &amp;&amp; !$end_phase &amp;&amp; (!$current || $depth &lt;= $current-&gt;{_depth} + $params{wrapped}) &amp;&amp; caller($depth + 1);
    $depth -= $params{wrapped};
    my $depth_ok = !DO_DEPTH_CHECK || $end_phase || !$current || $current-&gt;{_depth} &lt; $depth;

    if ($current &amp;&amp; $params{on_release} &amp;&amp; $depth_ok) {
        $current-&gt;{_on_release} ||= [];
        push @{$current-&gt;{_on_release}} =&gt; $params{on_release};
    }

    # I know this is ugly....
    ($!, $@, $?, $^E) = ($errno, $eval_error, $child_error, $extended_error) and return bless(
        {
            %$current,
            _is_canon   =&gt; undef,
            errno       =&gt; $errno,
            eval_error  =&gt; $eval_error,
            child_error =&gt; $child_error,
            _is_spawn   =&gt; [$pkg, $file, $line, $sub],
        },
        'Test2::API::Context'
    ) if $current &amp;&amp; $depth_ok;

    # Handle error condition of bad level
    if ($current) {
        unless (${$current-&gt;{_aborted}}) {
            _canon_error($current, [$pkg, $file, $line, $sub, $depth])
                unless $current-&gt;{_is_canon};

            _depth_error($current, [$pkg, $file, $line, $sub, $depth])
                unless $depth_ok;
        }

        $current-&gt;release if $current-&gt;{_is_canon};

        delete $CONTEXTS-&gt;{$hid};
    }

    # Directly bless the object here, calling new is a noticeable performance
    # hit with how often this needs to be called.
    my $trace = bless(
        {
            frame  =&gt; [$pkg, $file, $line, $sub],
            pid    =&gt; $$,
            tid    =&gt; get_tid(),
            cid    =&gt; gen_uid(),
            hid    =&gt; $hid,
            nested =&gt; $hub-&gt;{nested},
            buffered =&gt; $hub-&gt;{buffered},

            full_caller =&gt; [$pkg, $file, $line, $sub, @other],

            $$UUID_VIA ? (
                huuid =&gt; $hub-&gt;{uuid},
                uuid  =&gt; ${$UUID_VIA}-&gt;('context'),
            ) : (),
        },
        'Test2::EventFacet::Trace'
    );

    # Directly bless the object here, calling new is a noticeable performance
    # hit with how often this needs to be called.
    my $aborted = 0;
    $current = bless(
        {
            _aborted     =&gt; \$aborted,
            stack        =&gt; $stack,
            hub          =&gt; $hub,
            trace        =&gt; $trace,
            _is_canon    =&gt; 1,
            _depth       =&gt; $depth,
            errno        =&gt; $errno,
            eval_error   =&gt; $eval_error,
            child_error  =&gt; $child_error,
            $params{on_release} ? (_on_release =&gt; [$params{on_release}]) : (),
        },
        'Test2::API::Context'
    );

    $CONTEXTS-&gt;{$hid} = $current;
    weaken($CONTEXTS-&gt;{$hid});

    $_-&gt;($current) for @$INIT_CBS;
    map $_-&gt;($current), @{$hub-&gt;{_context_init}} if $hub-&gt;{_context_init};

    $params{on_init}-&gt;($current) if $params{on_init};

    ($!, $@, $?, $^E) = ($errno, $eval_error, $child_error, $extended_error);

    return $current;
}

sub _depth_error {
    _existing_error(@_, &lt;&lt;"    EOT");
context() was called to retrieve an existing context, however the existing
context was created in a stack frame at the same, or deeper level. This usually
means that a tool failed to release the context when it was finished.
    EOT
}

sub _canon_error {
    _existing_error(@_, &lt;&lt;"    EOT");
context() was called to retrieve an existing context, however the existing
context has an invalid internal state (!_canon_count). This should not normally
happen unless something is mucking about with internals...
    EOT
}

sub _existing_error {
    my ($ctx, $details, $msg) = @_;
    my ($pkg, $file, $line, $sub, $depth) = @$details;

    my $oldframe = $ctx-&gt;{trace}-&gt;frame;
    my $olddepth = $ctx-&gt;{_depth};

    # Older versions of Carp do not export longmess() function, so it needs to be called with package name
    my $mess = Carp::longmess();

    warn &lt;&lt;"    EOT";
$msg
Old context details:
   File: $oldframe-&gt;[1]
   Line: $oldframe-&gt;[2]
   Tool: $oldframe-&gt;[3]
  Depth: $olddepth

New context details:
   File: $file
   Line: $line
   Tool: $sub
  Depth: $depth

Trace: $mess

Removing the old context and creating a new one...
    EOT
}

sub release($;$) {
    $_[0]-&gt;release;
    return $_[1];
}

sub intercept(&amp;) {
    my $code = shift;
    my $ctx = context();

    my $events = _intercept($code, deep =&gt; 0);

    $ctx-&gt;release;

    return $events;
}

sub intercept_deep(&amp;) {
    my $code = shift;
    my $ctx = context();

    my $events = _intercept($code, deep =&gt; 1);

    $ctx-&gt;release;

    return $events;
}

sub _intercept {
    my $code = shift;
    my %params = @_;
    my $ctx = context();

    my $ipc;
    if (my $global_ipc = test2_ipc()) {
        my $driver = blessed($global_ipc);
        $ipc = $driver-&gt;new;
    }

    my $hub = Test2::Hub::Interceptor-&gt;new(
        ipc =&gt; $ipc,
        no_ending =&gt; 1,
    );

    my @events;
    $hub-&gt;listen(sub { push @events =&gt; $_[1] }, inherit =&gt; $params{deep});

    $ctx-&gt;stack-&gt;top; # Make sure there is a top hub before we begin.
    $ctx-&gt;stack-&gt;push($hub);

    my $trace = $ctx-&gt;trace;
    my $state = {};
    $hub-&gt;clean_inherited(trace =&gt; $trace, state =&gt; $state);

    my ($ok, $err) = (1, undef);
    T2_SUBTEST_WRAPPER: {
        # Do not use 'try' cause it localizes __DIE__
        $ok = eval { $code-&gt;(hub =&gt; $hub, context =&gt; $ctx-&gt;snapshot); 1 };
        $err = $@;

        # They might have done 'BEGIN { skip_all =&gt; "whatever" }'
        if (!$ok &amp;&amp; $err =~ m/Label not found for "last T2_SUBTEST_WRAPPER"/ || (blessed($err) &amp;&amp; $err-&gt;isa('Test2::Hub::Interceptor::Terminator'))) {
            $ok  = 1;
            $err = undef;
        }
    }

    $hub-&gt;cull;
    $ctx-&gt;stack-&gt;pop($hub);

    $hub-&gt;restore_inherited(trace =&gt; $trace, state =&gt; $state);

    $ctx-&gt;release;

    die $err unless $ok;

    $hub-&gt;finalize($trace, 1)
        if $ok
        &amp;&amp; !$hub-&gt;no_ending
        &amp;&amp; !$hub-&gt;ended;

    require Test2::API::InterceptResult;
    return Test2::API::InterceptResult-&gt;new_from_ref(\@events);
}

sub run_subtest {
    my ($name, $code, $params, @args) = @_;

    $_-&gt;($name,$code,@args)
        for Test2::API::test2_list_pre_subtest_callbacks();

    $params = {buffered =&gt; $params} unless ref $params;
    my $inherit_trace = delete $params-&gt;{inherit_trace};

    my $ctx = context();

    my $parent = $ctx-&gt;hub;

    # If a parent is buffered then the child must be as well.
    my $buffered = $params-&gt;{buffered} || $parent-&gt;{buffered};

    $ctx-&gt;note($name) unless $buffered;

    my $stack = $ctx-&gt;stack || $STACK;
    my $hub = $stack-&gt;new_hub(
        class =&gt; 'Test2::Hub::Subtest',
        %$params,
        buffered =&gt; $buffered,
    );

    my @events;
    $hub-&gt;listen(sub { push @events =&gt; $_[1] });

    if ($buffered) {
        if (my $format = $hub-&gt;format) {
            my $hide = $format-&gt;can('hide_buffered') ? $format-&gt;hide_buffered : 1;
            $hub-&gt;format(undef) if $hide;
        }
    }

    if ($inherit_trace) {
        my $orig = $code;
        $code = sub {
            my $base_trace = $ctx-&gt;trace;
            my $trace = $base_trace-&gt;snapshot(nested =&gt; 1 + $base_trace-&gt;nested);
            my $st_ctx = Test2::API::Context-&gt;new(
                trace  =&gt; $trace,
                hub    =&gt; $hub,
            );
            $st_ctx-&gt;do_in_context($orig, @args);
        };
    }

    my ($ok, $err, $finished);
    T2_SUBTEST_WRAPPER: {
        # Do not use 'try' cause it localizes __DIE__
        $ok = eval { $code-&gt;(@args); 1 };
        $err = $@;

        # They might have done 'BEGIN { skip_all =&gt; "whatever" }'
        if (!$ok &amp;&amp; $err =~ m/Label not found for "last T2_SUBTEST_WRAPPER"/ || (blessed($err) &amp;&amp; blessed($err) eq 'Test::Builder::Exception')) {
            $ok  = undef;
            $err = undef;
        }
        else {
            $finished = 1;
        }
    }

    if ($params-&gt;{no_fork}) {
        if ($$ != $ctx-&gt;trace-&gt;pid) {
            warn $ok ? "Forked inside subtest, but subtest never finished!\n" : $err;
            exit 255;
        }

        if (get_tid() != $ctx-&gt;trace-&gt;tid) {
            warn $ok ? "Started new thread inside subtest, but thread never finished!\n" : $err;
            exit 255;
        }
    }
    elsif (!$parent-&gt;is_local &amp;&amp; !$parent-&gt;ipc) {
        warn $ok ? "A new process or thread was started inside subtest, but IPC is not enabled!\n" : $err;
        exit 255;
    }

    $stack-&gt;pop($hub);

    my $trace = $ctx-&gt;trace;

    my $bailed = $hub-&gt;bailed_out;

    if (!$finished) {
        if ($bailed &amp;&amp; !$buffered) {
            $ctx-&gt;bail($bailed-&gt;reason);
        }
        elsif ($bailed &amp;&amp; $buffered) {
            $ok = 1;
        }
        else {
            my $code = $hub-&gt;exit_code;
            $ok = !$code;
            $err = "Subtest ended with exit code $code" if $code;
        }
    }

    $hub-&gt;finalize($trace-&gt;snapshot(huuid =&gt; $hub-&gt;uuid, hid =&gt; $hub-&gt;hid, nested =&gt; $hub-&gt;nested, buffered =&gt; $buffered), 1)
        if $ok
        &amp;&amp; !$hub-&gt;no_ending
        &amp;&amp; !$hub-&gt;ended;

    my $pass = $ok &amp;&amp; $hub-&gt;is_passing;
    my $e = $ctx-&gt;build_event(
        'Subtest',
        pass         =&gt; $pass,
        name         =&gt; $name,
        subtest_id   =&gt; $hub-&gt;id,
        subtest_uuid =&gt; $hub-&gt;uuid,
        buffered     =&gt; $buffered,
        subevents    =&gt; \@events,
    );

    my $plan_ok = $hub-&gt;check_plan;

    $ctx-&gt;hub-&gt;send($e);

    $ctx-&gt;failure_diag($e) unless $e-&gt;pass;

    $ctx-&gt;diag("Caught exception in subtest: $err") unless $ok;

    $ctx-&gt;diag("Bad subtest plan, expected " . $hub-&gt;plan . " but ran " . $hub-&gt;count)
        if defined($plan_ok) &amp;&amp; !$plan_ok;

    $ctx-&gt;bail($bailed-&gt;reason) if $bailed &amp;&amp; $buffered;

    $ctx-&gt;release;
    return $pass;
}

# There is a use-cycle between API and API/Context. Context needs to use some
# API functions as the package is compiling. Test2::API::context() needs
# Test2::API::Context to be loaded, but we cannot 'require' the module there as
# it causes a very noticeable performance impact with how often context() is
# called.
require Test2::API::Context;

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Test2::API - Primary interface for writing Test2 based testing tools.

=head1 ***INTERNALS NOTE***

B&lt;The internals of this package are subject to change at any time!&gt; The public
methods provided will not change in backwards-incompatible ways (once there is
a stable release), but the underlying implementation details might.
B&lt;Do not break encapsulation here!&gt;

Currently the implementation is to create a single instance of the
L&lt;Test2::API::Instance&gt; Object. All class methods defer to the single
instance. There is no public access to the singleton, and that is intentional.
The class methods provided by this package provide the only functionality
publicly exposed.

This is done primarily to avoid the problems Test::Builder had by exposing its
singleton. We do not want anyone to replace this singleton, rebless it, or
directly muck with its internals. If you need to do something and cannot
because of the restrictions placed here, then please report it as an issue. If
possible, we will create a way for you to implement your functionality without
exposing things that should not be exposed.

=head1 DESCRIPTION

This package exports all the functions necessary to write and/or verify testing
tools. Using these building blocks you can begin writing test tools very
quickly. You are also provided with tools that help you to test the tools you
write.

=head1 SYNOPSIS

=head2 WRITING A TOOL

The C&lt;context()&gt; method is your primary interface into the Test2 framework.

    package My::Ok;
    use Test2::API qw/context/;

    our @EXPORT = qw/my_ok/;
    use base 'Exporter';

    # Just like ok() from Test::More
    sub my_ok($;$) {
        my ($bool, $name) = @_;
        my $ctx = context(); # Get a context
        $ctx-&gt;ok($bool, $name);
        $ctx-&gt;release; # Release the context
        return $bool;
    }

See L&lt;Test2::API::Context&gt; for a list of methods available on the context object.

=head2 TESTING YOUR TOOLS

The C&lt;intercept { ... }&gt; tool lets you temporarily intercept all events
generated by the test system:

    use Test2::API qw/intercept/;

    use My::Ok qw/my_ok/;

    my $events = intercept {
        # These events are not displayed
        my_ok(1, "pass");
        my_ok(0, "fail");
    };

As of version 1.302178 this now returns an arrayref that is also an instance of
L&lt;Test2::API::InterceptResult&gt;. See the L&lt;Test2::API::InterceptResult&gt;
documentation for details on how to best use it.

=head2 OTHER API FUNCTIONS

    use Test2::API qw{
        test2_init_done
        test2_stack
        test2_set_is_end
        test2_get_is_end
        test2_ipc
        test2_formatter_set
        test2_formatter
        test2_is_testing_done
    };

    my $init  = test2_init_done();
    my $stack = test2_stack();
    my $ipc   = test2_ipc();

    test2_formatter_set($FORMATTER)
    my $formatter = test2_formatter();

    ... And others ...

=head1 MAIN API EXPORTS

All exports are optional. You must specify subs to import.

    use Test2::API qw/context intercept run_subtest/;

This is the list of exports that are most commonly needed. If you are simply
writing a tool, then this is probably all you need. If you need something and
you cannot find it here, then you can also look at L&lt;/OTHER API EXPORTS&gt;.

These exports lack the 'test2_' prefix because of how important/common they
are. Exports in the L&lt;/OTHER API EXPORTS&gt; section have the 'test2_' prefix to
ensure they stand out.

=head2 context(...)

Usage:

=over 4

=item $ctx = context()

=item $ctx = context(%params)

=back

The C&lt;context()&gt; function will always return the current context. If
there is already a context active, it will be returned. If there is not an
active context, one will be generated. When a context is generated it will
default to using the file and line number where the currently running sub was
called from.

Please see L&lt;Test2::API::Context/"CRITICAL DETAILS"&gt; for important rules about
what you can and cannot do with a context once it is obtained.

B&lt;Note&gt; This function will throw an exception if you ignore the context object
it returns.

B&lt;Note&gt; On perls 5.14+ a depth check is used to insure there are no context
leaks. This cannot be safely done on older perls due to
L&lt;https://rt.perl.org/Public/Bug/Display.html?id=127774&gt;
You can forcefully enable it either by setting C&lt;$ENV{T2_CHECK_DEPTH} = 1&gt; or
C&lt;$Test2::API::DO_DEPTH_CHECK = 1&gt; B&lt;BEFORE&gt; loading L&lt;Test2::API&gt;.

=head3 OPTIONAL PARAMETERS

All parameters to C&lt;context&gt; are optional.

=over 4

=item level =&gt; $int

If you must obtain a context in a sub deeper than your entry point you can use
this to tell it how many EXTRA stack frames to look back. If this option is not
provided the default of C&lt;0&gt; is used.

    sub third_party_tool {
        my $sub = shift;
        ... # Does not obtain a context
        $sub-&gt;();
        ...
    }

    third_party_tool(sub {
        my $ctx = context(level =&gt; 1);
        ...
        $ctx-&gt;release;
    });

=item wrapped =&gt; $int

Use this if you need to write your own tool that wraps a call to C&lt;context()&gt;
with the intent that it should return a context object.

    sub my_context {
        my %params = ( wrapped =&gt; 0, @_ );
        $params{wrapped}++;
        my $ctx = context(%params);
        ...
        return $ctx;
    }

    sub my_tool {
        my $ctx = my_context();
        ...
        $ctx-&gt;release;
    }

If you do not do this, then tools you call that also check for a context will
notice that the context they grabbed was created at the same stack depth, which
will trigger protective measures that warn you and destroy the existing
context.

=item stack =&gt; $stack

Normally C&lt;context()&gt; looks at the global hub stack. If you are maintaining
your own L&lt;Test2::API::Stack&gt; instance you may pass it in to be used
instead of the global one.

=item hub =&gt; $hub

Use this parameter if you want to obtain the context for a specific hub instead
of whatever one happens to be at the top of the stack.

=item on_init =&gt; sub { ... }

This lets you provide a callback sub that will be called B&lt;ONLY&gt; if your call
to C&lt;context()&gt; generated a new context. The callback B&lt;WILL NOT&gt; be called if
C&lt;context()&gt; is returning an existing context. The only argument passed into
the callback will be the context object itself.

    sub foo {
        my $ctx = context(on_init =&gt; sub { 'will run' });

        my $inner = sub {
            # This callback is not run since we are getting the existing
            # context from our parent sub.
            my $ctx = context(on_init =&gt; sub { 'will NOT run' });
            $ctx-&gt;release;
        }
        $inner-&gt;();

        $ctx-&gt;release;
    }

=item on_release =&gt; sub { ... }

This lets you provide a callback sub that will be called when the context
instance is released. This callback will be added to the returned context even
if an existing context is returned. If multiple calls to context add callbacks,
then all will be called in reverse order when the context is finally released.

    sub foo {
        my $ctx = context(on_release =&gt; sub { 'will run second' });

        my $inner = sub {
            my $ctx = context(on_release =&gt; sub { 'will run first' });

            # Neither callback runs on this release
            $ctx-&gt;release;
        }
        $inner-&gt;();

        # Both callbacks run here.
        $ctx-&gt;release;
    }

=back

=head2 release($;$)

Usage:

=over 4

=item release $ctx;

=item release $ctx, ...;

=back

This is intended as a shortcut that lets you release your context and return a
value in one statement. This function will get your context, and an optional
return value. It will release your context, then return your value. Scalar
context is always assumed.

    sub tool {
        my $ctx = context();
        ...

        return release $ctx, 1;
    }

This tool is most useful when you want to return the value you get from calling
a function that needs to see the current context:

    my $ctx = context();
    my $out = some_tool(...);
    $ctx-&gt;release;
    return $out;

We can combine the last 3 lines of the above like so:

    my $ctx = context();
    release $ctx, some_tool(...);

=head2 context_do(&amp;;@)

Usage:

    sub my_tool {
        context_do {
            my $ctx = shift;

            my (@args) = @_;

            $ctx-&gt;ok(1, "pass");

            ...

            # No need to call $ctx-&gt;release, done for you on scope exit.
        } @_;
    }

Using this inside your test tool takes care of a lot of boilerplate for you. It
will ensure a context is acquired. It will capture and rethrow any exception. It
will insure the context is released when you are done. It preserves the
subroutine call context (array, scalar, void).

This is the safest way to write a test tool. The only two downsides to this are a
slight performance decrease, and some extra indentation in your source. If the
indentation is a problem for you then you can take a peek at the next section.

=head2 no_context(&amp;;$)

Usage:

=over 4

=item no_context { ... };

=item no_context { ... } $hid;

    sub my_tool(&amp;) {
        my $code = shift;
        my $ctx = context();
        ...

        no_context {
            # Things in here will not see our current context, they get a new
            # one.

            $code-&gt;();
        };

        ...
        $ctx-&gt;release;
    };

=back

This tool will hide a context for the provided block of code. This means any
tools run inside the block will get a completely new context if they acquire
one. The new context will be inherited by tools nested below the one that
acquired it.

This will normally hide the current context for the top hub. If you need to
hide the context for a different hub you can pass in the optional C&lt;$hid&gt;
parameter.

=head2 intercept(&amp;)

Usage:

    my $events = intercept {
        ok(1, "pass");
        ok(0, "fail");
        ...
    };

This function takes a codeblock as its only argument, and it has a prototype.
It will execute the codeblock, intercepting any generated events in the
process. It will return an array reference with all the generated event
objects. All events should be subclasses of L&lt;Test2::Event&gt;.

As of version 1.302178 the events array that is returned is blssed as an
L&lt;Test2::API::InterceptResult&gt; instance. L&lt;Test2::API::InterceptResult&gt;
Provides a helpful interface for filtering and/or inspecting the events list
overall, or individual events within the list.

This is intended to help you test your test code. This is not intended for
people simply writing tests.

=head2 run_subtest(...)

Usage:

    run_subtest($NAME, \&amp;CODE, $BUFFERED, @ARGS)

    # or

    run_subtest($NAME, \&amp;CODE, \%PARAMS, @ARGS)

This will run the provided codeblock with the args in C&lt;@args&gt;. This codeblock
will be run as a subtest. A subtest is an isolated test state that is condensed
into a single L&lt;Test2::Event::Subtest&gt; event, which contains all events
generated inside the subtest.

=head3 ARGUMENTS:

=over 4

=item $NAME

The name of the subtest.

=item \&amp;CODE

The code to run inside the subtest.

=item $BUFFERED or \%PARAMS

If this is a simple scalar then it will be treated as a boolean for the
'buffered' setting. If this is a hash reference then it will be used as a
parameters hash. The param hash will be used for hub construction (with the
specified keys removed).

Keys that are removed and used by run_subtest:

=over 4

=item 'buffered' =&gt; $bool

Toggle buffered status.

=item 'inherit_trace' =&gt; $bool

Normally the subtest hub is pushed and the sub is allowed to generate its own
root context for the hub. When this setting is turned on a root context will be
created for the hub that shares the same trace as the current context.

Set this to true if your tool is producing subtests without user-specified
subs.

=item 'no_fork' =&gt; $bool

Defaults to off. Normally forking inside a subtest will actually fork the
subtest, resulting in 2 final subtest events. This parameter will turn off that
behavior, only the original process/thread will return a final subtest event.

=back

=item @ARGS

Any extra arguments you want passed into the subtest code.

=back

=head3 BUFFERED VS UNBUFFERED (OR STREAMED)

Normally all events inside and outside a subtest are sent to the formatter
immediately by the hub. Sometimes it is desirable to hold off sending events
within a subtest until the subtest is complete. This usually depends on the
formatter being used.

=over 4

=item Things not effected by this flag

In both cases events are generated and stored in an array. This array is
eventually used to populate the C&lt;subevents&gt; attribute on the
L&lt;Test2::Event::Subtest&gt; event that is generated at the end of the subtest.
This flag has no effect on this part, it always happens.

At the end of the subtest, the final L&lt;Test2::Event::Subtest&gt; event is sent to
the formatter.

=item Things that are effected by this flag

The C&lt;buffered&gt; attribute of the L&lt;Test2::Event::Subtest&gt; event will be set to
the value of this flag. This means any formatter, listener, etc which looks at
the event will know if it was buffered.

=item Things that are formatter dependant

Events within a buffered subtest may or may not be sent to the formatter as
they happen. If a formatter fails to specify then the default is to B&lt;NOT SEND&gt;
the events as they are generated, instead the formatter can pull them from the
C&lt;subevents&gt; attribute.

A formatter can specify by implementing the C&lt;hide_buffered()&gt; method. If this
method returns true then events generated inside a buffered subtest will not be
sent independently of the final subtest event.

=back

An example of how this is used is the L&lt;Test2::Formatter::TAP&gt; formatter. For
unbuffered subtests the events are rendered as they are generated. At the end
of the subtest, the final subtest event is rendered, but the C&lt;subevents&gt;
attribute is ignored. For buffered subtests the opposite occurs, the events are
NOT rendered as they are generated, instead the C&lt;subevents&gt; attribute is used
to render them all at once. This is useful when running subtests tests in
parallel, since without it the output from subtests would be interleaved
together.

=head1 OTHER API EXPORTS

Exports in this section are not commonly needed. These all have the 'test2_'
prefix to help ensure they stand out. You should look at the L&lt;/MAIN API
EXPORTS&gt; section before looking here. This section is one where "Great power
comes with great responsibility". It is possible to break things badly if you
are not careful with these.

All exports are optional. You need to list which ones you want at import time:

    use Test2::API qw/test2_init_done .../;

=head2 STATUS AND INITIALIZATION STATE

These provide access to internal state and object instances.

=over 4

=item $bool = test2_init_done()

This will return true if the stack and IPC instances have already been
initialized. It will return false if they have not. Init happens as late as
possible. It happens as soon as a tool requests the IPC instance, the
formatter, or the stack.

=item $bool = test2_load_done()

This will simply return the boolean value of the loaded flag. If Test2 has
finished loading this will be true, otherwise false. Loading is considered
complete the first time a tool requests a context.

=item test2_set_is_end()

=item test2_set_is_end($bool)

This is used to toggle Test2's belief that the END phase has already started.
With no arguments this will set it to true. With arguments it will set it to
the first argument's value.

This is used to prevent the use of C&lt;caller()&gt; in END blocks which can cause
segfaults. This is only necessary in some persistent environments that may have
multiple END phases.

=item $bool = test2_get_is_end()

Check if Test2 believes it is the END phase.

=item $stack = test2_stack()

This will return the global L&lt;Test2::API::Stack&gt; instance. If this has not
yet been initialized it will be initialized now.

=item $bool = test2_is_testing_done()

This will return true if testing is complete and no other events should be
sent. This is useful in things like warning handlers where you might want to
turn warnings into events, but need them to start acting like normal warnings
when testing is done.

    $SIG{__WARN__} = sub {
        my ($warning) = @_;

        if (test2_is_testing_done()) {
            warn @_;
        }
        else {
            my $ctx = context();
            ...
            $ctx-&gt;release
        }
    }

=item test2_ipc_disable

Disable IPC.

=item $bool = test2_ipc_diabled

Check if IPC is disabled.

=item test2_ipc_wait_enable()

=item test2_ipc_wait_disable()

=item $bool = test2_ipc_wait_enabled()

These can be used to turn IPC waiting on and off, or check the current value of
the flag.

Waiting is turned on by default. Waiting will cause the parent process/thread
to wait until all child processes and threads are finished before exiting. You
will almost never want to turn this off.

=item $bool = test2_no_wait()

=item test2_no_wait($bool)

B&lt;DISCOURAGED&gt;: This is a confusing interface, it is better to use
C&lt;test2_ipc_wait_enable()&gt;, C&lt;test2_ipc_wait_disable()&gt; and
C&lt;test2_ipc_wait_enabled()&gt;.

This can be used to get/set the no_wait status. Waiting is turned on by
default. Waiting will cause the parent process/thread to wait until all child
processes and threads are finished before exiting. You will almost never want
to turn this off.

=item $fh = test2_stdout()

=item $fh = test2_stderr()

These functions return the filehandles that test output should be written to.
They are primarily useful when writing a custom formatter and code that turns
events into actual output (TAP, etc.).  They will return a dupe of the original
filehandles that formatted output can be sent to regardless of whatever state
the currently running test may have left STDOUT and STDERR in.

=item test2_reset_io()

Re-dupe the internal filehandles returned by C&lt;test2_stdout()&gt; and
C&lt;test2_stderr()&gt; from the current STDOUT and STDERR.  You shouldn't need to do
this except in very peculiar situations (for example, you're testing a new
formatter and you need control over where the formatter is sending its output.)

=back

=head2 BEHAVIOR HOOKS

These are hooks that allow you to add custom behavior to actions taken by Test2
and tools built on top of it.

=over 4

=item test2_add_callback_exit(sub { ... })

This can be used to add a callback that is called after all testing is done. This
is too late to add additional results, the main use of this callback is to set the
exit code.

    test2_add_callback_exit(
        sub {
            my ($context, $exit, \$new_exit) = @_;
            ...
        }
    );

The C&lt;$context&gt; passed in will be an instance of L&lt;Test2::API::Context&gt;. The
C&lt;$exit&gt; argument will be the original exit code before anything modified it.
C&lt;$$new_exit&gt; is a reference to the new exit code. You may modify this to
change the exit code. Please note that C&lt;$$new_exit&gt; may already be different
from C&lt;$exit&gt;

=item test2_add_callback_post_load(sub { ... })

Add a callback that will be called when Test2 is finished loading. This
means the callback will be run once, the first time a context is obtained.
If Test2 has already finished loading then the callback will be run immediately.

=item test2_add_callback_testing_done(sub { ... })

This adds your coderef as a follow-up to the root hub after Test2 is finished loading.

This is essentially a helper to do the following:

    test2_add_callback_post_load(sub {
        my $stack = test2_stack();
        $stack-&gt;top; # Insure we have a hub
        my ($hub) = Test2::API::test2_stack-&gt;all;

        $hub-&gt;set_active(1);

        $hub-&gt;follow_up(sub { ... }); # &lt;-- Your coderef here
    });

=item test2_add_callback_context_acquire(sub { ... })

Add a callback that will be called every time someone tries to acquire a
context. This will be called on EVERY call to C&lt;context()&gt;. It gets a single
argument, a reference to the hash of parameters being used the construct the
context. This is your chance to change the parameters by directly altering the
hash.

    test2_add_callback_context_acquire(sub {
        my $params = shift;
        $params-&gt;{level}++;
    });

This is a very scary API function. Please do not use this unless you need to.
This is here for L&lt;Test::Builder&gt; and backwards compatibility. This has you
directly manipulate the hash instead of returning a new one for performance
reasons.

=item test2_add_callback_context_init(sub { ... })

Add a callback that will be called every time a new context is created. The
callback will receive the newly created context as its only argument.

=item test2_add_callback_context_release(sub { ... })

Add a callback that will be called every time a context is released. The
callback will receive the released context as its only argument.

=item test2_add_callback_pre_subtest(sub { ... })

Add a callback that will be called every time a subtest is going to be
run. The callback will receive the subtest name, coderef, and any
arguments.

=item @list = test2_list_context_acquire_callbacks()

Return all the context acquire callback references.

=item @list = test2_list_context_init_callbacks()

Returns all the context init callback references.

=item @list = test2_list_context_release_callbacks()

Returns all the context release callback references.

=item @list = test2_list_exit_callbacks()

Returns all the exit callback references.

=item @list = test2_list_post_load_callbacks()

Returns all the post load callback references.

=item @list = test2_list_pre_subtest_callbacks()

Returns all the pre-subtest callback references.

=item test2_add_uuid_via(sub { ... })

=item $sub = test2_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 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.

=back

=head2 IPC AND CONCURRENCY

These let you access, or specify, the IPC system internals.

=over 4

=item $bool = test2_has_ipc()

Check if IPC is enabled.

=item $ipc = test2_ipc()

This will return the global L&lt;Test2::IPC::Driver&gt; instance. If this has not yet
been initialized it will be initialized now.

=item test2_ipc_add_driver($DRIVER)

Add an IPC driver to the list. This will add the driver to the start of the
list.

=item @drivers = test2_ipc_drivers()

Get the list of IPC drivers.

=item $bool = test2_ipc_polling()

Check if polling is enabled.

=item test2_ipc_enable_polling()

Turn on polling. This will cull events from other processes and threads every
time a context is created.

=item test2_ipc_disable_polling()

Turn off IPC polling.

=item test2_ipc_enable_shm()

Legacy, this is currently a no-op that returns 0;

=item test2_ipc_set_pending($uniq_val)

Tell other processes and events that an event is pending. C&lt;$uniq_val&gt; should
be a unique value no other thread/process will generate.

B&lt;Note:&gt; After calling this C&lt;test2_ipc_get_pending()&gt; will return 1. This is
intentional, and not avoidable.

=item $pending = test2_ipc_get_pending()

This returns -1 if there is no way to check (assume yes)

This returns 0 if there are (most likely) no pending events.

This returns 1 if there are (likely) pending events. Upon return it will reset,
nothing else will be able to see that there were pending events.

=item $timeout = test2_ipc_get_timeout()

=item test2_ipc_set_timeout($timeout)

Get/Set the timeout value for the IPC system. This timeout is how long the IPC
system will wait for child processes and threads to finish before aborting.

The default value is C&lt;30&gt; seconds.

=back

=head2 MANAGING FORMATTERS

These let you access, or specify, the formatters that can/should be used.

=over 4

=item $formatter = test2_formatter

This will return the global formatter class. This is not an instance. By
default the formatter is set to L&lt;Test2::Formatter::TAP&gt;.

You can override this default using the C&lt;T2_FORMATTER&gt; environment variable.

Normally 'Test2::Formatter::' is prefixed to the value in the
environment variable:

    $ T2_FORMATTER='TAP' perl test.t     # Use the Test2::Formatter::TAP formatter
    $ T2_FORMATTER='Foo' perl test.t     # Use the Test2::Formatter::Foo formatter

If you want to specify a full module name you use the '+' prefix:

    $ T2_FORMATTER='+Foo::Bar' perl test.t     # Use the Foo::Bar formatter

=item test2_formatter_set($class_or_instance)

Set the global formatter class. This can only be set once. B&lt;Note:&gt; This will
override anything specified in the 'T2_FORMATTER' environment variable.

=item @formatters = test2_formatters()

Get a list of all loaded formatters.

=item test2_formatter_add($class_or_instance)

Add a formatter to the list. Last formatter added is used at initialization. If
this is called after initialization a warning will be issued.

=back

=head1 OTHER EXAMPLES

See the C&lt;/Examples/&gt; directory included in this distribution.

=head1 SEE ALSO

L&lt;Test2::API::Context&gt; - Detailed documentation of the context object.

L&lt;Test2::IPC&gt; - The IPC system used for threading/fork support.

L&lt;Test2::Formatter&gt; - Formatters such as TAP live here.

L&lt;Test2::Event&gt; - Events live in this namespace.

L&lt;Test2::Hub&gt; - All events eventually funnel through a hub. Custom hubs are how
C&lt;intercept()&gt; and C&lt;run_subtest()&gt; are implemented.

=head1 MAGIC

This package has an END block. This END block is responsible for setting the
exit code based on the test results. This end block also calls the callbacks that
can be added to this package.

=head1 SOURCE

The source code repository for Test2 can be found at
F&lt;http://github.com/Test-More/test-more/&gt;.

=head1 MAINTAINERS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 AUTHORS

=over 4

=item Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;

=back

=head1 COPYRIGHT

Copyright 2020 Chad Granum E&lt;lt&gt;exodist@cpan.orgE&lt;gt&gt;.

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

See F&lt;http://dev.perl.org/licenses/&gt;

=cut
</pre></body></html>