| 1 | package Scope::Guard; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 3 | ▶ | use Carp qw(confess); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 3 | ▶ | use Exporter (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||
| 10 | 3 | our @EXPORT_OK = qw(guard scope_guard); | |||||||||||||||||||
| 11 | 3 | our $VERSION = '0.21'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 21 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||
| 14 | 21 | ▶ | confess "Can't create a Scope::Guard in void context" unless (defined wantarray); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 18 | my $class = shift; | |||||||||||||||||||
| 17 | 18 | ▶ | my $handler = shift() || die 'Scope::Guard::new: no handler supplied'; | ||||||||||||||||||
|
Condition50%1/2
shift() || die('Scope::Guard::new: no handler supplied')
MC/DC0%0/1
shift() || die('Scope::Guard::new: no handler supplied')
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 18 | 18 | ▶ | 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
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 18 | ▶ | die "Scope::Guard::new: invalid handler - expected CODE ref, got: '$ref'" | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | unless ref($handler) eq 'CODE'; | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 18 | ▶ | 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
| |||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 18 | ▶ | sub dismiss { | ||||||||||||||||||
|
Subroutine
dismiss: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 27 | 18 | my $self = shift; | |||||||||||||||||||
| 28 | 18 | ▶ | my $dismiss = @_ ? shift : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 18 | $self->[0] = $dismiss; | |||||||||||||||||||
| 31 | } | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 7 | ▶ | sub guard(&) { __PACKAGE__->new(shift) } | ||||||||||||||||||
|
Subroutine
guard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 34 | 7 | ▶ | sub scope_guard($) { __PACKAGE__->new(shift) } | ||||||||||||||||||
|
Subroutine
scope_guard: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 18 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 37 | 18 | my $self = shift; | |||||||||||||||||||
| 38 | 18 | my ($dismiss, $handler) = @$self; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 18 | ▶ | $handler->() unless ($dismiss); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 3 | 1; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | __END__ | ||||||||||||||||||||