blib/lib/Test2/Event/Generic.pm

filter: Statementstmt 100% 81 / 81 Branchbran 100% 30 / 30 Conditioncond 76.9% 10 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 19 / 19 Podpod 80.0% 8 / 10 totaltotal 94.4% 152 / 161 CC 20 SCAR 9.5
CC
20
Cov
98%
set_callback
4.0
set_sets_plan
4.0
init
4.0
CRAP 2.6
« blib/lib/Test2/Tools/Basic.pm ↑ Summary blib/lib/Test2/Compare/Ref.pm »
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
BranchTrueFalseTotal
defined $self->{$field} ? : 14 76 90
29 90 ▶ next unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 50 40 90
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
BranchTrueFalseTotal
exists $_[0]{$field} ? : 121 28 149
40 30 ▶ unless exists &{$field};
Branch: 1 branch
BranchTrueFalseTotal
unless exists &{$field;} 18 12 30
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
BranchTrueFalseTotal
unless exists &{"set_$field";} 18 12 30
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
BranchTrueFalseTotal
unless $name eq "callback" 8 19 27
50 19 ▶ return $self->{callback} || \&Test2::Event::callback;
Condition100%2/2
$self->{'callback'} || \&Test2::Event::callback
l!l
712
MC/DC100%1/1
$self->{'callback'} || \&Test2::Event::callback
$self->{'callback'}
Truth table100%2/2
A
A= $self->{'callback'}
Aresult
11
00
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
l!l&&r!l&&!r
22190
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if defined $self->{"summary"} 2 32 34
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
BranchTrueFalseTotal
unless $self->{"sets_plan"} 18 5 23
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)
l!l
13
MC/DC100%1/1
$self->{'callback'} || (return)
$self->{'callback'}
Truth table100%2/2
A
A= $self->{'callback'}
Aresult
11
00
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
BranchTrueFalseTotal
unless (defined $bool) 1 4 5
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
BranchTrueFalseTotal
unless (defined $cb) 1 3 4
93 1 delete $self->{callback};
94 1 return undef;
95 }
96  
97 3 ▶ croak "callback must be a code reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb and builtin::reftype($cb) eq "CODE" 1 2 3
Condition66%2/3
ref $cb and builtin::reftype($cb) eq "CODE"
!ll&&!rl&&r
102
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless (defined $exit) 2 8 10
108 2 delete $self->{terminate};
109 2 return undef;
110 }
111  
112 8 ▶ croak "terminate must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless $exit =~ /^\d+$/ 3 5 8
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
BranchTrueFalseTotal
unless (defined $plan) 1 5 6
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
BranchTrueFalseTotal
unless ref $plan and builtin::reftype($plan) eq "ARRAY" 1 4 5
Condition66%2/3
ref $plan and builtin::reftype($plan) eq "ARRAY"
!ll&&!rl&&r
104
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"
ABresult
0X0
100
111
128 unless ref($plan) && reftype($plan) eq 'ARRAY';
129  
130 4 $self->{sets_plan} = $plan;
131 }
132  
133 3 1;
134  
135 __END__
« blib/lib/Test2/Tools/Basic.pm ↑ Summary blib/lib/Test2/Compare/Ref.pm »