lib/Dancer2.pm

filter: Statementstmt 100% 78 / 78 Branchbran 93.7% 15 / 16 Conditioncond 70.0% 7 / 10 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 18 / 18 Podpod 0.0% 0 / 3 totaltotal 90.8% 119 / 131 CC 16 SCAR 19.0
CC
16
Cov
96%
import
14.0
VERSION
2.1
__ANON__
2.0
CRAP 6.7
« lib/Dancer2/Core/Error.pm ↑ Summary blib/lib/Dancer2/Template/TemplateToolkit.pm »
1 package Dancer2;
2 178 $Dancer2::VERSION = '2.3.0';
3 # ABSTRACT: Lightweight yet powerful web application framework
4  
5 178 ▶use 5.12.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 178 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 178 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 178 ▶use List::Util 'first';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 178 ▶use Module::Runtime 'use_module';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 178 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 178 ▶use Dancer2::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 178 ▶use Dancer2::Core::App;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 178 ▶use Dancer2::Core::Runner;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 178 our $AUTHORITY = 'SUKRIA';
16  
17 155 ▶sub VERSION { shift->SUPER::VERSION(@_) || '0.000000_000' }
Subroutine VERSION: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->SUPER::VERSION(@_) or "0.000000_000" 155 0 155
18  
19 178 our $runner;
20  
21 2964 ▶sub runner {$runner}
Subroutine runner: called CC=1 SCAR=0.0
Pod undocumented
22 41 ▶sub psgi_app { shift->runner->psgi_app(@_) }
Subroutine psgi_app: called CC=1 SCAR=0.0
Pod undocumented
23  
24 264 ▶sub import {
Subroutine import: called CC=14 SCAR=26.4
25 264 my ($class, @args) = @_;
26 264 my ($caller, $script) = caller;
27  
28 264 my @final_args;
29 my $clean_import;
30 264 foreach my $arg (@args) {
31  
32 # ignore, no longer necessary
33 # in the future these will warn as deprecated
34 39 ▶ grep +($arg eq $_), qw<:script :syntax :tests>
Branch: 1 branch
BranchTrueFalseTotal
grep(($arg eq $_), (":script", ":syntax", ":tests")) and next 3 36 39
35 and next;
36  
37 36 ▶ if ($arg eq ':nopragmas') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq ":nopragmas") 1 35 36
38 1 $clean_import++;
39 1 next;
40 }
41  
42 35 ▶ if (substr($arg, 0, 1) eq '!') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($arg, 0, 1) eq '!') { } 9 26 35
43 9 push @final_args, $arg, 1;
44 }
45 else {
46 26 push @final_args, $arg;
47 }
48 }
49  
50 $clean_import
51 or $_->import::into($caller)
52 264 ▶ for qw<strict warnings utf8>;
Branch: 1 branch
BranchTrueFalseTotal
$clean_import or $_->import::into($caller) 3 789 792
53  
54 264 ▶ scalar @final_args % 2
Branch: 1 branch
BranchTrueFalseTotal
scalar @final_args % 2 and die "parameters must be key/value pairs or '!keyword'" 2 262 264
55 and die q{parameters must be key/value pairs or '!keyword'};
56  
57 262 my %final_args = @final_args;
58  
59 262 my $appname = delete $final_args{appname};
60 262 ▶ $appname ||= $caller;
Condition66%2/3
$appname ||= $caller
l!l&&r!l&&!r
92530
MC/DC0%0/2
$appname ||= $caller
$appname $caller
Truth table66%2/3
A ||= B
A= $appnameB= $caller
ABresult
1X1
011
000
61  
62 # never instantiated the runner, should do it now
63 262 ▶ if (not defined $runner) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Dancer2::runner) 160 102 262
64 160 $runner = Dancer2::Core::Runner->new();
65 }
66  
67 # Search through registered apps, creating a new app object
68 # if we do not find one with the same name.
69 262 my $app;
70 262 ▶ ($app) = first { $_->name eq $appname } @{$runner->apps};
Subroutine __ANON__: called CC=1 SCAR=0.0
71  
72 262 ▶ if (!$app) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($app) 251 11 262
73  
74 # populating with the server's postponed hooks in advance
75 $app = Dancer2::Core::App->new(
76 name => $appname,
77 caller => $script,
78 environment => $runner->environment,
79 251 ▶ postponed_hooks => $runner->postponed_hooks->{$appname} || {},
Condition50%1/2
$Dancer2::runner->postponed_hooks->{$appname} || {}
l!l
0251
MC/DC0%0/1
$Dancer2::runner->postponed_hooks->{$appname} || {}
$Dancer2::runner->postponed_hooks->{$appname}
Truth table50%1/2
A
A= $Dancer2::runner->postponed_hooks->{$appname}
Aresult
11
00
80 );
81  
82 # register the app within the runner instance
83 250 $runner->register_application($app);
84 }
85  
86 261 _set_import_method_to_caller($caller);
87  
88 # use config dsl class, must extend Dancer2::Core::DSL
89 261 ▶ my $config_dsl = $app->setting('dsl_class') || 'Dancer2::Core::DSL';
Condition100%2/2
$app->setting('dsl_class') || 'Dancer2::Core::DSL'
l!l
1260
MC/DC100%1/1
$app->setting('dsl_class') || 'Dancer2::Core::DSL'
$app->setting('dsl_class')
Truth table100%2/2
A
A= $app->setting('dsl_class')
Aresult
11
00
90 261 ▶ $final_args{dsl} ||= $config_dsl;
Condition66%2/3
$final_args{"dsl"} ||= $config_dsl
l!l&&r!l&&!r
22590
MC/DC0%0/2
$final_args{"dsl"} ||= $config_dsl
$final_args{"dsl"} $config_dsl
Truth table66%2/3
A ||= B
A= $final_args{"dsl"}B= $config_dsl
ABresult
1X1
011
000
91  
92 # load the DSL, defaulting to Dancer2::Core::DSL
93 261 my $dsl = use_module($final_args{dsl})->new(app => $app);
94 261 $dsl->export_symbols_to($caller, \%final_args);
95 }
96  
97 261 ▶sub _set_import_method_to_caller {
Subroutine _set_import_method_to_caller: called CC=1 SCAR=0.0
98 261 my ($caller) = @_;
99  
100 13 ▶ my $import = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
101 13 my ($self, %options) = @_;
102  
103 13 my $with = $options{with};
104 13 for my $key (keys %$with) {
105 5 $self->dancer_app->setting($key => $with->{$key});
106 }
107 261 };
108  
109 {
110 ## no critic
111 178 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
112 178 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
113 261 *{"${caller}::import"} = $import;
114 }
115 }
116  
117 178 1;
118  
119 __END__
« lib/Dancer2/Core/Error.pm ↑ Summary blib/lib/Dancer2/Template/TemplateToolkit.pm »