Hooks/Ctl.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 4 / 4 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 4 / 4 totaltotal 100% 50 / 50 CC 6 SCAR 7.7
CC
6
Cov
100%
new
3.0
_cleanup
3.0
decline
2.0
CRAP 2.2
« Hooks.pm ↑ Summary
1 package Async::Hooks::Ctl;
2 {
3 4 $Async::Hooks::Ctl::VERSION = '0.16';
4 }
5  
6 # ABSTRACT: Hook control object
7  
8 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # $self is a arrayref with three positions:
12 # . first is a arrayref with hooks to call;
13 # . second is a arrayref with the arguments of each hook;
14 # . third is the cleanup sub: always called even when done().
15 #
16  
17 23 ▶sub new { return bless [undef, $_[1] || [], $_[2] || [], $_[3]], $_[0] }
Subroutine new: called CC=3 SCAR=11.0
Pod documented
Condition100%4/4
$_[1] || []
l!l
221
$_[2] || []
l!l
149
MC/DC100%1/1
$_[1] || []
$_[1]
MC/DC100%1/1
$_[2] || []
$_[2]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
18  
19 2 ▶sub args { return $_[0][2] }
Subroutine args: called CC=1 SCAR=0.0
Pod documented
20  
21 # stop() or done() stops the chain
22 7 ▶sub done {
Subroutine done: called CC=1 SCAR=0.0
Pod documented
23 7 my $ctl = $_[0];
24  
25 7 @{$ctl->[1]} = ();
26  
27 7 return $ctl->_cleanup(1);
28 }
29  
30 4 *stop = \&done;
31  
32  
33 # decline(), declined() or next() will call the next hook in the chain
34 48 ▶sub decline {
Subroutine decline: called CC=2 SCAR=6.9
Pod documented
35 48 my $ctl = $_[0];
36  
37 48 my $hook = shift @{$ctl->[1]};
38 48 ▶ return $hook->($ctl, $ctl->[2]) if $hook;
Branch: 1 branch
BranchTrueFalseTotal
if $hook 33 15 48
39  
40 15 return $ctl->_cleanup(0);
41 }
42  
43 4 *declined = \&decline;
44 4 *next = \&declined;
45  
46  
47 # _cleanup ends the chain processing
48 22 ▶sub _cleanup {
Subroutine _cleanup: called CC=3 SCAR=11.0
49 22 my ($ctl, $is_done) = @_;
50  
51 22 ▶ return unless my $cleanup = $ctl->[3];
Branch: 1 branch
BranchTrueFalseTotal
unless my $cleanup = $ctl->[3] 11 11 22
52 11 ▶ return $cleanup->($ctl, $ctl->[2], $is_done || 0);
Condition100%2/2
$is_done || 0
l!l
65
MC/DC100%1/1
$is_done || 0
$is_done
Truth table100%2/2
A
A= $is_done
Aresult
11
00
53 }
54  
55 4 1; # End of Async::Hooks::Ctl
56  
57  
58 __END__
« Hooks.pm ↑ Summary