line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Factory::Hook; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SUKRIA'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Singleton class to create Dancer hooks |
4
|
|
|
|
|
|
|
$Dancer::Factory::Hook::VERSION = '1.3514_04'; # TRIAL |
5
|
|
|
|
|
|
|
$Dancer::Factory::Hook::VERSION = '1.351404'; |
6
|
195
|
|
|
195
|
|
1730
|
use strict; |
|
195
|
|
|
|
|
353
|
|
|
195
|
|
|
|
|
6355
|
|
7
|
195
|
|
|
195
|
|
1263
|
use warnings; |
|
195
|
|
|
|
|
338
|
|
|
195
|
|
|
|
|
4452
|
|
8
|
195
|
|
|
195
|
|
868
|
use Carp; |
|
195
|
|
|
|
|
381
|
|
|
195
|
|
|
|
|
10103
|
|
9
|
|
|
|
|
|
|
|
10
|
195
|
|
|
195
|
|
3407
|
use base 'Dancer::Object::Singleton'; |
|
195
|
|
|
|
|
455
|
|
|
195
|
|
|
|
|
71635
|
|
11
|
195
|
|
|
195
|
|
1143
|
use Dancer::Exception qw(:all); |
|
195
|
|
|
|
|
362
|
|
|
195
|
|
|
|
|
95130
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->attributes(qw/ hooks registered_hooks/); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub init { |
16
|
195
|
|
|
195
|
1
|
422
|
my ( $class, $self ) = @_; |
17
|
195
|
|
|
|
|
657
|
$self->hooks( {} ); |
18
|
195
|
|
|
|
|
653
|
$self->registered_hooks( [] ); |
19
|
195
|
|
|
|
|
367
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub install_hooks { |
23
|
1233
|
|
|
1233
|
0
|
3498
|
my ( $self, @hooks_name ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
1233
|
50
|
|
|
|
3363
|
if ( !scalar @hooks_name ) { |
26
|
0
|
|
|
|
|
0
|
raise core_factory_hook => "at least one name is required"; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
1233
|
|
|
|
|
2758
|
foreach my $hook_name (@hooks_name) { |
30
|
3171
|
50
|
|
|
|
6301
|
if ( $self->hook_is_registered($hook_name) ) { |
31
|
0
|
|
|
|
|
0
|
raise core_factory_hook => "$hook_name is already regsitered, please use another name"; |
32
|
|
|
|
|
|
|
} |
33
|
3171
|
|
|
|
|
5820
|
$self->_add_hook( $hook_name ); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub register_hook { |
38
|
132
|
|
|
132
|
0
|
249
|
my ( $self, $hook ) = @_; |
39
|
132
|
|
|
|
|
322
|
$self->_add_registered_hook( $hook->name, $hook->code ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _add_registered_hook { |
43
|
132
|
|
|
132
|
|
319
|
my ($class, $hook_name, $compiled_filter) = @_; |
44
|
132
|
|
|
|
|
191
|
push @{$class->hooks->{$hook_name}}, $compiled_filter; |
|
132
|
|
|
|
|
349
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _add_hook { |
48
|
3171
|
|
|
3171
|
|
4882
|
my ($self, $hook_name ) = @_; |
49
|
3171
|
|
|
|
|
3639
|
push @{$self->registered_hooks}, $hook_name; |
|
3171
|
|
|
|
|
5245
|
|
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub hook_is_registered { |
53
|
5161
|
|
|
5161
|
0
|
7852
|
my ( $self, $hook_name ) = @_; |
54
|
5161
|
|
|
|
|
6111
|
return grep { $_ eq $hook_name } @{$self->registered_hooks}; |
|
61996
|
|
|
|
|
86642
|
|
|
5161
|
|
|
|
|
10095
|
|
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub execute_hooks { |
58
|
1990
|
|
|
1990
|
0
|
4121
|
my ($self, $hook_name, @args) = @_; |
59
|
|
|
|
|
|
|
|
60
|
1990
|
50
|
|
|
|
3464
|
raise core_factory_hook => "Can't ask for hooks without a position" unless $hook_name; |
61
|
|
|
|
|
|
|
|
62
|
1990
|
50
|
|
|
|
3787
|
if (!$self->hook_is_registered($hook_name)){ |
63
|
0
|
|
|
|
|
0
|
raise core_factory_hook => "The hook '$hook_name' doesn't exists"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
1990
|
|
|
|
|
2585
|
foreach my $h (@{$self->get_hooks_for($hook_name)}) { |
|
1990
|
|
|
|
|
3696
|
|
67
|
299
|
|
|
|
|
1453
|
$h->(@args); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub get_hooks_for { |
72
|
1992
|
|
|
1992
|
0
|
3091
|
my ( $self, $hook_name ) = @_; |
73
|
|
|
|
|
|
|
|
74
|
1992
|
50
|
|
|
|
3308
|
raise core_factory_hook => "Can't ask for hooks without a position" unless $hook_name; |
75
|
|
|
|
|
|
|
|
76
|
1992
|
100
|
|
|
|
3721
|
$self->hooks->{$hook_name} || []; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
__END__ |