Restart.pm

filter: Statementstmt 96.9% 63 / 65 Branchbran 92.8% 13 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 16 / 16 Podpod 100% 5 / 5 totaltotal 95.1% 98 / 103 CC 12 SCAR 7.9
CC
12
Cov
95%
__ANON__
3.1
invoke
3.0
case
3.0
CRAP 2.2
↑ Summary Restart/Restart.pm »
1 package Worlogog::Restart;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 our $VERSION = '0.03';
7  
8 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Scope::OnExit::Wrap qw(on_scope_exit);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Return::MultiLevel qw(with_return);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use parent 'Exporter::Tiny';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 our @EXPORT_OK = qw(
14 case
15 bind
16 invoke
17 find
18 compute
19 );
20  
21 3 our @restarts;
22  
23 5 ▶sub bind (&$) {
Subroutine bind: called CC=1 SCAR=0.0
Pod documented
24 5 my ($body, $handlers) = @_;
25 5 my $limit = @restarts;
26 5 ▶ my $guard = on_scope_exit { splice @restarts, $limit };
Subroutine __ANON__: called CC=1 SCAR=0.0
27 5 push @restarts, \%$handlers;
28 5 $body->()
29 }
30  
31 8 ▶sub case (&$) {
Subroutine case: called CC=3 SCAR=11.0
Pod documented
32 8 my ($body, $handlers) = @_;
33 8 my $limit = @restarts;
34 8 ▶ my $guard = on_scope_exit { splice @restarts, $limit };
Subroutine __ANON__: called CC=1 SCAR=0.0
35 8 my $wantlist = wantarray;
36 8 ▶ my @v = with_return {
Subroutine __ANON__: called CC=3 SCAR=11.3
37 8 my ($return) = @_;
38 push @restarts, {
39 map {
40 8 my $v = $handlers->{$_};
41 4 ▶ $_ => sub { $return->($v, @_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
42 10 } keys %$handlers
43 };
44 8 ▶ unless (defined $wantlist) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $wantlist) 0 8 8
45 0 $body->();
46 0 return;
47 }
48 8 ▶ undef, $wantlist ? $body->() : scalar $body->()
Branch: 1 branch
BranchTrueFalseTotal
$wantlist ? : 1 7 8
49 8 };
50 7 ▶ if (my $f = shift @v) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = shift @v) 4 3 7
51 4 return $f->(@v);
52 }
53 3 ▶ $wantlist ? @v : $v[0]
Branch: 1 branch
BranchTrueFalseTotal
$wantlist ? : 1 2 3
54 }
55  
56 13 ▶sub _find {
Subroutine _find: called CC=3 SCAR=11.0
57 13 my ($k) = @_;
58 13 for my $rs (reverse @restarts) {
59 11 my $v = $rs->{$k};
60 11 ▶ return $v if $v;
Branch: 1 branch
BranchTrueFalseTotal
if $v 7 4 11
61 }
62 undef
63 6 }
64  
65 6 ▶sub invoke {
Subroutine invoke: called CC=3 SCAR=11.1
Pod documented
66 6 my $proto = shift;
67 6 ▶ my $code = ref $proto ? $proto->code : _find($proto) || croak qq{No restart named "$proto" is active};
Branch: 1 branch
BranchTrueFalseTotal
ref $proto ? : 1 5 6
Condition50%1/2
_find($proto) or croak(qq[No restart named "$proto" is active])
l!l
50
MC/DC0%0/1
_find($proto) or croak(qq[No restart named "$proto" is active])
_find($proto)
Truth table50%1/2
A
A= _find($proto)
Aresult
11
00
68 6 $code->(@_)
69 }
70  
71 8 ▶sub find {
Subroutine find: called CC=2 SCAR=6.9
Pod documented
72 8 my ($name) = @_;
73 8 ▶ my $code = _find($name) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $code = _find($name) or return undef 2 6 8
74 2 require Worlogog::Restart::Restart;
75 2 Worlogog::Restart::Restart->new(
76 name => $name,
77 code => $code,
78 )
79 }
80  
81 5 ▶sub compute {
Subroutine compute: called CC=3 SCAR=11.0
Pod documented
82 5 my @r;
83 5 for my $rs (reverse @restarts) {
84 10 for my $k (sort keys %$rs) {
85 12 my $v = $rs->{$k};
86 12 require Worlogog::Restart::Restart;
87 12 push @r, Worlogog::Restart::Restart->new(
88 name => $k,
89 code => $v,
90 );
91 }
92 }
93 @r
94 5 }
95  
96 3 'ok'
97  
98 __END__
↑ Summary Restart/Restart.pm »