| 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
| |||||||||||
| 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
| |||||||||||
| 35 | 807 | return $res; | |||||||||
| 36 | 421 | }; | |||||||||
| 37 | }, | ||||||||||
| 38 | 191 | ); | |||||||||
| 39 | |||||||||||
| 40 | 191 | 1; | |||||||||
| 41 | |||||||||||
| 42 | __END__ | ||||||||||