lib/Dancer2/Core/Hook.pm

filter: Statementstmt 100% 25 / 25 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 100% 36 / 36 CC 3 SCAR 3.7
CC
3
Cov
100%
__ANON__
2.0
__ANON__
2.0
BEGIN
1.0
CRAP 1.4
« lib/Dancer2/Core.pm ↑ Summary lib/Dancer2/Core/Response/Delayed.pm »
1 package Dancer2::Core::Hook;
2 # ABSTRACT: Manipulate hooks with Dancer2
3 191 $Dancer2::Core::Hook::VERSION = '2.3.0';
4 191 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 191 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 191 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 191 ▶use Sub::Util qw/ set_subname subname /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 has name => (
10 is => 'rw',
11 isa => Str,
12 required => 1,
13 829 ▶ coerce => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
14 829 my ($hook_name) = @_;
15  
16 # XXX at the moment, we have a filer position named "before_template".
17 # this one is renamed "before_template_render", so we need to alias it.
18 # maybe we need to deprecate 'before_template' to enforce the use
19 # of 'hook before_template_render => sub {}' ?
20 829 ▶ $hook_name = 'before_template_render'
Branch: 1 branch
BranchTrueFalseTotal
if $hook_name eq "before_template" 5 824 829
21 if $hook_name eq 'before_template';
22 829 return $hook_name;
23 },
24 191 );
25  
26 has code => (
27 is => 'ro',
28 isa => CodeRef,
29 required => 1,
30 421 ▶ coerce => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 421 my ($hook) = @_;
32 835 ▶ set_subname subname($hook) => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
33 835 my $res = eval { $hook->(@_) };
34 827 ▶ croak "Hook error: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 20 807 827
35 807 return $res;
36 421 };
37 },
38 191 );
39  
40 191 1;
41  
42 __END__
« lib/Dancer2/Core.pm ↑ Summary lib/Dancer2/Core/Response/Delayed.pm »