1package Test2::Hub::Subtest;
2use strict;
3use warnings;
4
5our $VERSION = '1.302190';
6
7BEGIN { require Test2::Hub; our @ISA = qw(Test2::Hub) }
8use Test2::Util::HashBase qw/nested exit_code manual_skip_all/;
9use Test2::Util qw/get_tid/;
10
11sub is_subtest { 1 }
12
13sub inherit {
14    my $self = shift;
15    my ($from) = @_;
16
17    $self->SUPER::inherit($from);
18
19    $self->{+NESTED} = $from->nested + 1;
20}
21
22{
23    # Legacy
24    no warnings 'once';
25    *ID = \&Test2::Hub::HID;
26    *id = \&Test2::Hub::hid;
27    *set_id = \&Test2::Hub::set_hid;
28}
29
30sub send {
31    my $self = shift;
32    my ($e) = @_;
33
34    my $out = $self->SUPER::send($e);
35
36    return $out if $self->{+MANUAL_SKIP_ALL};
37
38    my $f = $e->facet_data;
39
40    my $plan = $f->{plan} or return $out;
41    return $out unless $plan->{skip};
42
43    my $trace = $f->{trace} or die "Missing Trace!";
44    return $out unless $trace->{pid} != $self->pid
45                    || $trace->{tid} != $self->tid;
46
47    no warnings 'exiting';
48    last T2_SUBTEST_WRAPPER;
49}
50
51sub terminate {
52    my $self = shift;
53    my ($code, $e, $f) = @_;
54    $self->set_exit_code($code);
55
56    return if $self->{+MANUAL_SKIP_ALL};
57
58    $f ||= $e->facet_data;
59
60    if(my $plan = $f->{plan}) {
61        my $trace = $f->{trace} or die "Missing Trace!";
62        return if $plan->{skip}
63               && ($trace->{pid} != $$ || $trace->{tid} != get_tid);
64    }
65
66    no warnings 'exiting';
67    last T2_SUBTEST_WRAPPER;
68}
69
701;
71
72__END__
73
74=pod
75
76=encoding UTF-8
77
78=head1 NAME
79
80Test2::Hub::Subtest - Hub used by subtests
81
82=head1 DESCRIPTION
83
84Subtests make use of this hub to route events.
85
86=head1 TOGGLES
87
88=over 4
89
90=item $bool = $hub->manual_skip_all
91
92=item $hub->set_manual_skip_all($bool)
93
94The default is false.
95
96Normally a skip-all plan event will cause a subtest to stop executing. This is
97accomplished via C<last LABEL> to a label inside the subtest code. Most of the
98time this is perfectly fine. There are times however where this flow control
99causes bad things to happen.
100
101This toggle lets you turn off the abort logic for the hub. When this is toggled
102to true B<you> are responsible for ensuring no additional events are generated.
103
104=back
105
106=head1 SOURCE
107
108The source code repository for Test2 can be found at
109F<http://github.com/Test-More/test-more/>.
110
111=head1 MAINTAINERS
112
113=over 4
114
115=item Chad Granum E<lt>exodist@cpan.orgE<gt>
116
117=back
118
119=head1 AUTHORS
120
121=over 4
122
123=item Chad Granum E<lt>exodist@cpan.orgE<gt>
124
125=back
126
127=head1 COPYRIGHT
128
129Copyright 2020 Chad Granum E<lt>exodist@cpan.orgE<gt>.
130
131This program is free software; you can redistribute it and/or
132modify it under the same terms as Perl itself.
133
134See F<http://dev.perl.org/licenses/>
135
136=cut
137