| 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
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 35 | and next; | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 36 | ▶ | if ($arg eq ':nopragmas') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 1 | $clean_import++; | |||||||||||||||||||
| 39 | 1 | next; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 35 | ▶ | if (substr($arg, 0, 1) eq '!') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 264 | ▶ | scalar @final_args % 2 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
MC/DC0%0/2
$appname ||= $caller
$appname
$caller
Truth table66%2/3
A ||= B
A= $appnameB= $caller
| |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | # never instantiated the runner, should do it now | ||||||||||||||||||||
| 63 | 262 | ▶ | if (not defined $runner) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 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} || {}
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}
| |||||||||||||||||||||
| 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'
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')
| |||||||||||||||||||||
| 90 | 261 | ▶ | $final_args{dsl} ||= $config_dsl; | ||||||||||||||||||
|
Condition66%2/3
$final_args{"dsl"} ||= $config_dsl
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
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||