lib/Dancer/Hook.pm

filter: Statementstmt 90.3% 47 / 52 Branchbran 64.2% 9 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 86.8% 66 / 76 CC 8 SCAR 12.4
CC
8
Cov
85%
new
6.5
__ANON__
3.0
BEGIN
1.0
CRAP 3.4
« blib/lib/Dancer/Serializer/Mutable.pm ↑ Summary lib/Dancer/Hook/Properties.pm »
1 package Dancer::Hook;
2 178 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: Class to manipulate hooks with Dancer
4 178 $Dancer::Hook::VERSION = '1.3522';
5 178 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 178 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 178 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 178 ▶use base 'Dancer::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 178 __PACKAGE__->attributes(qw/name code properties/);
12  
13 178 ▶use Dancer::Factory::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 178 ▶use Dancer::Hook::Properties;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 178 ▶use Dancer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 134 ▶sub new {
Subroutine new: called CC=6 SCAR=18.8
Pod documented
18 134 my ($class, @args) = @_;
19  
20 134 my $self = bless {}, $class;
21  
22 134 ▶ if (!scalar @args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @args) 0 134 134
23 0 raise core_hook => "one name and a coderef are required";
24 }
25  
26 134 my $hook_name = shift @args;
27  
28 # XXX at the moment, we have a filer position named "before_template".
29 # this one is renamed "before_template_render", so we need to alias it.
30 # maybe we need to deprecate 'before_template' to enforce the use
31 # of 'hook before_template_render => sub {}' ?
32 134 ▶ $hook_name = 'before_template_render' if $hook_name eq 'before_template';
Branch: 1 branch
BranchTrueFalseTotal
if $hook_name eq "before_template" 5 129 134
33  
34 134 $self->name($hook_name);
35  
36 134 my ( $properties, $code );
37 134 ▶ if ( scalar @args == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1) { } 134 0 134
elsif (scalar @args == 2) { } 0 0 0
38 134 $properties = Dancer::Hook::Properties->new();
39 134 $code = shift @args;
40 }
41 elsif ( scalar @args == 2 ) {
42 0 my $prop = shift @args;
43 0 $properties = Dancer::Hook::Properties->new(%$prop);
44 0 $code = shift @args;
45 }
46 else {
47 0 raise core_hook => "something's wrong with parameters passed to Hook constructor";
48 }
49 134 ▶ ref $code eq 'CODE'
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq "CODE" or &raise("core_hook", "the code argument passed to hook construction was not a CodeRef. Value was : '${code}'") 133 1 134
50 or raise core_hook => "the code argument passed to hook construction was not a CodeRef. Value was : '$code'";
51  
52  
53 299 ▶ my $compiled_filter = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
54 299 my @arguments = @_;
55 299 ▶ return if Dancer::SharedData->response->halted;
Branch: 1 branch
BranchTrueFalseTotal
if "Dancer::SharedData"->response->halted 1 298 299
56  
57 298 my $app = Dancer::App->current();
58 298 ▶ return unless $properties->should_run_this_app($app->name);
Branch: 1 branch
BranchTrueFalseTotal
unless $properties->should_run_this_app($app->name) 0 298 298
59  
60 298 Dancer::Logger::core( "entering " . $hook_name . " hook" );
61  
62 298 $code->(@arguments);
63  
64 133 };
65  
66 133 $self->properties($properties);
67 133 $self->code($compiled_filter);
68  
69 133 Dancer::Factory::Hook->instance->register_hook($self);
70 133 return $self;
71 }
72  
73 178 1;
74  
75 __END__
« blib/lib/Dancer/Serializer/Mutable.pm ↑ Summary lib/Dancer/Hook/Properties.pm »