blib/lib/Scope/Guard.pm

filter: Statementstmt 100% 30 / 30 Branchbran 87.5% 7 / 8 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 85.4% 53 / 62 CC 8 SCAR 12.4
CC
8
Cov
89%
new
6.9
dismiss
2.0
DESTROY
2.0
CRAP 3.5
↑ Summary
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
BranchTrueFalseTotal
unless defined wantarray 3 18 21
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')
l!l
180
MC/DC0%0/1
shift() || die('Scope::Guard::new: no handler supplied')
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
18 18 ▶ my $ref = ref $handler || '';
Condition50%1/2
ref $handler || ''
l!l
180
MC/DC0%0/1
ref $handler || ''
ref $handler
Truth table50%1/2
A
A= ref $handler
Aresult
11
00
19  
20 18 ▶ die "Scope::Guard::new: invalid handler - expected CODE ref, got: '$ref'"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $handler eq "CODE" 0 18 18
21 unless ref($handler) eq 'CODE';
22  
23 18 ▶ bless [ 0, $handler ], ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0180
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
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
BranchTrueFalseTotal
@_ ? : 12 6 18
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
BranchTrueFalseTotal
unless $dismiss 12 6 18
41 }
42  
43 3 1;
44  
45 __END__
↑ Summary