1package Test2::Hub::Interceptor; 2use strict; 3use warnings; 4 5our $VERSION = '1.302194'; 6 7 8use Test2::Hub::Interceptor::Terminator(); 9 10BEGIN { require Test2::Hub; our @ISA = qw(Test2::Hub) } 11use Test2::Util::HashBase; 12 13sub init { 14 my $self = shift; 15 $self->SUPER::init(); 16 $self->{+NESTED} = 0; 17} 18 19sub inherit { 20 my $self = shift; 21 my ($from, %params) = @_; 22 23 $self->{+NESTED} = 0; 24 25 if ($from->{+IPC} && !$self->{+IPC} && !exists($params{ipc})) { 26 my $ipc = $from->{+IPC}; 27 $self->{+IPC} = $ipc; 28 $ipc->add_hub($self->{+HID}); 29 } 30 31 if (my $ls = $from->{+_LISTENERS}) { 32 push @{$self->{+_LISTENERS}} => grep { $_->{intercept_inherit} } @$ls; 33 } 34 35 if (my $pfs = $from->{+_PRE_FILTERS}) { 36 push @{$self->{+_PRE_FILTERS}} => grep { $_->{intercept_inherit} } @$pfs; 37 } 38 39 if (my $fs = $from->{+_FILTERS}) { 40 push @{$self->{+_FILTERS}} => grep { $_->{intercept_inherit} } @$fs; 41 } 42} 43 44sub clean_inherited { 45 my $self = shift; 46 my %params = @_; 47 48 my @sets = ( 49 $self->{+_LISTENERS}, 50 $self->{+_PRE_FILTERS}, 51 $self->{+_FILTERS}, 52 ); 53 54 for my $set (@sets) { 55 next unless $set; 56 57 for my $i (@$set) { 58 my $cbs = $i->{intercept_inherit} or next; 59 next unless ref($cbs) eq 'HASH'; 60 my $cb = $cbs->{clean} or next; 61 $cb->(%params); 62 } 63 } 64} 65 66sub restore_inherited { 67 my $self = shift; 68 my %params = @_; 69 70 my @sets = ( 71 $self->{+_FILTERS}, 72 $self->{+_PRE_FILTERS}, 73 $self->{+_LISTENERS}, 74 ); 75 76 for my $set (@sets) { 77 next unless $set; 78 79 for my $i (@$set) { 80 my $cbs = $i->{intercept_inherit} or next; 81 next unless ref($cbs) eq 'HASH'; 82 my $cb = $cbs->{restore} or next; 83 $cb->(%params); 84 } 85 } 86} 87 88sub terminate { 89 my $self = shift; 90 my ($code) = @_; 91 92 eval { 93 no warnings 'exiting'; 94 last T2_SUBTEST_WRAPPER; 95 }; 96 my $err = $@; 97 98 # Fallback 99 die bless(\$err, 'Test2::Hub::Interceptor::Terminator'); 100} 101 1021; 103 104__END__ 105 106=pod 107 108=encoding UTF-8 109 110=head1 NAME 111 112Test2::Hub::Interceptor - Hub used by interceptor to grab results. 113 114=head1 SOURCE 115 116The source code repository for Test2 can be found at 117F<http://github.com/Test-More/test-more/>. 118 119=head1 MAINTAINERS 120 121=over 4 122 123=item Chad Granum E<lt>exodist@cpan.orgE<gt> 124 125=back 126 127=head1 AUTHORS 128 129=over 4 130 131=item Chad Granum E<lt>exodist@cpan.orgE<gt> 132 133=back 134 135=head1 COPYRIGHT 136 137Copyright 2020 Chad Granum E<lt>exodist@cpan.orgE<gt>. 138 139This program is free software; you can redistribute it and/or 140modify it under the same terms as Perl itself. 141 142See F<http://dev.perl.org/licenses/> 143 144=cut 145