Hooks.pm

filter: Statementstmt 100% 37 / 37 Branchbran 88.8% 16 / 18 Conditioncond 81.8% 9 / 11 MC/DCmcdc 71.4% 5 / 7 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 92.8% 78 / 84 CC 14 SCAR 16.7
CC
14
Cov
94%
call
9.1
hook
4.0
has_hooks_for
3.0
CRAP 5.3
↑ Summary Hooks/Ctl.pm »
1 package Async::Hooks;
2 {
3 3 $Async::Hooks::VERSION = '0.16';
4 }
5  
6 # ABSTRACT: Hook system with asynchronous capabilities
7  
8 3 ▶use Mo qw(is default);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp 'confess';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Async::Hooks::Ctl;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 has registry => (
15 is => 'ro',
16 1 ▶ default => sub { {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
17 3 );
18  
19  
20 23 ▶sub hook {
Subroutine hook: called CC=4 SCAR=13.9
Pod documented
21 23 my ($self, $hook, $cb) = @_;
22  
23 23 ▶ confess("Missing first parameter, the hook name, ") unless $hook;
Branch: 1 branch
BranchTrueFalseTotal
unless $hook 2 21 23
24 21 ▶ confess("Missing second parameter, the coderef callback, ")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 2 19 21
25 unless ref($cb) eq 'CODE';
26  
27 19 ▶ my $cbs = $self->{registry}{$hook} ||= [];
Condition100%2/2
$self->{"registry"}{$hook} ||= []
l!l
910
MC/DC100%1/1
$self->{"registry"}{$hook} ||= []
$self->{"registry"}{$hook}
Truth table100%2/2
A
A= $self->{"registry"}{$hook}
Aresult
11
00
28 19 push @$cbs, $cb;
29  
30 19 return;
31 }
32  
33  
34 6 ▶sub has_hooks_for {
Subroutine has_hooks_for: called CC=3 SCAR=11.0
Pod documented
35 6 my ($self, $hook) = @_;
36  
37 6 ▶ confess("Missing first parameter, the hook name, ") unless $hook;
Branch: 1 branch
BranchTrueFalseTotal
unless $hook 0 6 6
38  
39 6 my $reg = $self->{registry};
40 6 ▶ return 0 unless exists $reg->{$hook};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $reg->{$hook} 2 4 6
41 4 return scalar(@{$reg->{$hook}});
42 }
43  
44  
45 22 ▶sub call {
Subroutine call: called CC=9 SCAR=22.1
Pod documented
46 22 my ($self, $hook, $args, $cleanup) = @_;
47 22 ▶ ($args, $cleanup) = (undef, $args) if ref($args) eq 'CODE' && !$cleanup;
Branch: 1 branch
BranchTrueFalseTotal
if ref $args eq "CODE" and not $cleanup 0 22 22
Condition33%1/3
ref $args eq "CODE" and not $cleanup
!ll&&!rl&&r
2200
MC/DC0%0/2
ref $args eq "CODE" and not $cleanup
ref $args eq "CODE" not $cleanup
Truth table33%1/3
A and not(B)
A= ref $args eq "CODE"B= not $cleanup
ABresult
0X0
100
111
48  
49 22 ▶ confess("Missing first parameter, the hook name, ") unless $hook;
Branch: 1 branch
BranchTrueFalseTotal
unless $hook 1 21 22
50 21 ▶ confess("Second parameter, the arguments list, must be a arrayref, ")
Branch: 1 branch
BranchTrueFalseTotal
if $args and ref $args ne "ARRAY" 2 19 21
Condition100%3/3
$args and ref $args ne "ARRAY"
!ll&&!rl&&r
8112
MC/DC100%2/2
$args and ref $args ne "ARRAY"
$args ref $args ne "ARRAY"
Truth table100%3/3
A and B
A= $argsB= ref $args ne "ARRAY"
ABresult
0X0
100
111
51 if $args && ref($args) ne 'ARRAY';
52 19 ▶ confess("Third parameter, the cleanup callback, must be a coderef, ")
Branch: 1 branch
BranchTrueFalseTotal
if $cleanup and ref $cleanup ne "CODE" 2 17 19
Condition100%3/3
$cleanup and ref $cleanup ne "CODE"
!ll&&!rl&&r
7102
MC/DC100%2/2
$cleanup and ref $cleanup ne "CODE"
$cleanup ref $cleanup ne "CODE"
Truth table100%3/3
A and B
A= $cleanupB= ref $cleanup ne "CODE"
ABresult
0X0
100
111
53 if $cleanup && ref($cleanup) ne 'CODE';
54  
55 17 my $r = $self->{registry};
56 17 ▶ my $cbs = exists $r->{$hook} ? $r->{$hook} : [];
Branch: 1 branch
BranchTrueFalseTotal
exists $r->{$hook} ? : 11 6 17
57  
58 17 return Async::Hooks::Ctl->new([@$cbs], $args, $cleanup)->next;
59 }
60  
61  
62 3 1; # End of Async::Hooks
63  
64  
65 __END__
↑ Summary Hooks/Ctl.pm »