Reversible.pm

filter: Statementstmt 93.9% 31 / 33 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.8% 8 / 9 Podpod 100% 3 / 3 totaltotal 90.2% 46 / 51 CC 5 SCAR 9.6
CC
5
Cov
90%
reversibly
5.0
failure_warning
2.0
BEGIN
1.0
CRAP 2.6
« Its/RT.pm ↑ Summary Test.pm »
1 package App::Gitc::Reversible;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 our @EXPORT = qw(
8 failure_warning
9 to_undo
10 reversibly
11 );
12 };
13  
14 # ABSTRACT: Simple reversible computation for gitc
15 3 our $VERSION = '0.60'; # VERSION
16  
17  
18 0 ▶sub failure_warning {
Subroutine failure_warning: not called CC=1 SCAR=6.9
Pod documented
19 0 my ($message) = @_;
20 0 our $failure_warning = $message;
21 }
22  
23  
24  
25 23 ▶sub to_undo (&) {
Subroutine to_undo: called CC=1 SCAR=0.0
Pod documented
26 23 my ($code) = @_;
27 23 push our(@undo_stack), $code;
28 23 return;
29 }
30  
31  
32 14 ▶sub reversibly(&) {
Subroutine reversibly: called CC=5 SCAR=16.1
Pod documented
33 14 my ($code) = @_;
34  
35 14 ▶ local $SIG{INT} = sub { die "SIGINT\n" };
Subroutine __ANON__: called CC=1 SCAR=0.0
36 14 ▶ local $SIG{TERM} = sub { die "SIGTERM\n" };
Subroutine __ANON__: called CC=1 SCAR=0.0
37 14 local our(@undo_stack); # to allow nested, reversible computations
38  
39 14 my $rc = eval { $code->() };
40 14 ▶ if ( my $exception = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $exception = $@) 10 4 14
41 10 our $failure_warning;
42 10 ▶ warn $failure_warning if defined $failure_warning;
Branch: 1 branch
BranchTrueFalseTotal
if defined $App::Gitc::Reversible::failure_warning 0 10 10
43 10 for my $undo ( reverse @undo_stack ) {
44 16 eval { $undo->() };
45 16 ▶ warn "Exception during undo: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 16 16
46 }
47  
48 # rethrow the exception, with commentary
49 10 die "\nThe exception that caused rollback was: $exception";
50 }
51 }
52  
53  
54  
55 3 1;
56  
57 __END__
« Its/RT.pm ↑ Summary Test.pm »