blib/lib/Test2/Hub.pm

filter: Statementstmt 99.6% 312 / 313 Branchbran 92.3% 144 / 156 Conditioncond 78.6% 107 / 136 MC/DCmcdc 60.7% 48 / 79 Subroutinesub 100% 38 / 38 Podpod 77.7% 21 / 27 totaltotal 89.4% 670 / 749 CC 133 SCAR 25.8
CC
133
Cov
93%
process
35.0
finalize
16.0
is_passing
15.0
CRAP 13.1
« blib/lib/Test2/Util/Stash.pm ↑ Summary blib/lib/Test2/V0.pm »
1 package Test2::Hub;
2 455 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 455 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 455 our $VERSION = '1.302226';
6  
7  
8 455 ▶use Carp qw/carp croak confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 455 ▶use Test2::Util qw/get_tid gen_uid/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 455 ▶use Scalar::Util qw/weaken/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 455 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 455 ▶use Test2::Util::ExternalMeta qw/meta get_meta set_meta delete_meta/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 455 ▶use Test2::Util::HashBase qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
16 pid tid hid ipc
17 nested buffered
18 no_ending
19 _filters
20 _pre_filters
21 _listeners
22 _follow_ups
23 _formatter
24 _context_acquire
25 _context_init
26 _context_release
27  
28 suppress_release_error
29  
30 uuid
31 active
32 count
33 failed
34 ended
35 bailed_out
36 _passing
37 _plan
38 skip_reason
39 455 };
40  
41 {
42 455 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
43 # Support an originally misspelled method name, at least 1 downstream
44 # release already uses it. It will be fixed, but we do not want to break
45 # things before it is fixed.
46 455 *surpress_release_error = \&suppress_release_error;
47 }
48  
49 455 my $UUID_VIA;
50  
51 2044 ▶sub init {
Subroutine init: called CC=7 SCAR=19.5
Pod undocumented
52 2044 my $self = shift;
53  
54 2044 $self->{+PID} = $$;
55 2044 $self->{+TID} = get_tid();
56 2044 $self->{+HID} = gen_uid();
57  
58 2044 ▶ $UUID_VIA ||= Test2::API::_add_uuid_via_ref();
Condition66%2/3
$UUID_VIA ||= Test2::API::_add_uuid_via_ref()
l!l&&r!l&&!r
15904540
MC/DC0%0/2
$UUID_VIA ||= Test2::API::_add_uuid_via_ref()
$UUID_VIA Test2::API::_add_uuid_via_ref()
Truth table66%2/3
A ||= B
A= $UUID_VIAB= Test2::API::_add_uuid_via_ref()
ABresult
1X1
011
000
59 2044 ▶ $self->{+UUID} = ${$UUID_VIA}->('hub') if $$UUID_VIA;
Branch: 1 branch
BranchTrueFalseTotal
if $$UUID_VIA 9 2035 2044
60  
61 2044 ▶ $self->{+NESTED} = 0 unless defined $self->{+NESTED};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"nested"} 1534 510 2044
62 2044 ▶ $self->{+BUFFERED} = 0 unless defined $self->{+BUFFERED};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"buffered"} 1169 875 2044
63  
64 2044 $self->{+COUNT} = 0;
65 2044 $self->{+FAILED} = 0;
66 2044 $self->{+_PASSING} = 1;
67  
68 2044 ▶ if (my $formatter = delete $self->{formatter}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $formatter = delete $self->{"formatter"}) 185 1859 2044
69 185 $self->format($formatter);
70 }
71  
72 2044 ▶ if (my $ipc = $self->{+IPC}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ipc = $self->{"ipc"}) 640 1404 2044
73 640 $ipc->add_hub($self->{+HID});
74 }
75 }
76  
77 397 ▶sub is_subtest { 0 }
Subroutine is_subtest: called CC=1 SCAR=0.0
Pod undocumented
78  
79 55 ▶sub _tb_reset {
Subroutine _tb_reset: called CC=4 SCAR=14.2
80 55 my $self = shift;
81  
82 # Nothing to do
83 55 ▶ return if $self->{+PID} == $$ && $self->{+TID} == get_tid();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pid"} == $$ and $self->{"tid"} == 0 54 1 55
Condition66%2/3
$self->{"pid"} == $$ and $self->{"tid"} == 0
!ll&&!rl&&r
1054
MC/DC50%1/2
$self->{"pid"} == $$ and $self->{"tid"} == 0
$self->{"pid"} == $$ $self->{"tid"} == 0
Truth table66%2/3
A and B
A= $self->{"pid"} == $$B= $self->{"tid"} == 0
ABresult
0X0
100
111
84  
85 1 $self->{+PID} = $$;
86 1 $self->{+TID} = get_tid();
87 1 $self->{+HID} = gen_uid();
88  
89 1 ▶ if (my $ipc = $self->{+IPC}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ipc = $self->{"ipc"}) 0 1 1
90 0 $ipc->add_hub($self->{+HID});
91 }
92 }
93  
94 58 ▶sub reset_state {
Subroutine reset_state: called CC=1 SCAR=0.0
Pod documented
95 58 my $self = shift;
96  
97 58 $self->{+COUNT} = 0;
98 58 $self->{+FAILED} = 0;
99 58 $self->{+_PASSING} = 1;
100  
101 58 delete $self->{+_PLAN};
102 58 delete $self->{+ENDED};
103 58 delete $self->{+BAILED_OUT};
104 58 delete $self->{+SKIP_REASON};
105 }
106  
107 540 ▶sub inherit {
Subroutine inherit: called CC=10 SCAR=23.1
Pod undocumented
108 540 my $self = shift;
109 540 my ($from, %params) = @_;
110  
111 540 ▶ $self->{+NESTED} ||= 0;
Condition50%1/2
$self->{"nested"} ||= 0
l!l
0540
MC/DC0%0/1
$self->{"nested"} ||= 0
$self->{"nested"}
Truth table50%1/2
A
A= $self->{"nested"}
Aresult
11
00
112  
113 $self->{+_FORMATTER} = $from->{+_FORMATTER}
114 540 ▶ unless $self->{+_FORMATTER} || exists($params{formatter});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_formatter"} or exists $params{"formatter"} 539 1 540
Condition66%2/3
$self->{"_formatter"} or exists $params{"formatter"}
l!l&&r!l&&!r
01539
MC/DC50%1/2
$self->{"_formatter"} or exists $params{"formatter"}
$self->{"_formatter"} exists $params{"formatter"}
Truth table66%2/3
A or B
A= $self->{"_formatter"}B= exists $params{"formatter"}
ABresult
1X1
011
000
115  
116 540 ▶ if ($from->{+IPC} && !$self->{+IPC} && !exists($params{ipc})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from->{"ipc"} and not $self->{"ipc"} and not exists $params{"ipc"}) 46 494 540
Condition83%5/6
$from->{"ipc"} and not $self->{"ipc"} and not exists $params{"ipc"}
!ll&&!rl&&r
493146
$from->{"ipc"} and not $self->{"ipc"}
!ll&&!rl&&r
493047
MC/DC66%2/3
$from->{"ipc"} and not $self->{"ipc"} and not exists $params{"ipc"}
$from->{"ipc"} not $self->{"ipc"} not exists $params{"ipc"}
Truth table75%3/4
A and not(B) and not(C)
A= $from->{"ipc"}B= not $self->{"ipc"}C= not exists $params{"ipc"}
ABCresult
0XX0
10X0
1100
1111
117 46 my $ipc = $from->{+IPC};
118 46 $self->{+IPC} = $ipc;
119 46 $ipc->add_hub($self->{+HID});
120 }
121  
122 540 ▶ if (my $ls = $from->{+_LISTENERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ls = $from->{"_listeners"}) 93 447 540
123 93 push @{$self->{+_LISTENERS}} => grep { $_->{inherit} } @$ls;
124 }
125  
126 540 ▶ if (my $pfs = $from->{+_PRE_FILTERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pfs = $from->{"_pre_filters"}) 178 362 540
127 178 push @{$self->{+_PRE_FILTERS}} => grep { $_->{inherit} } @$pfs;
128 }
129  
130 540 ▶ if (my $fs = $from->{+_FILTERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fs = $from->{"_filters"}) 12 528 540
131 12 push @{$self->{+_FILTERS}} => grep { $_->{inherit} } @$fs;
132 }
133 }
134  
135 5920 ▶sub format {
Subroutine format: called CC=2 SCAR=6.9
Pod documented
136 5920 my $self = shift;
137  
138 5920 my $old = $self->{+_FORMATTER};
139 5920 ▶ ($self->{+_FORMATTER}) = @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1273 4647 5920
140  
141 5920 return $old;
142 }
143  
144 2627 ▶sub is_local {
Subroutine is_local: called CC=2 SCAR=7.1
Pod undocumented
145 2627 my $self = shift;
146 return $$ == $self->{+PID}
147 2627 ▶ && get_tid() == $self->{+TID};
Condition66%2/3
$$ == $self->{'pid'} && 0 == $self->{'tid'}
!ll&&!rl&&r
22402403
MC/DC50%1/2
$$ == $self->{'pid'} && 0 == $self->{'tid'}
$$ == $self->{'pid'} 0 == $self->{'tid'}
Truth table66%2/3
A && B
A= $$ == $self->{'pid'}B= 0 == $self->{'tid'}
ABresult
0X0
100
111
148 }
149  
150 1453 ▶sub listen {
Subroutine listen: called CC=5 SCAR=16.7
Pod documented
151 1453 my $self = shift;
152 1453 my ($sub, %params) = @_;
153  
154 carp "Useless addition of a listener in a child process or thread!"
155 1453 ▶ if $$ != $self->{+PID} || get_tid() != $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
if $$ != $self->{"pid"} or 0 != $self->{"tid"} 0 1453 1453
Condition33%1/3
$$ != $self->{"pid"} or 0 != $self->{"tid"}
l!l&&r!l&&!r
001453
MC/DC0%0/2
$$ != $self->{"pid"} or 0 != $self->{"tid"}
$$ != $self->{"pid"} 0 != $self->{"tid"}
Truth table33%1/3
A or B
A= $$ != $self->{"pid"}B= 0 != $self->{"tid"}
ABresult
1X1
011
000
156  
157 1453 ▶ croak "listen only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 1 1452 1453
Condition66%2/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
101452
MC/DC50%1/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table66%2/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
158 unless ref $sub && ref $sub eq 'CODE';
159  
160 1452 push @{$self->{+_LISTENERS}} => { %params, code => $sub };
161  
162 1452 $sub; # Intentional return.
163 }
164  
165 5 ▶sub unlisten {
Subroutine unlisten: called CC=3 SCAR=11.3
Pod documented
166 5 my $self = shift;
167  
168 carp "Useless removal of a listener in a child process or thread!"
169 5 ▶ if $$ != $self->{+PID} || get_tid() != $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
if $$ != $self->{"pid"} or 0 != $self->{"tid"} 0 5 5
Condition33%1/3
$$ != $self->{"pid"} or 0 != $self->{"tid"}
l!l&&r!l&&!r
005
MC/DC0%0/2
$$ != $self->{"pid"} or 0 != $self->{"tid"}
$$ != $self->{"pid"} 0 != $self->{"tid"}
Truth table33%1/3
A or B
A= $$ != $self->{"pid"}B= 0 != $self->{"tid"}
ABresult
1X1
011
000
170  
171 5 my %subs = map {$_ => $_} @_;
172  
173 5 @{$self->{+_LISTENERS}} = grep { !$subs{$_->{code}} } @{$self->{+_LISTENERS}};
174 }
175  
176 11 ▶sub filter {
Subroutine filter: called CC=5 SCAR=16.7
Pod documented
177 11 my $self = shift;
178 11 my ($sub, %params) = @_;
179  
180 carp "Useless addition of a filter in a child process or thread!"
181 11 ▶ if $$ != $self->{+PID} || get_tid() != $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
if $$ != $self->{"pid"} or 0 != $self->{"tid"} 0 11 11
Condition33%1/3
$$ != $self->{"pid"} or 0 != $self->{"tid"}
l!l&&r!l&&!r
0011
MC/DC0%0/2
$$ != $self->{"pid"} or 0 != $self->{"tid"}
$$ != $self->{"pid"} 0 != $self->{"tid"}
Truth table33%1/3
A or B
A= $$ != $self->{"pid"}B= 0 != $self->{"tid"}
ABresult
1X1
011
000
182  
183 11 ▶ croak "filter only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 1 10 11
Condition66%2/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
1010
MC/DC50%1/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table66%2/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
184 unless ref $sub && ref $sub eq 'CODE';
185  
186 10 push @{$self->{+_FILTERS}} => { %params, code => $sub };
187  
188 10 $sub; # Intentional Return
189 }
190  
191 2 ▶sub unfilter {
Subroutine unfilter: called CC=3 SCAR=11.3
Pod documented
192 2 my $self = shift;
193 carp "Useless removal of a filter in a child process or thread!"
194 2 ▶ if $$ != $self->{+PID} || get_tid() != $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
if $$ != $self->{"pid"} or 0 != $self->{"tid"} 0 2 2
Condition33%1/3
$$ != $self->{"pid"} or 0 != $self->{"tid"}
l!l&&r!l&&!r
002
MC/DC0%0/2
$$ != $self->{"pid"} or 0 != $self->{"tid"}
$$ != $self->{"pid"} 0 != $self->{"tid"}
Truth table33%1/3
A or B
A= $$ != $self->{"pid"}B= 0 != $self->{"tid"}
ABresult
1X1
011
000
195 2 my %subs = map {$_ => $_} @_;
196 2 @{$self->{+_FILTERS}} = grep { !$subs{$_->{code}} } @{$self->{+_FILTERS}};
197 }
198  
199 516 ▶sub pre_filter {
Subroutine pre_filter: called CC=3 SCAR=11.0
Pod documented
200 516 my $self = shift;
201 516 my ($sub, %params) = @_;
202  
203 516 ▶ croak "pre_filter only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 1 515 516
Condition66%2/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
10515
MC/DC50%1/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table66%2/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
204 unless ref $sub && ref $sub eq 'CODE';
205  
206 515 push @{$self->{+_PRE_FILTERS}} => { %params, code => $sub };
207  
208 515 $sub; # Intentional Return
209 }
210  
211 103 ▶sub pre_unfilter {
Subroutine pre_unfilter: called CC=1 SCAR=0.0
Pod documented
212 103 my $self = shift;
213 103 my %subs = map {$_ => $_} @_;
214 103 @{$self->{+_PRE_FILTERS}} = grep { !$subs{$_->{code}} } @{$self->{+_PRE_FILTERS}};
215 }
216  
217 38 ▶sub follow_up {
Subroutine follow_up: called CC=5 SCAR=16.8
Pod documented
218 38 my $self = shift;
219 38 my ($sub) = @_;
220  
221 carp "Useless addition of a follow-up in a child process or thread!"
222 38 ▶ if $$ != $self->{+PID} || get_tid() != $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
if $$ != $self->{"pid"} or 0 != $self->{"tid"} 0 38 38
Condition33%1/3
$$ != $self->{"pid"} or 0 != $self->{"tid"}
l!l&&r!l&&!r
0038
MC/DC0%0/2
$$ != $self->{"pid"} or 0 != $self->{"tid"}
$$ != $self->{"pid"} 0 != $self->{"tid"}
Truth table33%1/3
A or B
A= $$ != $self->{"pid"}B= 0 != $self->{"tid"}
ABresult
1X1
011
000
223  
224 38 ▶ croak "follow_up only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 2 36 38
Condition66%2/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
2036
MC/DC50%1/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table66%2/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
225 unless ref $sub && ref $sub eq 'CODE';
226  
227 36 push @{$self->{+_FOLLOW_UPS}} => $sub;
228 }
229  
230 455 *add_context_aquire = \&add_context_acquire;
231 1 ▶sub add_context_acquire {
Subroutine add_context_acquire: called CC=3 SCAR=11.6
Pod documented
232 1 my $self = shift;
233 1 my ($sub) = @_;
234  
235 1 ▶ croak "add_context_acquire only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 0 1 1
Condition33%1/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table33%1/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
236 unless ref $sub && ref $sub eq 'CODE';
237  
238 1 push @{$self->{+_CONTEXT_ACQUIRE}} => $sub;
239  
240 1 $sub; # Intentional return.
241 }
242  
243 455 *remove_context_aquire = \&remove_context_acquire;
244 1 ▶sub remove_context_acquire {
Subroutine remove_context_acquire: called CC=1 SCAR=0.0
Pod documented
245 1 my $self = shift;
246 1 my %subs = map {$_ => 1} @_;
247 1 @{$self->{+_CONTEXT_ACQUIRE}} = grep { !$subs{$_} } @{$self->{+_CONTEXT_ACQUIRE}};
248 }
249  
250 1 ▶sub add_context_init {
Subroutine add_context_init: called CC=3 SCAR=11.6
Pod documented
251 1 my $self = shift;
252 1 my ($sub) = @_;
253  
254 1 ▶ croak "add_context_init only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 0 1 1
Condition33%1/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table33%1/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
255 unless ref $sub && ref $sub eq 'CODE';
256  
257 1 push @{$self->{+_CONTEXT_INIT}} => $sub;
258  
259 1 $sub; # Intentional return.
260 }
261  
262 1 ▶sub remove_context_init {
Subroutine remove_context_init: called CC=1 SCAR=0.0
Pod documented
263 1 my $self = shift;
264 1 my %subs = map {$_ => 1} @_;
265 1 @{$self->{+_CONTEXT_INIT}} = grep { !$subs{$_} } @{$self->{+_CONTEXT_INIT}};
266 }
267  
268 1 ▶sub add_context_release {
Subroutine add_context_release: called CC=3 SCAR=11.6
Pod documented
269 1 my $self = shift;
270 1 my ($sub) = @_;
271  
272 1 ▶ croak "add_context_release only takes coderefs for arguments, got '$sub'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $sub and ref $sub eq "CODE" 0 1 1
Condition33%1/3
ref $sub and ref $sub eq "CODE"
!ll&&!rl&&r
001
MC/DC0%0/2
ref $sub and ref $sub eq "CODE"
ref $sub ref $sub eq "CODE"
Truth table33%1/3
A and B
A= ref $subB= ref $sub eq "CODE"
ABresult
0X0
100
111
273 unless ref $sub && ref $sub eq 'CODE';
274  
275 1 push @{$self->{+_CONTEXT_RELEASE}} => $sub;
276  
277 1 $sub; # Intentional return.
278 }
279  
280 1 ▶sub remove_context_release {
Subroutine remove_context_release: called CC=1 SCAR=0.0
Pod documented
281 1 my $self = shift;
282 1 my %subs = map {$_ => 1} @_;
283 1 @{$self->{+_CONTEXT_RELEASE}} = grep { !$subs{$_} } @{$self->{+_CONTEXT_RELEASE}};
284 }
285  
286 11563 ▶sub send {
Subroutine send: called CC=10 SCAR=23.0
Pod documented
287 11563 my $self = shift;
288 11563 my ($e) = @_;
289  
290 11563 $e->eid;
291  
292 $e->add_hub(
293 {
294 details => ref($self),
295  
296 buffered => $self->{+BUFFERED},
297 hid => $self->{+HID},
298 nested => $self->{+NESTED},
299 pid => $self->{+PID},
300 tid => $self->{+TID},
301 uuid => $self->{+UUID},
302  
303 11563 ▶ ipc => $self->{+IPC} ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'ipc'} ? : 2679 8884 11563
304 }
305 );
306  
307 11563 ▶ $e->set_uuid(${$UUID_VIA}->('event')) if $$UUID_VIA;
Branch: 1 branch
BranchTrueFalseTotal
if $$UUID_VIA 73 11490 11563
308  
309 11563 ▶ if ($self->{+_PRE_FILTERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_pre_filters"}) 4042 7521 11563
310 4042 for (@{$self->{+_PRE_FILTERS}}) {
311 5503 $e = $_->{code}->($self, $e);
312 5503 ▶ return unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 3 5500 5503
313 }
314 }
315  
316 11560 ▶ my $ipc = $self->{+IPC} || return $self->process($e);
Condition100%2/2
$self->{'ipc'} || (return $self->process($e))
l!l
26798881
MC/DC100%1/1
$self->{'ipc'} || (return $self->process($e))
$self->{'ipc'}
Truth table100%2/2
A
A= $self->{'ipc'}
Aresult
11
00
317  
318 2679 ▶ if($e->global) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->global) 1 2678 2679
319 1 $ipc->send($self->{+HID}, $e, 'GLOBAL');
320 1 return $self->process($e);
321 }
322  
323 return $ipc->send($self->{+HID}, $e)
324 2678 ▶ if $$ != $self->{+PID} || get_tid() != $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
if $$ != $self->{"pid"} or 0 != $self->{"tid"} 176 2502 2678
Condition66%2/3
$$ != $self->{"pid"} or 0 != $self->{"tid"}
l!l&&r!l&&!r
17602502
MC/DC50%1/2
$$ != $self->{"pid"} or 0 != $self->{"tid"}
$$ != $self->{"pid"} 0 != $self->{"tid"}
Truth table66%2/3
A or B
A= $$ != $self->{"pid"}B= 0 != $self->{"tid"}
ABresult
1X1
011
000
325  
326 2502 $self->process($e);
327 }
328  
329 12139 ▶sub process {
Subroutine process: called CC=35 SCAR=35.6
Pod documented
330 12139 my $self = shift;
331 12139 my ($e) = @_;
332  
333 12139 ▶ if ($self->{+_FILTERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_filters"}) 18 12121 12139
334 18 for (@{$self->{+_FILTERS}}) {
335 17 $e = $_->{code}->($self, $e);
336 17 ▶ return unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 9 8 17
337 }
338 }
339  
340 # Optimize the most common case
341 12130 my $type = ref($e);
342 12130 ▶ if ($type eq 'Test2::Event::Pass' || ($type eq 'Test2::Event::Ok' && $e->{pass})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "Test2::Event::Pass" or $type eq "Test2::Event::Ok" and $e->{"pass"}) 6202 5928 12130
Condition100%6/6
$type eq "Test2::Event::Pass" or $type eq "Test2::Event::Ok" and $e->{"pass"}
l!l&&r!l&&!r
195242505928
$type eq "Test2::Event::Ok" and $e->{"pass"}
!ll&&!rl&&r
54055234250
MC/DC100%3/3
$type eq "Test2::Event::Pass" or $type eq "Test2::Event::Ok" and $e->{"pass"}
$type eq "Test2::Event::Pass" $type eq "Test2::Event::Ok" $e->{"pass"}
Truth table100%4/4
A or B and C
A= $type eq "Test2::Event::Pass"B= $type eq "Test2::Event::Ok"C= $e->{"pass"}
ABCresult
1XX1
0111
00X0
0100
343 6202 my $count = ++($self->{+COUNT});
344 6202 ▶ $self->{+_FORMATTER}->write($e, $count) if $self->{+_FORMATTER};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_formatter"} 3554 2648 6202
345  
346 6202 ▶ if ($self->{+_LISTENERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_listeners"}) 2778 3424 6202
347 2778 $_->{code}->($self, $e, $count) for @{$self->{+_LISTENERS}};
348 }
349  
350 6202 return $e;
351 }
352  
353 5928 my $f = $e->facet_data;
354  
355 5928 my $fail = 0;
356 5928 ▶ $fail = 1 if $f->{assert} && !$f->{assert}->{pass};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"assert"} and not $f->{"assert"}{"pass"} 877 5051 5928
Condition100%3/3
$f->{"assert"} and not $f->{"assert"}{"pass"}
!ll&&!rl&&r
4166885877
MC/DC100%2/2
$f->{"assert"} and not $f->{"assert"}{"pass"}
$f->{"assert"} not $f->{"assert"}{"pass"}
Truth table100%3/3
A and not(B)
A= $f->{"assert"}B= not $f->{"assert"}{"pass"}
ABresult
0X0
100
111
357 5928 ▶ $fail = 1 if $f->{errors} && grep { $_->{fail} } @{$f->{errors}};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"errors"} and grep {$_->{"fail"};} @{$$f{"errors"};} 14 5914 5928
Condition100%3/3
$f->{"errors"} and grep {$_->{"fail"};} @{$$f{"errors"};}
!ll&&!rl&&r
5911314
MC/DC100%2/2
$f->{"errors"} and grep {$_->{"fail"};} @{$$f{"errors"};}
$f->{"errors"} grep {$_->{"fail"};} @{$$f{"errors"};}
Truth table100%3/3
A and B
A= $f->{"errors"}B= grep {$_->{"fail"};} @{$$f{"errors"};}
ABresult
0X0
100
111
358 5928 ▶ $fail = 0 if $f->{amnesty};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"amnesty"} 490 5438 5928
359  
360 5928 ▶ $self->{+COUNT}++ if $f->{assert};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"assert"} 1762 4166 5928
361 5928 ▶ $self->{+FAILED}++ if $fail && $f->{assert};
Branch: 1 branch
BranchTrueFalseTotal
if $fail and $f->{"assert"} 603 5325 5928
Condition100%3/3
$fail and $f->{"assert"}
!ll&&!rl&&r
531312603
MC/DC100%2/2
$fail and $f->{"assert"}
$fail $f->{"assert"}
Truth table100%3/3
A and B
A= $failB= $f->{"assert"}
ABresult
0X0
100
111
362 5928 ▶ $self->{+_PASSING} = 0 if $fail;
Branch: 1 branch
BranchTrueFalseTotal
if $fail 615 5313 5928
363  
364 5928 ▶ my $code = $f->{control} ? $f->{control}->{terminate} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$f->{'control'} ? : 2151 3777 5928
365 5928 my $count = $self->{+COUNT};
366  
367 5928 ▶ if (my $plan = $f->{plan}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $plan = $f->{"plan"}) 1330 4598 5928
368 1330 ▶ if ($plan->{skip}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($plan->{'skip'}) { } 174 1156 1330
elsif ($plan->{'none'}) { } 1 1155 1156
369 174 $self->plan('SKIP');
370 174 ▶ $self->set_skip_reason($plan->{details} || 1);
Condition100%2/2
$plan->{'details'} || 1
l!l
1722
MC/DC100%1/1
$plan->{'details'} || 1
$plan->{'details'}
Truth table100%2/2
A
A= $plan->{'details'}
Aresult
11
00
371 174 ▶ $code ||= 0;
Condition50%1/2
$code ||= 0
l!l
0174
MC/DC0%0/1
$code ||= 0
$code
Truth table50%1/2
A
A= $code
Aresult
11
00
372 }
373 elsif ($plan->{none}) {
374 1 $self->plan('NO PLAN');
375 }
376 else {
377 1155 $self->plan($plan->{count});
378 }
379 }
380  
381 5928 ▶ $e->callback($self) if $f->{control} && $f->{control}->{has_callback};
Branch: 1 branch
BranchTrueFalseTotal
if $f->{"control"} and $f->{"control"}{"has_callback"} 432 5496 5928
Condition100%3/3
$f->{"control"} and $f->{"control"}{"has_callback"}
!ll&&!rl&&r
37771719432
MC/DC100%2/2
$f->{"control"} and $f->{"control"}{"has_callback"}
$f->{"control"} $f->{"control"}{"has_callback"}
Truth table100%3/3
A and B
A= $f->{"control"}B= $f->{"control"}{"has_callback"}
ABresult
0X0
100
111
382  
383 5928 ▶ $self->{+_FORMATTER}->write($e, $count, $f) if $self->{+_FORMATTER};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_formatter"} 2901 3027 5928
384  
385 5928 ▶ if ($self->{+_LISTENERS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_listeners"}) 3494 2434 5928
386 3494 $_->{code}->($self, $e, $count, $f) for @{$self->{+_LISTENERS}};
387 }
388  
389 5928 ▶ if ($f->{control} && $f->{control}->{halt}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f->{"control"} and $f->{"control"}{"halt"}) 18 5910 5928
Condition100%3/3
$f->{"control"} and $f->{"control"}{"halt"}
!ll&&!rl&&r
1844406618
MC/DC100%2/2
$f->{"control"} and $f->{"control"}{"halt"}
$f->{"control"} $f->{"control"}{"halt"}
Truth table100%3/3
A and B
A= $f->{"control"}B= $f->{"control"}{"halt"}
ABresult
0X0
100
111
390 18 ▶ $code ||= 255;
Condition100%2/2
$code ||= 255
l!l
162
MC/DC100%1/1
$code ||= 255
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
391 18 $self->set_bailed_out($e);
392 }
393  
394 5928 ▶ if (defined $code) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code) 192 5736 5928
395 192 ▶ $self->{+_FORMATTER}->terminate($e, $f) if $self->{+_FORMATTER};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_formatter"} 33 159 192
396 192 $self->terminate($code, $e, $f);
397 }
398  
399 5875 return $e;
400 }
401  
402 25 ▶sub terminate {
Subroutine terminate: called CC=1 SCAR=0.0
Pod undocumented
403 25 my $self = shift;
404 25 my ($code) = @_;
405 25 exit($code);
406 }
407  
408 5670 ▶sub cull {
Subroutine cull: called CC=5 SCAR=16.1
Pod documented
409 5670 my $self = shift;
410  
411 5670 ▶ my $ipc = $self->{+IPC} || return;
Condition100%2/2
$self->{'ipc'} || (return)
l!l
46001070
MC/DC100%1/1
$self->{'ipc'} || (return)
$self->{'ipc'}
Truth table100%2/2
A
A= $self->{'ipc'}
Aresult
11
00
412 4600 ▶ return if $self->{+PID} != $$ || $self->{+TID} != get_tid();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"pid"} != $$ or $self->{"tid"} != 0 68 4532 4600
Condition66%2/3
$self->{"pid"} != $$ or $self->{"tid"} != 0
l!l&&r!l&&!r
6804532
MC/DC50%1/2
$self->{"pid"} != $$ or $self->{"tid"} != 0
$self->{"pid"} != $$ $self->{"tid"} != 0
Truth table66%2/3
A or B
A= $self->{"pid"} != $$B= $self->{"tid"} != 0
ABresult
1X1
011
000
413  
414 # No need to do IPC checks on culled events
415 4532 $self->process($_) for $ipc->cull($self->{+HID});
416 }
417  
418 1287 ▶sub finalize {
Subroutine finalize: called CC=16 SCAR=27.7
Pod undocumented
419 1287 my $self = shift;
420 1287 my ($trace, $do_plan) = @_;
421  
422 1287 $self->cull();
423  
424 1287 my $plan = $self->{+_PLAN};
425 1287 my $count = $self->{+COUNT};
426 1287 my $failed = $self->{+FAILED};
427 1287 my $active = $self->{+ACTIVE};
428  
429 # return if NOTHING was done.
430 1287 ▶ unless ($active || $do_plan || defined($plan) || $count || $failed) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($active or $do_plan or defined $plan or $count or $failed) 34 1253 1287
Condition100%12/12
$active or $do_plan or defined $plan or $count or $failed
l!l&&r!l&&!r
1249434
$active or $do_plan or defined $plan or $count
l!l&&r!l&&!r
1243638
$active or $do_plan or defined $plan
l!l&&r!l&&!r
113410944
$active or $do_plan
l!l&&r!l&&!r
341100153
MC/DC100%5/5
$active or $do_plan or defined $plan or $count or $failed
$active $do_plan defined $plan $count $failed
Truth table100%6/6
A or B or C or D or E
A= $activeB= $do_planC= defined $planD= $countE= $failed
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
431 34 ▶ $self->{+_FORMATTER}->finalize($plan, $count, $failed, 0, $self->is_subtest) if $self->{+_FORMATTER};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_formatter"} 15 19 34
432 34 return;
433 }
434  
435 1253 ▶ unless ($self->{+ENDED}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ended"}) 1250 3 1253
436 1250 ▶ if ($self->{+_FOLLOW_UPS}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_follow_ups"}) 36 1214 1250
437 36 $_->($trace, $self) for reverse @{$self->{+_FOLLOW_UPS}};
438 }
439  
440 # These need to be refreshed now
441 1228 $plan = $self->{+_PLAN};
442 1228 $count = $self->{+COUNT};
443 1228 $failed = $self->{+FAILED};
444  
445 1228 ▶ if ((defined($plan) && $plan eq 'NO PLAN') || ($do_plan && !defined($plan))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plan and $plan eq "NO PLAN" or $do_plan and not defined $plan) 923 305 1228
Condition100%9/9
defined $plan and $plan eq "NO PLAN" or $do_plan and not defined $plan
l!l&&r!l&&!r
8915305
defined $plan and $plan eq "NO PLAN"
!ll&&!rl&&r
9232978
$do_plan and not defined $plan
!ll&&!rl&&r
112193915
MC/DC75%3/4
defined $plan and $plan eq "NO PLAN" or $do_plan and not defined $plan
defined $plan $plan eq "NO PLAN" $do_plan not defined $plan
Truth table71%5/7
A and B or C and not(D)
A= defined $planB= $plan eq "NO PLAN"C= $do_planD= not defined $plan
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
446 923 $self->send(
447 Test2::Event::Plan->new(
448 trace => $trace,
449 max => $count,
450 )
451 );
452 }
453 1228 $plan = $self->{+_PLAN};
454 }
455  
456 1231 my $frame = $trace->frame;
457 1231 ▶ if($self->{+ENDED}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ended"}) 3 1228 1231
458 3 my (undef, $ffile, $fline) = @{$self->{+ENDED}};
459 3 my (undef, $sfile, $sline) = @$frame;
460  
461 3 $self->{+SUPPRESS_RELEASE_ERROR} = 1;
462  
463 3 die <<" EOT"
464 Test already ended! (Did you call done_testing twice?)
465 First End: $ffile line $fline
466 Second End: $sfile line $sline
467 EOT
468 }
469  
470 1228 $self->{+ENDED} = $frame;
471 1228 my $pass = $self->is_passing(); # Generate the final boolean.
472  
473 1228 ▶ $self->{+_FORMATTER}->finalize($plan, $count, $failed, $pass, $self->is_subtest) if $self->{+_FORMATTER};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_formatter"} 490 738 1228
474  
475 1228 return $pass;
476 }
477  
478 4464 ▶sub is_passing {
Subroutine is_passing: called CC=15 SCAR=27.1
Pod documented
479 4464 my $self = shift;
480  
481 4464 ▶ ($self->{+_PASSING}) = @_ if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 268 4196 4464
482  
483 # If we already failed just return 0.
484 4464 ▶ my $pass = $self->{+_PASSING} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
my $pass = $self->{"_passing"} or return 0 3982 482 4464
485 3982 ▶ return $self->{+_PASSING} = 0 if $self->{+FAILED};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"failed"} 8 3974 3982
486  
487 3974 my $count = $self->{+COUNT};
488 3974 my $ended = $self->{+ENDED};
489 3974 my $plan = $self->{+_PLAN};
490  
491 3974 ▶ return $pass if !$count && $plan && $plan =~ m/^SKIP$/;
Branch: 1 branch
BranchTrueFalseTotal
if not $count and $plan and $plan =~ /^SKIP$/ 343 3631 3974
Condition100%6/6
not $count and $plan and $plan =~ /^SKIP$/
!ll&&!rl&&r
3153478343
not $count and $plan
!ll&&!rl&&r
2695458821
MC/DC100%3/3
not $count and $plan and $plan =~ /^SKIP$/
not $count $plan $plan =~ /^SKIP$/
Truth table100%4/4
not(A) and B and C
A= not $countB= $planC= $plan =~ /^SKIP$/
ABCresult
0XX0
10X0
1100
1111
492  
493 3631 ▶ return $self->{+_PASSING} = 0
Branch: 1 branch
BranchTrueFalseTotal
if $ended and not $count && $plan 36 3595 3631
Condition100%6/6
$ended and not $count && $plan
!ll&&!rl&&r
1389220636
$count && $plan
!ll&&!rl&&r
3332206
MC/DC100%3/3
$ended and not $count && $plan
$ended $count $plan
Truth table100%4/4
A and not(B && C)
A= $endedB= $countC= $plan
ABCresult
0XX0
1110
10X1
1101
494 if $ended && (!$count || !$plan);
495  
496 3595 ▶ return $pass unless $plan && $plan =~ m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $plan and $plan =~ /^\d+$/ 711 2884 3595
Condition100%3/3
$plan and $plan =~ /^\d+$/
!ll&&!rl&&r
669422884
MC/DC100%2/2
$plan and $plan =~ /^\d+$/
$plan $plan =~ /^\d+$/
Truth table100%3/3
A and B
A= $planB= $plan =~ /^\d+$/
ABresult
0X0
100
111
497  
498 2884 ▶ if ($ended) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ended) { } 2206 678 2884
499 2206 ▶ return $self->{+_PASSING} = 0 if $count != $plan;
Branch: 1 branch
BranchTrueFalseTotal
if $count != $plan 6 2200 2206
500 }
501 else {
502 678 ▶ return $self->{+_PASSING} = 0 if $count > $plan;
Branch: 1 branch
BranchTrueFalseTotal
if $count > $plan 1 677 678
503 }
504  
505 2877 return $pass;
506 }
507  
508 2951 ▶sub plan {
Subroutine plan: called CC=6 SCAR=17.9
Pod documented
509 2951 my $self = shift;
510  
511 2951 ▶ return $self->{+_PLAN} unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1589 1362 2951
512  
513 1362 my ($plan) = @_;
514  
515 1362 ▶ confess "You cannot unset the plan"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $plan 0 1362 1362
516 unless defined $plan;
517  
518 confess "You cannot change the plan"
519 1362 ▶ if $self->{+_PLAN} && $self->{+_PLAN} !~ m/^NO PLAN$/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_plan"} and not $self->{"_plan"} =~ /^NO PLAN$/ 1 1361 1362
Condition100%3/3
$self->{"_plan"} and not $self->{"_plan"} =~ /^NO PLAN$/
!ll&&!rl&&r
1348131
MC/DC100%2/2
$self->{"_plan"} and not $self->{"_plan"} =~ /^NO PLAN$/
$self->{"_plan"} not $self->{"_plan"} =~ /^NO PLAN$/
Truth table100%3/3
A and not(B)
A= $self->{"_plan"}B= not $self->{"_plan"} =~ /^NO PLAN$/
ABresult
0X0
100
111
520  
521 1361 ▶ confess "'$plan' is not a valid plan! Plan must be an integer greater than 0, 'NO PLAN', or 'SKIP'"
Branch: 1 branch
BranchTrueFalseTotal
unless $plan =~ /^(\d+|NO PLAN|SKIP)$/ 1 1360 1361
522 unless $plan =~ m/^(\d+|NO PLAN|SKIP)$/;
523  
524 1360 $self->{+_PLAN} = $plan;
525 }
526  
527 352 ▶sub check_plan {
Subroutine check_plan: called CC=5 SCAR=16.1
Pod documented
528 352 my $self = shift;
529  
530 352 ▶ return undef unless $self->{+ENDED};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ended"} 0 352 352
531 352 ▶ my $plan = $self->{+_PLAN} || return undef;
Condition100%2/2
$self->{'_plan'} || (return undef)
l!l
34210
MC/DC100%1/1
$self->{'_plan'} || (return undef)
$self->{'_plan'}
Truth table100%2/2
A
A= $self->{'_plan'}
Aresult
11
00
532  
533 342 ▶ return 1 if $plan !~ m/^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $plan =~ /^\d+$/ 3 339 342
534  
535 339 ▶ return 1 if $plan == $self->{+COUNT};
Branch: 1 branch
BranchTrueFalseTotal
if $plan == $self->{"count"} 337 2 339
536 2 return 0;
537 }
538  
539 1473 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=13.9
540 1473 my $self = shift;
541 1473 ▶ my $ipc = $self->{+IPC} || return;
Condition100%2/2
$self->{'ipc'} || (return)
l!l
2121261
MC/DC100%1/1
$self->{'ipc'} || (return)
$self->{'ipc'}
Truth table100%2/2
A
A= $self->{'ipc'}
Aresult
11
00
542 212 ▶ return unless $$ == $self->{+PID};
Branch: 1 branch
BranchTrueFalseTotal
unless $$ == $self->{"pid"} 45 167 212
543 167 ▶ return unless get_tid() == $self->{+TID};
Branch: 1 branch
BranchTrueFalseTotal
unless 0 == $self->{"tid"} 0 167 167
544 167 $ipc->drop_hub($self->{+HID});
545 }
546  
547 455 1;
548  
549 __END__
« blib/lib/Test2/Util/Stash.pm ↑ Summary blib/lib/Test2/V0.pm »