| 1 | package Test2::Event::Generic; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Scalar::Util qw/reftype/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '1.302226'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | BEGIN { require Test2::Event; our @ISA = qw(Test2::Event) } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Test2::Util::HashBase; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | my @FIELDS = qw{ | |||||||||||||||||||||||||||
| 14 | causes_fail increments_count diagnostics no_display callback terminate | ||||||||||||||||||||||||||||
| 15 | global sets_plan summary facet_data | ||||||||||||||||||||||||||||
| 16 | }; | ||||||||||||||||||||||||||||
| 17 | 3 | my %DEFAULTS = ( | |||||||||||||||||||||||||||
| 18 | causes_fail => 0, | ||||||||||||||||||||||||||||
| 19 | increments_count => 0, | ||||||||||||||||||||||||||||
| 20 | diagnostics => 0, | ||||||||||||||||||||||||||||
| 21 | no_display => 0, | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 9 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 9 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 9 | for my $field (@FIELDS) { | |||||||||||||||||||||||||||
| 28 | 90 | ▶ | my $val = defined $self->{$field} ? delete $self->{$field} : $DEFAULTS{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 90 | ▶ | next unless defined $val; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 40 | my $set = "set_$field"; | |||||||||||||||||||||||||||
| 32 | 40 | $self->$set($val); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 3 | for my $field (@FIELDS) { | |||||||||||||||||||||||||||
| 37 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 149 | ▶ | *$field = sub { exists $_[0]->{$field} ? $_[0]->{$field} : () } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 30 | ▶ | unless exists &{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 51 | ▶ | *{"set_$field"} = sub { $_[0]->{$field} = $_[1] } | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 30 | ▶ | unless exists &{"set_$field"}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 27 | ▶ | sub can { | ||||||||||||||||||||||||||
|
Subroutine
can: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 27 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 27 | my ($name) = @_; | |||||||||||||||||||||||||||
| 49 | 27 | ▶ | return $self->SUPER::can($name) unless $name eq 'callback'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 19 | ▶ | return $self->{callback} || \&Test2::Event::callback; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'callback'} || \&Test2::Event::callback
MC/DC100%1/1
$self->{'callback'} || \&Test2::Event::callback
$self->{'callback'}
Truth table100%2/2
A
A= $self->{'callback'}
| |||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 41 | ▶ | sub facet_data { | ||||||||||||||||||||||||||
|
Subroutine
facet_data: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 41 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 41 | ▶ | return $self->{facet_data} || $self->SUPER::facet_data(); | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{'facet_data'} || $self->SUPER::facet_data
MC/DC0%0/2
$self->{'facet_data'} || $self->SUPER::facet_data
$self->{'facet_data'}
$self->SUPER::facet_data
Truth table66%2/3
A || B
A= $self->{'facet_data'}B= $self->SUPER::facet_data
| |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 34 | ▶ | sub summary { | ||||||||||||||||||||||||||
|
Subroutine
summary: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 59 | 34 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 34 | ▶ | return $self->{summary} if defined $self->{summary}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 32 | $self->SUPER::summary(); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 23 | ▶ | sub sets_plan { | ||||||||||||||||||||||||||
|
Subroutine
sets_plan: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 23 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 23 | ▶ | return unless $self->{sets_plan}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 5 | return @{$self->{sets_plan}}; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 4 | ▶ | sub callback { | ||||||||||||||||||||||||||
|
Subroutine
callback: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 71 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 4 | ▶ | my $cb = $self->{callback} || return; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'callback'} || (return)
MC/DC100%1/1
$self->{'callback'} || (return)
$self->{'callback'}
Truth table100%2/2
A
A= $self->{'callback'}
| |||||||||||||||||||||||||||||
| 73 | 1 | $self->$cb(@_); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 5 | ▶ | sub set_global { | ||||||||||||||||||||||||||
|
Subroutine
set_global: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 5 | my ($bool) = @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 5 | ▶ | if(!defined $bool) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 1 | delete $self->{global}; | |||||||||||||||||||||||||||
| 82 | 1 | return undef; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 4 | $self->{global} = $bool; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | sub set_callback { | ||||||||||||||||||||||||||
|
Subroutine
set_callback: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | 4 | my ($cb) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 4 | ▶ | if(!defined $cb) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 1 | delete $self->{callback}; | |||||||||||||||||||||||||||
| 94 | 1 | return undef; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 3 | ▶ | croak "callback must be a code reference" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $cb and builtin::reftype($cb) eq "CODE"
MC/DC50%1/2
ref $cb and builtin::reftype($cb) eq "CODE"
ref $cb
builtin::reftype($cb) eq "CODE"
Truth table66%2/3
A and B
A= ref $cbB= builtin::reftype($cb) eq "CODE"
| |||||||||||||||||||||||||||||
| 98 | unless ref($cb) && reftype($cb) eq 'CODE'; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | $self->{callback} = $cb; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 10 | ▶ | sub set_terminate { | ||||||||||||||||||||||||||
|
Subroutine
set_terminate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 10 | my ($exit) = @_; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 10 | ▶ | if(!defined $exit) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 2 | delete $self->{terminate}; | |||||||||||||||||||||||||||
| 109 | 2 | return undef; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 8 | ▶ | croak "terminate must be a positive integer" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | unless $exit =~ m/^\d+$/; | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 5 | $self->{terminate} = $exit; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 6 | ▶ | sub set_sets_plan { | ||||||||||||||||||||||||||
|
Subroutine
set_sets_plan: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 119 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 120 | 6 | my ($plan) = @_; | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 6 | ▶ | if(!defined $plan) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 1 | delete $self->{sets_plan}; | |||||||||||||||||||||||||||
| 124 | 1 | return undef; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 5 | ▶ | croak "'sets_plan' must be an array reference" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $plan and builtin::reftype($plan) eq "ARRAY"
MC/DC50%1/2
ref $plan and builtin::reftype($plan) eq "ARRAY"
ref $plan
builtin::reftype($plan) eq "ARRAY"
Truth table66%2/3
A and B
A= ref $planB= builtin::reftype($plan) eq "ARRAY"
| |||||||||||||||||||||||||||||
| 128 | unless ref($plan) && reftype($plan) eq 'ARRAY'; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 4 | $self->{sets_plan} = $plan; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 3 | 1; | |||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | __END__ | ||||||||||||||||||||||||||||