Kit/Run.pm

filter: Statementstmt 91.6% 33 / 36 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 92.8% 52 / 56 CC 9 SCAR 13.6
CC
9
Cov
94%
guard
5.0
give_back
5.0
__ANON__
1.4
CRAP 3.9
« Kit/Keys.pm ↑ Summary Kit/Choose.pm »
1 package Game::Terminal::Kit::Run;
2  
3 3 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.02';
8  
9 12 ▶sub give_back {
Subroutine give_back: called CC=5 SCAR=16.1
Pod documented
10 12 my (@held) = @_;
11 12 for my $thing (@held) {
12 19 ▶ next unless ref $thing;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $thing 2 17 19
13 17 ▶ eval { $thing->leave_raw } if $thing->can('leave_raw');
Branch: 1 branch
BranchTrueFalseTotal
if $thing->can("leave_raw") 10 7 17
14 17 ▶ eval { $thing->restore } if $thing->can('restore');
Branch: 1 branch
BranchTrueFalseTotal
if $thing->can("restore") 8 9 17
15 }
16 12 return;
17 }
18  
19 12 ▶sub guard {
Subroutine guard: called CC=5 SCAR=16.2
Pod documented
20 12 my ($body, @held) = @_;
21 12 local @SIG{qw(INT TERM HUP)};
22 12 for my $sig (qw(INT TERM HUP)) {
23 36 ▶ $SIG{$sig} = sub { give_back(@held); $SIG{$sig} = 'DEFAULT'; kill $sig, $$ };
Subroutine __ANON__: not called CC=1 SCAR=3.5
24 }
25 12 my $list = wantarray;
26 12 my @result;
27 12 my $lived = eval {
28 12 ▶ if ($list) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list) { } 5 7 12
29 5 @result = $body->();
30 } else {
31 7 $result[0] = $body->();
32 }
33 9 1;
34 };
35 12 my $died = $@;
36 12 give_back(@held);
37 12 ▶ die $died unless $lived;
Branch: 1 branch
BranchTrueFalseTotal
unless $lived 3 9 12
38 9 ▶ return $list ? @result : $result[0];
Branch: 1 branch
BranchTrueFalseTotal
$list ? : 5 4 9
39 }
40  
41 3 1;
42  
43 __END__
« Kit/Keys.pm ↑ Summary Kit/Choose.pm »