| 1 | package Test2::API::Context; | ||||||||||||||||||||||||||||||||||||||||||
| 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/confess croak/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 455 | ▶ | use Scalar::Util qw/weaken blessed/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 455 | ▶ | use Test2::Util qw/get_tid try pkg_to_file get_tid/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 455 | ▶ | use Test2::EventFacet::Trace(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 455 | ▶ | use Test2::API(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # Preload some key event types | ||||||||||||||||||||||||||||||||||||||||||
| 16 | my %LOADED = ( | ||||||||||||||||||||||||||||||||||||||||||
| 17 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 455 | my $pkg = "Test2::Event::$_"; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 5460 | my $file = "Test2/Event/$_.pm"; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 5460 | ▶ | require $file unless $INC{$file}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 5460 | ( $pkg => $pkg, $_ => $pkg ) | |||||||||||||||||||||||||||||||||||||||||
| 22 | } qw/Ok Diag Note Plan Bail Exception Waiting Skip Subtest Pass Fail V2/ | ||||||||||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 455 | ▶ | use Test2::Util::ExternalMeta qw/meta get_meta set_meta delete_meta/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 455 | ▶ | use Test2::Util::HashBase qw{ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | stack hub trace _on_release _depth _is_canon _is_spawn _aborted | ||||||||||||||||||||||||||||||||||||||||||
| 28 | errno eval_error child_error thrown _failed _start_fail_count | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 455 | }; | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | # Private, not package vars | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # It is safe to cache these. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 455 | my $ON_RELEASE = Test2::API::_context_release_callbacks_ref(); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 455 | my $CONTEXTS = Test2::API::_contexts_ref(); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1176 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=8 SCAR=21.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1176 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | confess "The 'trace' attribute is required" | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 1176 | ▶ | unless $self->{+TRACE}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | confess "The 'hub' attribute is required" | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 1175 | ▶ | unless $self->{+HUB}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1174 | ▶ | $self->{+_START_FAIL_COUNT} = $self->{+HUB}->{failed} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'hub'}{'failed'} || 0
MC/DC100%1/1
$self->{'hub'}{'failed'} || 0
$self->{'hub'}{'failed'}
Truth table100%2/2
A
A= $self->{'hub'}{'failed'}
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1174 | ▶ | $self->{+_DEPTH} = 0 unless defined $self->{+_DEPTH}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1174 | ▶ | $self->{+ERRNO} = $! unless exists $self->{+ERRNO}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1174 | ▶ | $self->{+EVAL_ERROR} = $@ unless exists $self->{+EVAL_ERROR}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1174 | ▶ | $self->{+CHILD_ERROR} = $? unless exists $self->{+CHILD_ERROR}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 597 | ▶ | sub snapshot { bless {%{$_[0]}, _is_canon => undef, _is_spawn => undef, _aborted => undef}, __PACKAGE__ } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
snapshot: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub restore_error_vars { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
restore_error_vars: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 20700 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=20 SCAR=32.2
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 20700 | ▶ | return unless $_[0]->{+_IS_CANON} || $_[0]->{+_IS_SPAWN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_[0]{"_is_canon"} or $_[0]{"_is_spawn"}
MC/DC100%2/2
$_[0]{"_is_canon"} or $_[0]{"_is_spawn"}
$_[0]{"_is_canon"}
$_[0]{"_is_spawn"}
Truth table100%3/3
A or B
A= $_[0]{"_is_canon"}B= $_[0]{"_is_spawn"}
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 227 | ▶ | return if $_[0]->{+_ABORTED} && ${$_[0]->{+_ABORTED}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$_[0]{"_aborted"} and ${$_[0]{"_aborted"};}
MC/DC50%1/2
$_[0]{"_aborted"} and ${$_[0]{"_aborted"};}
$_[0]{"_aborted"}
${$_[0]{"_aborted"};}
Truth table66%2/3
A and B
A= $_[0]{"_aborted"}B= ${$_[0]{"_aborted"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 104 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 104 | my $hub = $self->{+HUB}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 104 | my $hid = $hub->{hid}; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 104 | ▶ | $self->{+_FAILED} = ($hub->{failed} || 0) - $self->{+_START_FAIL_COUNT}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$hub->{'failed'} || 0
MC/DC0%0/1
$hub->{'failed'} || 0
$hub->{'failed'}
Truth table50%1/2
A
A= $hub->{'failed'}
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # Do not show the warning if it looks like an exception has been thrown, or | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # if the context is not local to this process or thread. | ||||||||||||||||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # Sometimes $@ is uninitialized, not a problem in this case so do not | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # show the warning about using eq. | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 455 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 104 | ▶ | if($self->{+EVAL_ERROR} eq $@ && $hub->is_local && !$hub->suppress_release_error) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->{"eval_error"} eq $@ and $hub->is_local and not $hub->suppress_release_error
$self->{"eval_error"} eq $@ and $hub->is_local
MC/DC66%2/3
$self->{"eval_error"} eq $@ and $hub->is_local and not $hub->suppress_release_error
$self->{"eval_error"} eq $@
$hub->is_local
not $hub->suppress_release_error
Truth table75%3/4
A and B and not(C)
A= $self->{"eval_error"} eq $@B= $hub->is_localC= not $hub->suppress_release_error
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 5 | require Carp; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | my $mess = Carp::longmess("Context destroyed"); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | my $frame = $self->{+_IS_SPAWN} || $self->{+TRACE}->frame; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'_is_spawn'} || $self->{'trace'}->frame
MC/DC0%0/2
$self->{'_is_spawn'} || $self->{'trace'}->frame
$self->{'_is_spawn'}
$self->{'trace'}->frame
Truth table66%2/3
A || B
A= $self->{'_is_spawn'}B= $self->{'trace'}->frame
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | warn <<" EOT"; | |||||||||||||||||||||||||||||||||||||||||
| 82 | A context appears to have been destroyed without first calling release(). | ||||||||||||||||||||||||||||||||||||||||||
| 83 | Based on \$@ it does not look like an exception was thrown (this is not always | ||||||||||||||||||||||||||||||||||||||||||
| 84 | a reliable test) | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | This is a problem because the global error variables (\$!, \$@, and \$?) will | ||||||||||||||||||||||||||||||||||||||||||
| 87 | not be restored. In addition some release callbacks will not work properly from | ||||||||||||||||||||||||||||||||||||||||||
| 88 | inside a DESTROY method. | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | Here are the context creation details, just in case a tool forgot to call | ||||||||||||||||||||||||||||||||||||||||||
| 91 | release(): | ||||||||||||||||||||||||||||||||||||||||||
| 92 | File: $frame->[1] | ||||||||||||||||||||||||||||||||||||||||||
| 93 | Line: $frame->[2] | ||||||||||||||||||||||||||||||||||||||||||
| 94 | Tool: $frame->[3] | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | Here is a trace to the code that caused the context to be destroyed, this could | ||||||||||||||||||||||||||||||||||||||||||
| 97 | be an exit(), a goto, or simply the end of a scope: | ||||||||||||||||||||||||||||||||||||||||||
| 98 | $mess | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | Cleaning up the CONTEXT stack... | ||||||||||||||||||||||||||||||||||||||||||
| 101 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 104 | ▶ | return if $self->{+_IS_SPAWN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # Remove the key itself to avoid a slow memory leak | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 77 | delete $CONTEXTS->{$hid}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 77 | $self->{+_IS_CANON} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 77 | ▶ | if (my $cbk = $self->{+_ON_RELEASE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $_->($self) for reverse @$cbk; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 77 | ▶ | if (my $hcbk = $hub->{_context_release}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | $_->($self) for reverse @$hcbk; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 77 | $_->($self) for reverse @$ON_RELEASE; | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 77 | ▶ | if (my @diags = Test2::API::test2_clear_pending_diags()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if ($self->{+_FAILED} || ${$self->{+_ABORTED}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"_failed"} or ${$self->{"_aborted"};}
MC/DC0%0/2
$self->{"_failed"} or ${$self->{"_aborted"};}
$self->{"_failed"}
${$self->{"_aborted"};}
Truth table0%0/3
A or B
A= $self->{"_failed"}B= ${$self->{"_aborted"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->diag($_) for @diags; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # release exists to implement behaviors like die-on-fail. In die-on-fail you | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # want to die after a failure, but only after diagnostics have been reported. | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # The ideal time for the die to happen is when the context is released. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # Unfortunately die does not work in a DESTROY block. | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 18735 | ▶ | sub release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
release: called CC=18 SCAR=29.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 18735 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 18735 | ▶ | ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} and return if $self->{+THROWN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$self->{'thrown'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return))
($!, $@, $?) = @$self{"errno", "eval_error", "child_error"} and return
MC/DC0%0/2
$self->{'thrown'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return))
$self->{'thrown'}
($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
Truth table33%1/3
A && B
A= $self->{'thrown'}B= ($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} and return $self->{+_IS_SPAWN} = undef | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 18708 | ▶ | if $self->{+_IS_SPAWN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
$self->{'_is_spawn'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return $self->{'_is_spawn'} = undef))
($!, $@, $?) = @$self{"errno", "eval_error", "child_error"} and return $self->{"_is_spawn"} = undef
MC/DC0%0/2
$self->{'_is_spawn'} && ((($!, $@, $?) = @$self{'errno', 'eval_error', 'child_error'}) && (return $self->{'_is_spawn'} = undef))
$self->{'_is_spawn'}
($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
Truth table33%1/3
A && B
A= $self->{'_is_spawn'}B= ($!, $@, $?) = @$self{"errno", "eval_error", "child_error"}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | croak "release() should not be called on context that is neither canon nor a child" | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 12945 | ▶ | unless $self->{+_IS_CANON}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 12944 | my $hub = $self->{+HUB}; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 12944 | my $hid = $hub->{hid}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 12944 | ▶ | $self->{+_FAILED} = ($hub->{failed} || 0) - $self->{+_START_FAIL_COUNT}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$hub->{'failed'} || 0
MC/DC100%1/1
$hub->{'failed'} || 0
$hub->{'failed'}
Truth table100%2/2
A
A= $hub->{'failed'}
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | croak "context thinks it is canon, but it is not" | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 12944 | ▶ | unless $CONTEXTS->{$hid} && $CONTEXTS->{$hid} == $self; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$CONTEXTS->{$hid} and $CONTEXTS->{$hid} == $self
MC/DC0%0/2
$CONTEXTS->{$hid} and $CONTEXTS->{$hid} == $self
$CONTEXTS->{$hid}
$CONTEXTS->{$hid} == $self
Truth table33%1/3
A and B
A= $CONTEXTS->{$hid}B= $CONTEXTS->{$hid} == $self
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | # Remove the key itself to avoid a slow memory leak | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 12944 | $self->{+_IS_CANON} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 12944 | delete $CONTEXTS->{$hid}; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 12944 | ▶ | if (my $cbk = $self->{+_ON_RELEASE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 2 | $_->($self) for reverse @$cbk; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 12944 | ▶ | if (my $hcbk = $hub->{_context_release}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 47 | $_->($self) for reverse @$hcbk; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 12944 | $_->($self) for reverse @$ON_RELEASE; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 12940 | ▶ | if (my @diags = Test2::API::test2_clear_pending_diags()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | if ($self->{+_FAILED} || ${$self->{+_ABORTED}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"_failed"} or ${$self->{"_aborted"};}
MC/DC50%1/2
$self->{"_failed"} or ${$self->{"_aborted"};}
$self->{"_failed"}
${$self->{"_aborted"};}
Truth table66%2/3
A or B
A= $self->{"_failed"}B= ${$self->{"_aborted"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | $self->diag($_) for @diags; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | # Do this last so that nothing else changes them. | ||||||||||||||||||||||||||||||||||||||||||
| 168 | # If one of the hooks dies then these do not get restored, this is | ||||||||||||||||||||||||||||||||||||||||||
| 169 | # intentional | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 12940 | ($!, $@, $?) = @$self{+ERRNO, +EVAL_ERROR, +CHILD_ERROR}; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 12940 | return; | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 7 | ▶ | sub do_in_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
do_in_context: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 7 | my ($sub, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | # We need to update the pid/tid and error vars. | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | my $clone = $self->snapshot; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | @$clone{+ERRNO, +EVAL_ERROR, +CHILD_ERROR} = ($!, $@, $?); | |||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | $clone->{+TRACE} = $clone->{+TRACE}->snapshot(pid => $$, tid => get_tid()); | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 7 | my $hub = $clone->{+HUB}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 7 | my $hid = $hub->hid; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 7 | my $old = $CONTEXTS->{$hid}; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | $clone->{+_IS_CANON} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 7 | $CONTEXTS->{$hid} = $clone; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 7 | weaken($CONTEXTS->{$hid}); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | my ($ok, $err) = &try($sub, @args); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 7 | ▶ | my ($rok, $rerr) = try { $clone->release }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 7 | delete $clone->{+_IS_CANON}; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | ▶ | if ($old) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | $CONTEXTS->{$hid} = $old; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | weaken($CONTEXTS->{$hid}); | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 6 | delete $CONTEXTS->{$hid}; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 7 | ▶ | die $err unless $ok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | ▶ | die $rerr unless $rok; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | 89 | ▶ | sub done_testing { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
done_testing: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | 89 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 210 | 89 | $self->hub->finalize($self->trace, 1); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 89 | return; | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 25 | ▶ | sub throw { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
throw: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 25 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 25 | $self->{+THROWN} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 25 | ▶ | ${$self->{+_ABORTED}}++ if $self->{+_ABORTED}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 25 | ▶ | $self->release if $self->{+_IS_CANON} || $self->{+_IS_SPAWN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"_is_canon"} or $self->{"_is_spawn"}
MC/DC100%2/2
$self->{"_is_canon"} or $self->{"_is_spawn"}
$self->{"_is_canon"}
$self->{"_is_spawn"}
Truth table100%3/3
A or B
A= $self->{"_is_canon"}B= $self->{"_is_spawn"}
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 25 | $self->trace->throw($msg); | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | ▶ | sub alert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | my ($self, $msg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | $self->trace->alert($msg); | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | sub send_ev2_and_release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_ev2_and_release: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my $out = $self->send_ev2(@_); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $self->release; | |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 361 | ▶ | sub send_ev2 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_ev2: called CC=5 SCAR=17.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 361 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 361 | my $e; | |||||||||||||||||||||||||||||||||||||||||
| 238 | { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 361 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||||||||||||||||
| 240 | $e = Test2::Event::V2->new( | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 361 | trace => $self->{+TRACE}->snapshot, | |||||||||||||||||||||||||||||||||||||||||
| 242 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 243 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 361 | ▶ | if ($self->{+_ABORTED}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | my $f = $e->facet_data; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | ▶ | ${$self->{+_ABORTED}}++ if $f->{control}->{halt} || defined($f->{control}->{terminate}) || defined($e->terminate); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"}
MC/DC0%0/3
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
$f->{"control"}{"halt"}
defined $f->{"control"}{"terminate"}
defined $e->terminate
Truth table25%1/4
A or B or C
A= $f->{"control"}{"halt"}B= defined $f->{"control"}{"terminate"}C= defined $e->terminate
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 361 | $self->{+HUB}->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | ▶ | sub build_ev2 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_ev2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||||||||||||||||
| 257 | Test2::Event::V2->new( | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | trace => $self->{+TRACE}->snapshot, | |||||||||||||||||||||||||||||||||||||||||
| 259 | @_, | ||||||||||||||||||||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | sub send_event_and_release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_event_and_release: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $out = $self->send_event(@_); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $self->release; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 2222 | ▶ | sub send_event { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_event: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 2222 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 2222 | my $event = shift; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 2222 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 2222 | ▶ | my $pkg = $LOADED{$event} || $self->_parse_event($event); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$LOADED{$event} || $self->_parse_event($event)
MC/DC0%0/2
$LOADED{$event} || $self->_parse_event($event)
$LOADED{$event}
$self->_parse_event($event)
Truth table66%2/3
A || B
A= $LOADED{$event}B= $self->_parse_event($event)
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 2222 | my $e; | |||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 2222 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||||||||||||||||
| 280 | $e = $pkg->new( | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 2222 | trace => $self->{+TRACE}->snapshot, | |||||||||||||||||||||||||||||||||||||||||
| 282 | %args, | ||||||||||||||||||||||||||||||||||||||||||
| 283 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | 2222 | ▶ | if ($self->{+_ABORTED}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | 2092 | my $f = $e->facet_data; | |||||||||||||||||||||||||||||||||||||||||
| 288 | 2092 | ▶ | ${$self->{+_ABORTED}}++ if $f->{control}->{halt} || defined($f->{control}->{terminate}) || defined($e->terminate); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"}
MC/DC66%2/3
$f->{"control"}{"halt"} or defined $f->{"control"}{"terminate"} or defined $e->terminate
$f->{"control"}{"halt"}
defined $f->{"control"}{"terminate"}
defined $e->terminate
Truth table75%3/4
A or B or C
A= $f->{"control"}{"halt"}B= defined $f->{"control"}{"terminate"}C= defined $e->terminate
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 2222 | $self->{+HUB}->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | 732 | ▶ | sub build_event { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_event: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 732 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 732 | my $event = shift; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 732 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 732 | ▶ | my $pkg = $LOADED{$event} || $self->_parse_event($event); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$LOADED{$event} || $self->_parse_event($event)
MC/DC0%0/2
$LOADED{$event} || $self->_parse_event($event)
$LOADED{$event}
$self->_parse_event($event)
Truth table33%1/3
A || B
A= $LOADED{$event}B= $self->_parse_event($event)
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 732 | local $Carp::CarpLevel = $Carp::CarpLevel + 1; | |||||||||||||||||||||||||||||||||||||||||
| 301 | $pkg->new( | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 732 | trace => $self->{+TRACE}->snapshot, | |||||||||||||||||||||||||||||||||||||||||
| 303 | %args, | ||||||||||||||||||||||||||||||||||||||||||
| 304 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | ▶ | sub pass { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pass: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | my $e = bless( | ||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 2 | trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'), | |||||||||||||||||||||||||||||||||||||||||
| 314 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 315 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 316 | "Test2::Event::Pass" | ||||||||||||||||||||||||||||||||||||||||||
| 317 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | $self->{+HUB}->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | return $e; | |||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 1948 | ▶ | sub pass_and_release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pass_and_release: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 324 | 1948 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 1948 | my ($name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | my $e = bless( | ||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 1948 | trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'), | |||||||||||||||||||||||||||||||||||||||||
| 330 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 331 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 332 | "Test2::Event::Pass" | ||||||||||||||||||||||||||||||||||||||||||
| 333 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | 1948 | $self->{+HUB}->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 1948 | $self->release; | |||||||||||||||||||||||||||||||||||||||||
| 337 | 1948 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | 230 | ▶ | sub fail { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 230 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 230 | my ($name, @diag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | my $e = bless( | ||||||||||||||||||||||||||||||||||||||||||
| 345 | { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 230 | trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'), | |||||||||||||||||||||||||||||||||||||||||
| 347 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 348 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 349 | "Test2::Event::Fail" | ||||||||||||||||||||||||||||||||||||||||||
| 350 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 230 | for my $msg (@diag) { | |||||||||||||||||||||||||||||||||||||||||
| 353 | 234 | ▶ | if (ref($msg) eq 'Test2::EventFacet::Info::Table') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 229 | $e->add_info({tag => 'DIAG', debug => 1, $msg->info_args}); | |||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||
| 356 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 5 | $e->add_info({tag => 'DIAG', debug => 1, details => $msg}); | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | 230 | $self->{+HUB}->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 362 | 230 | return $e; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 27 | ▶ | sub fail_and_release { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail_and_release: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 27 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 27 | my ($name, @diag) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | my $e = bless( | ||||||||||||||||||||||||||||||||||||||||||
| 370 | { | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 27 | trace => bless({%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'), | |||||||||||||||||||||||||||||||||||||||||
| 372 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 373 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 374 | "Test2::Event::Fail" | ||||||||||||||||||||||||||||||||||||||||||
| 375 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 27 | for my $msg (@diag) { | |||||||||||||||||||||||||||||||||||||||||
| 378 | 21 | ▶ | if (ref($msg) eq 'Test2::EventFacet::Info::Table') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | $e->add_info({tag => 'DIAG', debug => 1, $msg->info_args}); | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 20 | $e->add_info({tag => 'DIAG', debug => 1, details => $msg}); | |||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | 27 | $self->{+HUB}->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 387 | 27 | $self->release; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 27 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 2570 | ▶ | sub ok { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ok: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 2570 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 2570 | my ($pass, $name, $on_fail) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 2570 | my $hub = $self->{+HUB}; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | my $e = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 2570 | trace => bless( {%{$self->{+TRACE}}}, 'Test2::EventFacet::Trace'), | |||||||||||||||||||||||||||||||||||||||||
| 399 | pass => $pass, | ||||||||||||||||||||||||||||||||||||||||||
| 400 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 401 | }, 'Test2::Event::Ok'; | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 2570 | $e->init; | |||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 2570 | $hub->send($e); | |||||||||||||||||||||||||||||||||||||||||
| 405 | 2570 | ▶ | return $e if $pass; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 88 | $self->failure_diag($e); | |||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 88 | ▶ | if ($on_fail && @$on_fail) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$on_fail and @$on_fail
MC/DC100%2/2
$on_fail and @$on_fail
$on_fail
@$on_fail
Truth table100%3/3
A and B
A= $on_failB= @$on_fail
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 48 | $self->diag($_) for @$on_fail; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 88 | return $e; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 109 | ▶ | sub failure_diag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
failure_diag: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 109 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 109 | my ($e) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | # Figure out the debug info, this is typically the file name and line | ||||||||||||||||||||||||||||||||||||||||||
| 421 | # number, but can also be a custom message. If no trace object is provided | ||||||||||||||||||||||||||||||||||||||||||
| 422 | # then we have nothing useful to display. | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 109 | my $name = $e->name; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 109 | my $trace = $e->trace; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 109 | ▶ | my $debug = $trace ? $trace->debug : "[No trace info available]"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | # Create the initial diagnostics. If the test has a name we put the debug | ||||||||||||||||||||||||||||||||||||||||||
| 428 | # info on a second line, this behavior is inherited from Test::Builder. | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 109 | ▶ | my $msg = defined($name) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | ? qq[Failed test '$name'\n$debug.\n] | ||||||||||||||||||||||||||||||||||||||||||
| 431 | : qq[Failed test $debug.\n]; | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 109 | $self->diag($msg); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 43 | ▶ | sub skip { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
skip: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 43 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 43 | my ($name, $reason, @extra) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 43 | $self->send_event( | |||||||||||||||||||||||||||||||||||||||||
| 440 | 'Skip', | ||||||||||||||||||||||||||||||||||||||||||
| 441 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||
| 442 | reason => $reason, | ||||||||||||||||||||||||||||||||||||||||||
| 443 | pass => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 444 | @extra, | ||||||||||||||||||||||||||||||||||||||||||
| 445 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 876 | ▶ | sub note { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
note: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 876 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 876 | my ($message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 876 | $self->send_event('Note', message => $message); | |||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 986 | ▶ | sub diag { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diag: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | 986 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 456 | 986 | my ($message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 457 | 986 | $self->send_event( | |||||||||||||||||||||||||||||||||||||||||
| 458 | 'Diag', | ||||||||||||||||||||||||||||||||||||||||||
| 459 | message => $message, | ||||||||||||||||||||||||||||||||||||||||||
| 460 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | 283 | ▶ | sub plan { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plan: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | 283 | my ($self, $max, $directive, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 465 | 283 | $self->send_event('Plan', max => $max, directive => $directive, reason => $reason); | |||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 15 | ▶ | sub bail { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bail: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | 15 | my ($self, $reason) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 470 | 15 | $self->send_event('Bail', reason => $reason); | |||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 6 | ▶ | sub _parse_event { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_event: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 475 | 6 | my $event = shift; | |||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | 6 | my $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 6 | ▶ | if ($event =~ m/^\+(.*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | 3 | $pkg = $1; | |||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||
| 481 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 3 | $pkg = "Test2::Event::$event"; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 6 | ▶ | unless ($LOADED{$pkg}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | my $file = pkg_to_file($pkg); | |||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | ▶ | my ($ok, $err) = try { require $file }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | ▶ | $self->throw("Could not load event module '$pkg': $err") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | unless $ok; | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | $LOADED{$pkg} = $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 5 | ▶ | confess "'$pkg' is not a subclass of 'Test2::Event'" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | unless $pkg->isa('Test2::Event'); | ||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | 5 | $LOADED{$event} = $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | 5 | return $pkg; | |||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | 455 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | __END__ | ||||||||||||||||||||||||||||||||||||||||||