blib/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 blib/lib/Dancer/Hook/Properties.pm »
1 package Dancer::Hook;
2 169 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: Class to manipulate hooks with Dancer
4 169 $Dancer::Hook::VERSION = '1.3513';
5 169 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 169 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 169 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 169 ▶use base 'Dancer::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 169 __PACKAGE__->attributes(qw/name code properties/);
12  
13 169 ▶use Dancer::Factory::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 169 ▶use Dancer::Hook::Properties;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 169 ▶use Dancer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub new {
18 128 ▶ my ($class, @args) = @_;
Subroutine new: called CC=6 SCAR=18.8
Pod documented
19  
20 128 my $self = bless {}, $class;
21  
22 128 ▶ if (!scalar @args) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @args) 0 128 128
23 0 raise core_hook => "one name and a coderef are required";
24 }
25  
26 128 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 128 ▶ $hook_name = 'before_template_render' if $hook_name eq 'before_template';
Branch: 1 branch
BranchTrueFalseTotal
if $hook_name eq "before_template" 5 123 128
33  
34 128 $self->name($hook_name);
35  
36 128 my ( $properties, $code );
37 128 ▶ if ( scalar @args == 1 ) {
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @args == 1) { } 128 0 128
elsif (scalar @args == 2) { } 0 0 0
38 128 $properties = Dancer::Hook::Properties->new();
39 128 $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 128 ▶ 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}'") 1 127 128
50 or raise core_hook => "the code argument passed to hook construction was not a CodeRef. Value was : '$code'";
51  
52  
53 my $compiled_filter = sub {
54 292 ▶ my @arguments = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
55 292 ▶ return if Dancer::SharedData->response->halted;
Branch: 1 branch
BranchTrueFalseTotal
if "Dancer::SharedData"->response->halted 1 291 292
56  
57 291 my $app = Dancer::App->current();
58 291 ▶ return unless $properties->should_run_this_app($app->name);
Branch: 1 branch
BranchTrueFalseTotal
unless $properties->should_run_this_app($app->name) 0 291 291
59  
60 291 Dancer::Logger::core( "entering " . $hook_name . " hook" );
61  
62 291 $code->(@arguments);
63  
64 127 };
65  
66 127 $self->properties($properties);
67 127 $self->code($compiled_filter);
68  
69 127 Dancer::Factory::Hook->instance->register_hook($self);
70 127 return $self;
71 }
72  
73 169 1;
74  
75 __END__
« blib/lib/Dancer/Serializer/Mutable.pm ↑ Summary blib/lib/Dancer/Hook/Properties.pm »