| 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
| |||||||||||||||||||||
| 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')
MC/DC0%0/1
shift() || die('Test2::Util::Guard::new: no handler supplied')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 15 | 48 | ▶ | my $ref = ref $handler || ''; | ||||||||||||||||||
|
Condition50%1/2
ref $handler || ''
MC/DC0%0/1
ref $handler || ''
ref $handler
Truth table50%1/2
A
A= ref $handler
| |||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 48 | ▶ | die "Test2::Util::new: invalid handler - expected CODE ref, got: '$ref'" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | unless ref($handler) eq 'CODE'; | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 48 | ▶ | bless [ 0, $handler ], ref $class || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 69 | 1; | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | __END__ | ||||||||||||||||||||