blib/lib/Test2/Util/Guard.pm

filter: Statementstmt 100% 23 / 23 Branchbran 62.5% 5 / 8 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 2 totaltotal 74.0% 37 / 50 CC 8 SCAR 14.7
CC
8
Cov
82%
new
7.6
dismiss
2.0
DESTROY
2.0
CRAP 4.4
« blib/lib/Test2/AsyncSubtest/Hub.pm ↑ Summary blib/lib/Test2/Tools/Ref.pm »
1 package Test2::Util::Guard;
2  
3 69 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 69 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 69 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 69 our $VERSION = '1.302226';
9  
10 48 ▶sub new {
Subroutine new: called CC=6 SCAR=20.3
Pod undocumented
11 48 ▶ confess "Can't create a Test2::Util::Guard in void context" unless (defined wantarray);
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 48 48
12  
13 48 my $class = shift;
14 48 ▶ my $handler = shift() || die 'Test2::Util::Guard::new: no handler supplied';
Condition50%1/2
shift() || die('Test2::Util::Guard::new: no handler supplied')
l!l
480
MC/DC0%0/1
shift() || die('Test2::Util::Guard::new: no handler supplied')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
15 48 ▶ my $ref = ref $handler || '';
Condition50%1/2
ref $handler || ''
l!l
480
MC/DC0%0/1
ref $handler || ''
ref $handler
Truth table50%1/2
A
A= ref $handler
Aresult
11
00
16  
17 48 ▶ die "Test2::Util::new: invalid handler - expected CODE ref, got: '$ref'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler eq "CODE" 0 48 48
18 unless ref($handler) eq 'CODE';
19  
20 48 ▶ bless [ 0, $handler ], ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0480
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
21 }
22  
23 44 ▶sub dismiss {
Subroutine dismiss: called CC=2 SCAR=7.1
Pod undocumented
24 44 my $self = shift;
25 44 ▶ my $dismiss = @_ ? shift : 1;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 44 44
26  
27 44 $self->[0] = $dismiss;
28 }
29  
30 45 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
31 45 my $self = shift;
32 45 my ($dismiss, $handler) = @$self;
33  
34 45 ▶ $handler->() unless ($dismiss);
Branch: 1 branch
BranchTrueFalseTotal
unless $dismiss 1 44 45
35 }
36  
37 69 1;
38  
39 __END__
« blib/lib/Test2/AsyncSubtest/Hub.pm ↑ Summary blib/lib/Test2/Tools/Ref.pm »