blib/lib/Dancer.pm

filter: Statementstmt 85.9% 251 / 292 Branchbran 70.7% 58 / 82 Conditioncond 41.6% 15 / 36 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 86.1% 93 / 108 Podpod 100% 67 / 67 totaltotal 80.0% 486 / 607 SCAR 44.7
CC
57
Cov
79%
__ANON__
56.0
_send_file
42.1
_init_script_dir
18.2
CRAP 87.0
« blib/lib/Dancer/Config.pm ↑ Summary blib/lib/Dancer/Test.pm »
1 package Dancer;
2 169 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: lightweight yet powerful web application framework
4 169 $Dancer::VERSION = '1.3520';
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 169 ▶use Cwd 'realpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 169 ▶use Dancer::App;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 169 ▶use Dancer::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 169 ▶use Dancer::Cookies;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 169 ▶use Dancer::FileUtils;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 169 ▶use Dancer::GetOpt;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 169 ▶use Dancer::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 169 ▶use Dancer::Hook;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 169 ▶use Dancer::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 169 ▶use Dancer::Renderer;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 169 ▶use Dancer::Route;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 169 ▶use Dancer::Serializer::JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 169 ▶use Dancer::Serializer::YAML;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 169 ▶use Dancer::Serializer::XML;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 169 ▶use Dancer::Serializer::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 169 ▶use Dancer::Session;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 169 ▶use Dancer::SharedData;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 169 ▶use Dancer::Handler;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 169 ▶use Dancer::MIME;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 169 ▶use Dancer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 169 ▶use Dancer::Continuation::Halted;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 169 ▶use Dancer::Continuation::Route::Forwarded;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 169 ▶use Dancer::Continuation::Route::Passed;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 169 ▶use Dancer::Continuation::Route::ErrorSent;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 169 ▶use Dancer::Continuation::Route::FileSent;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 169 ▶use Dancer::Continuation::Route::Templated;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 169 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 169 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 169 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 169 our @EXPORT = qw(
43 after
44 any
45 before
46 before_template
47 cookie
48 cookies
49 config
50 content_type
51 dance
52 dancer_version
53 debug
54 del
55 dirname
56 info
57 error
58 engine
59 false
60 forward
61 from_dumper
62 from_json
63 from_yaml
64 from_xml
65 get
66 halt
67 header
68 headers
69 hook
70 layout
71 load
72 load_app
73 logger
74 mime
75 options
76 param
77 param_array
78 params
79 pass
80 path
81 patch
82 post
83 prefix
84 push_header
85 put
86 redirect
87 render_with_layout
88 request
89 send_file
90 send_error
91 set
92 setting
93 set_cookie
94 session
95 splat
96 status
97 start
98 template
99 to_dumper
100 to_json
101 to_yaml
102 to_xml
103 true
104 upload
105 captures
106 uri_for
107 var
108 vars
109 warning
110 );
111  
112 # Dancer's syntax
113  
114 sub after {
115 0 ▶ Dancer::Deprecation->deprecated(reason => "use hooks!",
Subroutine after: not called CC=1 SCAR=6.9
Pod documented
116 version => '1.3080',
117 fatal => 0);
118 0 Dancer::Hook->new('after', @_);
119 }
120 sub before {
121 0 ▶ Dancer::Deprecation->deprecated(reason => "use hooks!",
Subroutine before: not called CC=1 SCAR=6.9
Pod documented
122 version => '1.3080',
123 fatal => 0);
124 0 Dancer::Hook->new('before', @_);
125 }
126 sub before_template {
127 0 ▶ Dancer::Deprecation->deprecated(reason => "use hooks!",
Subroutine before_template: not called CC=1 SCAR=6.9
Pod documented
128 version => '1.3080',
129 fatal => 0);
130 0 Dancer::Hook->new('before_template', @_);
131 }
132  
133 24 ▶sub any { Dancer::App->current->registry->any_add(@_) }
Subroutine any: called CC=1 SCAR=0.0
Pod documented
134 2 ▶sub captures { Dancer::SharedData->request->params->{captures} }
Subroutine captures: called CC=1 SCAR=0.0
Pod documented
135 4 ▶sub cookie { Dancer::Cookies->cookie( @_ ) }
Subroutine cookie: called CC=1 SCAR=0.0
Pod documented
136 7 ▶sub cookies { Dancer::Cookies->cookies }
Subroutine cookies: called CC=1 SCAR=0.0
Pod documented
137 17 ▶sub config { Dancer::Config::settings() }
Subroutine config: called CC=1 SCAR=0.0
Pod documented
138 22 ▶sub content_type { Dancer::SharedData->response->content_type(@_) }
Subroutine content_type: called CC=1 SCAR=0.0
Pod documented
139 0 ▶sub dance { goto &start }
Subroutine dance: not called CC=1 SCAR=6.9
Pod documented
140 0 ▶sub dancer_version { Dancer->VERSION }
Subroutine dancer_version: not called CC=1 SCAR=6.9
Pod documented
141 5 ▶sub debug { goto &Dancer::Logger::debug }
Subroutine debug: called CC=1 SCAR=0.0
Pod documented
142 2 ▶sub del { Dancer::App->current->registry->universal_add('delete', @_) }
Subroutine del: called CC=1 SCAR=0.0
Pod documented
143 12 ▶sub dirname { Dancer::FileUtils::dirname(@_) }
Subroutine dirname: called CC=1 SCAR=0.0
Pod documented
144 32 ▶sub engine { Dancer::Engine->engine(@_) }
Subroutine engine: called CC=1 SCAR=0.0
Pod documented
145 6 ▶sub error { goto &Dancer::Logger::error }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
146 1 ▶sub false { 0 }
Subroutine false: called CC=1 SCAR=0.0
Pod documented
147 15 ▶sub forward { Dancer::SharedData->response->forward(@_);
Subroutine forward: called CC=1 SCAR=0.0
Pod documented
148 # throw a special continuation exception
149 15 Dancer::Continuation::Route::Forwarded->new->throw;
150 }
151 0 ▶sub from_dumper { Dancer::Serializer::Dumper::from_dumper(@_) }
Subroutine from_dumper: not called CC=1 SCAR=6.9
Pod documented
152 13 ▶sub from_json { Dancer::Serializer::JSON::from_json(@_) }
Subroutine from_json: called CC=1 SCAR=0.0
Pod documented
153 0 ▶sub from_xml { Dancer::Serializer::XML::from_xml(@_) }
Subroutine from_xml: not called CC=1 SCAR=6.9
Pod documented
154 8 ▶sub from_yaml { Dancer::Serializer::YAML::from_yaml(@_) }
Subroutine from_yaml: called CC=1 SCAR=0.0
Pod documented
155 640 ▶sub get { map { my $r = $_; Dancer::App->current->registry->universal_add($r, @_) } qw(head get) }
Subroutine get: called CC=1 SCAR=0.0
Pod documented
156 11 ▶sub halt { Dancer::SharedData->response->halt(@_);
Subroutine halt: called CC=1 SCAR=0.0
Pod documented
157 # throw a special continuation exception
158 11 Dancer::Continuation::Halted->new->throw;
159 }
160 8 ▶sub header { goto &headers }
Subroutine header: called CC=1 SCAR=0.0
Pod documented
161 0 ▶sub info { goto &Dancer::Logger::info }
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
162 9 ▶sub push_header { Dancer::SharedData->response->push_header(@_); }
Subroutine push_header: called CC=1 SCAR=0.0
Pod documented
163 15 ▶sub headers { Dancer::SharedData->response->headers(@_); }
Subroutine headers: called CC=1 SCAR=0.0
Pod documented
164 116 ▶sub hook { Dancer::Hook->new(@_) }
Subroutine hook: called CC=1 SCAR=0.0
Pod documented
165 sub layout {
166 0 ▶ Dancer::Deprecation->deprecated(reason => "use 'set layout => \"value\"'",
Subroutine layout: not called CC=1 SCAR=6.9
Pod documented
167 version => '1.3050',
168 fatal => 1);
169 }
170 1 ▶sub load { require $_ for @_ }
Subroutine load: called CC=2 SCAR=6.9
Pod documented
171 9 ▶sub load_app { goto &_load_app } # goto doesn't add a call frame. So caller() will work as expected
Subroutine load_app: called CC=1 SCAR=0.0
Pod documented
172 sub logger {
173 0 ▶ Dancer::Deprecation->deprecated(reason => "use 'set logger => \"value\"'",
Subroutine logger: not called CC=1 SCAR=6.9
Pod documented
174 fatal => 1,version=>'1.3050');
175 }
176 8 ▶sub mime { Dancer::MIME->instance() }
Subroutine mime: called CC=1 SCAR=0.0
Pod documented
177 1 ▶sub options { Dancer::App->current->registry->universal_add('options', @_) }
Subroutine options: called CC=1 SCAR=0.0
Pod documented
178 255 ▶sub params { Dancer::SharedData->request->params(@_) }
Subroutine params: called CC=1 SCAR=0.0
Pod documented
179 13 ▶sub param { params->{$_[0]} }
Subroutine param: called CC=1 SCAR=0.0
Pod documented
180 sub param_array {
181 6 ▶ my $value = param(shift);
Subroutine param_array: called CC=3 SCAR=11.0
Pod documented
182  
183 6 ▶ my @array = ref $value eq 'ARRAY' ? @$value
Branch: 2 branches
BranchTrueFalseTotal
ref $value eq 'ARRAY' ? : 2 4 6
defined $value ? : 2 2 4
184 : defined $value ? ( $value )
185 : ()
186 ;
187  
188 6 return @array;
189 }
190 78 ▶sub pass { Dancer::SharedData->response->pass(1);
Subroutine pass: called CC=1 SCAR=0.0
Pod documented
191 # throw a special continuation exception
192 78 Dancer::Continuation::Route::Passed->new->throw;
193 }
194 0 ▶sub patch { Dancer::App->current->registry->universal_add('patch', @_) }
Subroutine patch: not called CC=1 SCAR=6.9
Pod documented
195 223 ▶sub path { Dancer::FileUtils::path(@_) }
Subroutine path: called CC=1 SCAR=0.0
Pod documented
196 72 ▶sub post { Dancer::App->current->registry->universal_add('post', @_) }
Subroutine post: called CC=1 SCAR=0.0
Pod documented
197 32 ▶sub prefix { @_ == 0 ? Dancer::App->current->get_prefix :
Subroutine prefix: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 0 ? : 3 29 32
198 Dancer::App->current->set_prefix(@_) }
199 20 ▶sub put { Dancer::App->current->registry->universal_add('put', @_) }
Subroutine put: called CC=1 SCAR=0.0
Pod documented
200 19 ▶sub redirect { goto &_redirect }
Subroutine redirect: called CC=1 SCAR=0.0
Pod documented
201 0 ▶sub render_with_layout { Dancer::Template::Abstract->_render_with_layout(@_) }
Subroutine render_with_layout: not called CC=1 SCAR=6.9
Pod documented
202 222 ▶sub request { Dancer::SharedData->request }
Subroutine request: called CC=1 SCAR=0.0
Pod documented
203 11 ▶sub send_error { Dancer::Continuation::Route::ErrorSent->new(
Subroutine send_error: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
$_[1] || 500
l!l
65
MC/DC100%1/1
$_[1] || 500
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
204 return_value => Dancer::Error->new(
205 message => $_[0],
206 code => $_[1] || 500)->render()
207 )->throw }
208 #sub send_file { goto &_send_file }
209 9 ▶sub send_file { Dancer::Continuation::Route::FileSent->new(
Subroutine send_file: called CC=1 SCAR=0.0
Pod documented
210 return_value => _send_file(@_)
211 )->throw
212 }
213 99 ▶sub set { goto &setting }
Subroutine set: called CC=1 SCAR=0.0
Pod documented
214 8 ▶sub set_cookie { Dancer::Cookies->set_cookie(@_) }
Subroutine set_cookie: called CC=1 SCAR=0.0
Pod documented
215 1365 ▶sub setting { Dancer::App->applications ? Dancer::App->current->setting(@_) : Dancer::Config::setting(@_) }
Subroutine setting: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
'Dancer::App'->applications ? : 107 1258 1365
216 18 ▶sub session { goto &_session }
Subroutine session: called CC=1 SCAR=0.0
Pod documented
217 21 ▶sub splat { @{ Dancer::SharedData->request->params->{splat} || [] } }
Subroutine splat: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
"Dancer::SharedData"->request->params->{"splat"} or [] 0 21 21
218 2 ▶sub start { goto &_start }
Subroutine start: called CC=1 SCAR=0.0
Pod documented
219 9 ▶sub status { Dancer::SharedData->response->status(@_) }
Subroutine status: called CC=1 SCAR=0.0
Pod documented
220 39 ▶sub template { Dancer::Template::Abstract->template(@_) }
Subroutine template: called CC=1 SCAR=0.0
Pod documented
221 1 ▶sub to_dumper { Dancer::Serializer::Dumper::to_dumper(@_) }
Subroutine to_dumper: called CC=1 SCAR=0.0
Pod documented
222 8 ▶sub to_json { Dancer::Serializer::JSON::to_json(@_) }
Subroutine to_json: called CC=1 SCAR=0.0
Pod documented
223 0 ▶sub to_xml { Dancer::Serializer::XML::to_xml(@_) }
Subroutine to_xml: not called CC=1 SCAR=6.9
Pod documented
224 4 ▶sub to_yaml { Dancer::Serializer::YAML::to_yaml(@_) }
Subroutine to_yaml: called CC=1 SCAR=0.0
Pod documented
225 21 ▶sub true { 1 }
Subroutine true: called CC=1 SCAR=0.0
Pod documented
226 3 ▶sub upload { Dancer::SharedData->request->upload(@_) }
Subroutine upload: called CC=1 SCAR=0.0
Pod documented
227 1 ▶sub uri_for { Dancer::SharedData->request->uri_for(@_) }
Subroutine uri_for: called CC=1 SCAR=0.0
Pod documented
228 19 ▶sub var { Dancer::SharedData->var(@_) }
Subroutine var: called CC=1 SCAR=0.0
Pod documented
229 28 ▶sub vars { Dancer::SharedData->vars }
Subroutine vars: called CC=1 SCAR=0.0
Pod documented
230 3 ▶sub warning { goto &Dancer::Logger::warning }
Subroutine warning: called CC=1 SCAR=0.0
Pod documented
231  
232 # When importing the package, strict and warnings pragma are loaded,
233 # and the appdir detection is performed.
234 {
235 169 my $as_script = 0;
236  
237 sub import {
238 306 ▶ my ($class, @args) = @_;
Subroutine import: called CC=9 SCAR=22.0
239 306 my ($package, $script) = caller;
240  
241 306 strict->import;
242 306 warnings->import;
243 306 utf8->import;
244  
245 306 my @final_args;
246 306 my $syntax_only = 0;
247 306 foreach (@args) {
248 335 ▶ if ( $_ eq ':moose' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($_ eq ':moose') { } 2 333 335
elsif ($_ eq ':tests') { } 126 207 333
elsif ($_ eq ':syntax') { } 206 1 207
elsif ($_ eq ':script') { } 1 0 1
249 2 push @final_args, '!before', '!after';
250 }
251 elsif ( $_ eq ':tests' ) {
252 126 push @final_args, '!pass';
253 }
254 elsif ( $_ eq ':syntax' ) {
255 206 $syntax_only = 1;
256 }
257 elsif ($_ eq ':script') {
258 1 $as_script = 1;
259 } else {
260 0 push @final_args, $_;
261 }
262 }
263  
264 306 $class->export_to_level(1, $class, @final_args);
265  
266 # if :syntax option exists, don't change settings
267 306 ▶ return if $syntax_only;
Branch: 1 branch
BranchTrueFalseTotal
if $syntax_only 206 100 306
268  
269 100 ▶ $as_script = 1 if $ENV{PLACK_ENV};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PLACK_ENV"} 1 99 100
270  
271 100 ▶ Dancer::GetOpt->process_args unless $as_script;
Branch: 1 branch
BranchTrueFalseTotal
unless $as_script 98 2 100
272  
273 100 _init_script_dir($script);
274 100 Dancer::Config->load;
275 }
276  
277 }
278  
279 # private code
280  
281 # FIXME handle previous usage of load_app with multiple app names
282 169 sub _load_app {
283 9 ▶ my ($app_name, %options) = @_;
Subroutine _load_app: called CC=4 SCAR=13.9
284 9 my $script = (caller)[1];
285 9 Dancer::Logger::core("loading application $app_name");
286  
287 # set the application
288 9 my $app = Dancer::App->set_running_app($app_name);
289  
290 # Application options
291 9 ▶ $app->set_app_prefix($options{prefix}) if $options{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"prefix"} 1 8 9
292 9 ▶ $app->settings($options{settings}) if $options{settings};
Branch: 1 branch
BranchTrueFalseTotal
if $options{"settings"} 1 8 9
293  
294 # load the application
295 9 _init_script_dir($script);
296 9 my ($res, $error) = Dancer::ModuleLoader->load($app_name);
297 9 ▶ $res or raise core => "unable to load application $app_name : $error";
Branch: 1 branch
BranchTrueFalseTotal
$res or &raise("core", "unable to load application $app_name : $error") 2 7 9
298  
299 # restore the main application
300 7 Dancer::App->set_running_app('main');
301 }
302  
303 sub _init_script_dir {
304 194 ▶ my ($script) = @_;
Subroutine _init_script_dir: called CC=13 SCAR=29.0
305  
306 194 my ($script_vol, $script_dirs, $script_name) =
307 File::Spec->splitpath(File::Spec->rel2abs($script));
308  
309 # normalize
310 194 ▶ if ( -d ( my $fulldir = File::Spec->catdir( $script_dirs, $script_name ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d (my $fulldir = "File::Spec"->catdir($script_dirs, $script_name))) 84 110 194
311 84 $script_dirs = $fulldir;
312 84 $script_name = '';
313 }
314  
315 194 my @script_dirs = File::Spec->splitdir($script_dirs);
316 194 my $script_path;
317 194 ▶ if ($script_vol) {
Branch: 1 branch
BranchTrueFalseTotal
if ($script_vol) { } 0 194 194
318 0 $script_path = Dancer::path($script_vol, $script_dirs);
319 } else {
320 194 $script_path = Dancer::path($script_dirs);
321 }
322  
323 194 my $LAYOUT_PRE_DANCER_1_2 = 1;
324  
325 # in bin/ or public/ or t/ we need to go one level up to find the appdir
326 194 ▶ $LAYOUT_PRE_DANCER_1_2 = 0
Branch: 1 branch
BranchTrueFalseTotal
if $script_dirs[$#script_dirs - 1] eq "bin" or $script_dirs[$#script_dirs - 1] eq "public" or $script_dirs[$#script_dirs - 1] eq "t" 0 194 194
Condition33%2/6
$script_dirs[$#script_dirs - 1] eq "bin" or $script_dirs[$#script_dirs - 1] eq "public" or $script_dirs[$#script_dirs - 1] eq "t"
l!l&&r!l&&!r
00194
$script_dirs[$#script_dirs - 1] eq "bin" or $script_dirs[$#script_dirs - 1] eq "public"
l!l&&r!l&&!r
00194
MC/DC0%0/3
$script_dirs[$#script_dirs - 1] eq "bin" or $script_dirs[$#script_dirs - 1] eq "public" or $script_dirs[$#script_dirs - 1] eq "t"
$script_dirs[$#script_dirs - 1] eq "bin" $script_dirs[$#script_dirs - 1] eq "public" $script_dirs[$#script_dirs - 1] eq "t"
Truth table25%1/4
A or B or C
A= $script_dirs[$#script_dirs - 1] eq "bin"B= $script_dirs[$#script_dirs - 1] eq "public"C= $script_dirs[$#script_dirs - 1] eq "t"
ABCresult
1XX1
01X1
0011
0000
327 if ($script_dirs[$#script_dirs - 1] eq 'bin')
328 or ($script_dirs[$#script_dirs - 1] eq 'public')
329 or ($script_dirs[$#script_dirs - 1] eq 't');
330  
331 my $appdir = $ENV{DANCER_APPDIR} || (
332 194 ▶ $LAYOUT_PRE_DANCER_1_2
Branch: 1 branch
BranchTrueFalseTotal
$LAYOUT_PRE_DANCER_1_2 ? : 127 0 127
Condition66%2/3
$ENV{'DANCER_APPDIR'} || ($LAYOUT_PRE_DANCER_1_2 ? $script_path : 'File::Spec'->rel2abs(path($script_path, '..')))
l!l&&r!l&&!r
671270
MC/DC0%0/2
$ENV{'DANCER_APPDIR'} || ($LAYOUT_PRE_DANCER_1_2 ? $script_path : 'File::Spec'->rel2abs(path($script_path, '..')))
$ENV{'DANCER_APPDIR'} ($LAYOUT_PRE_DANCER_1_2 ? $script_path : 'File::Spec'->rel2abs(path($script_path, '..')))
Truth table66%2/3
A || B
A= $ENV{'DANCER_APPDIR'}B= ($LAYOUT_PRE_DANCER_1_2 ? $script_path : 'File::Spec'->rel2abs(path($script_path, '..')))
ABresult
1X1
011
000
333 ? $script_path
334 : File::Spec->rel2abs(Dancer::path($script_path, '..'))
335 );
336 194 Dancer::setting(appdir => $appdir);
337  
338 # once the dancer_appdir have been defined, we export to env
339 194 $ENV{DANCER_APPDIR} = $appdir;
340  
341 194 Dancer::Logger::core("initializing appdir to: `$appdir'");
342  
343 Dancer::setting(confdir => $ENV{DANCER_CONFDIR}
344 194 ▶ || $appdir) unless Dancer::setting('confdir');
Branch: 1 branch
BranchTrueFalseTotal
unless setting("confdir") 127 67 194
Condition33%1/3
$ENV{'DANCER_CONFDIR'} || $appdir
l!l&&r!l&&!r
01270
MC/DC0%0/2
$ENV{'DANCER_CONFDIR'} || $appdir
$ENV{'DANCER_CONFDIR'} $appdir
Truth table33%1/3
A || B
A= $ENV{'DANCER_CONFDIR'}B= $appdir
ABresult
1X1
011
000
345  
346 Dancer::setting(public => $ENV{DANCER_PUBLIC}
347 194 ▶ || Dancer::FileUtils::path($appdir, 'public'));
Condition33%1/3
$ENV{'DANCER_PUBLIC'} || Dancer::FileUtils::path($appdir, 'public')
l!l&&r!l&&!r
01940
MC/DC0%0/2
$ENV{'DANCER_PUBLIC'} || Dancer::FileUtils::path($appdir, 'public')
$ENV{'DANCER_PUBLIC'} Dancer::FileUtils::path($appdir, 'public')
Truth table33%1/3
A || B
A= $ENV{'DANCER_PUBLIC'}B= Dancer::FileUtils::path($appdir, 'public')
ABresult
1X1
011
000
348  
349 Dancer::setting(views => $ENV{DANCER_VIEWS}
350 194 ▶ || Dancer::FileUtils::path($appdir, 'views'));
Condition33%1/3
$ENV{'DANCER_VIEWS'} || Dancer::FileUtils::path($appdir, 'views')
l!l&&r!l&&!r
01940
MC/DC0%0/2
$ENV{'DANCER_VIEWS'} || Dancer::FileUtils::path($appdir, 'views')
$ENV{'DANCER_VIEWS'} Dancer::FileUtils::path($appdir, 'views')
Truth table33%1/3
A || B
A= $ENV{'DANCER_VIEWS'}B= Dancer::FileUtils::path($appdir, 'views')
ABresult
1X1
011
000
351  
352 194 my ($res, $error) = Dancer::ModuleLoader->use_lib(Dancer::FileUtils::path($appdir, 'lib'));
353 194 ▶ $res or raise core => "unable to set libdir : $error";
Branch: 1 branch
BranchTrueFalseTotal
$res or &raise("core", "unable to set libdir : $error") 0 194 194
354 }
355  
356  
357 # Scheme grammar as defined in RFC 2396
358 # scheme = alpha *( alpha | digit | "+" | "-" | "." )
359 169 my $scheme_re = qr{ [a-z][a-z0-9\+\-\.]* }ix;
360 sub _redirect {
361 19 ▶ my ($destination, $status) = @_;
Subroutine _redirect: called CC=3 SCAR=11.0
362  
363 # RFC 2616 requires an absolute URI with a scheme,
364 # turn the URI into that if it needs it
365 19 ▶ if ($destination !~ m{^ $scheme_re : }x) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($destination =~ /^ $scheme_re : /x) 18 1 19
366 18 my $request = Dancer::SharedData->request;
367 18 $destination = $request->uri_for($destination, {}, 1);
368 }
369 19 my $response = Dancer::SharedData->response;
370 19 ▶ $response->status($status || 302);
Condition50%1/2
$status || 302
l!l
019
MC/DC0%0/1
$status || 302
$status
Truth table50%1/2
A
A= $status
Aresult
11
00
371 19 $response->headers('Location' => $destination);
372 }
373  
374 sub _session {
375 18 ▶ engine 'session'
Subroutine _session: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
engine("session") or &raise("core", "Must specify session engine in settings prior to using 'session' keyword") 0 18 18
376 or raise core => "Must specify session engine in settings prior to using 'session' keyword";
377 18 ▶ @_ == 0 ? Dancer::Session->get
Branch: 2 branches
BranchTrueFalseTotal
@_ == 0 ? : 2 16 18
@_ == 1 ? : 8 8 16
378 : @_ == 1 ? Dancer::Session->read(@_)
379 : Dancer::Session->write(@_);
380 }
381  
382 sub _send_file {
383 9 ▶ my ($path, %options) = @_;
Subroutine _send_file: called CC=14 SCAR=37.4
384 9 my $env = Dancer::SharedData->request->env;
385  
386 9 my $request = Dancer::Request->new_for_request('GET' => $path);
387 9 Dancer::SharedData->request($request);
388  
389 # if you asked for streaming but it's not supported in PSGI
390 9 ▶ if ( $options{'streaming'} && ! $env->{'psgi.streaming'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"streaming"} and not $env->{"psgi.streaming"}) 0 9 9
Condition33%1/3
$options{"streaming"} and not $env->{"psgi.streaming"}
!ll&&!rl&&r
900
MC/DC0%0/2
$options{"streaming"} and not $env->{"psgi.streaming"}
$options{"streaming"} not $env->{"psgi.streaming"}
Truth table33%1/3
A and not(B)
A= $options{"streaming"}B= not $env->{"psgi.streaming"}
ABresult
0X0
100
111
391 # TODO: throw a fit (AKA "exception") or a Dancer::Error?
392 0 raise core => 'Sorry, streaming is not supported on this server.';
393 }
394  
395 9 ▶ if (exists($options{content_type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"content_type"}) 3 6 9
396 3 $request->content_type($options{content_type});
397 }
398  
399 # If we're given an IO::Scalar object, DTRT (take the scalar ref from it)
400 9 ▶ if (Scalar::Util::blessed($path) && $path->isa('IO::Scalar')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($path) and $path->isa("IO::Scalar")) 0 9 9
Condition33%1/3
builtin::blessed($path) and $path->isa("IO::Scalar")
!ll&&!rl&&r
900
MC/DC0%0/2
builtin::blessed($path) and $path->isa("IO::Scalar")
builtin::blessed($path) $path->isa("IO::Scalar")
Truth table33%1/3
A and B
A= builtin::blessed($path)B= $path->isa("IO::Scalar")
ABresult
0X0
100
111
401 0 $path = $path->sref;
402 }
403  
404 9 my $resp;
405 9 ▶ if (ref($path) eq "SCALAR") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $path eq 'SCALAR') { } 1 8 9
406 # send_data
407 1 ▶ $resp = Dancer::SharedData->response() || Dancer::Response->new();
Condition33%1/3
'Dancer::SharedData'->response || 'Dancer::Response'->new
l!l&&r!l&&!r
100
MC/DC0%0/2
'Dancer::SharedData'->response || 'Dancer::Response'->new
'Dancer::SharedData'->response 'Dancer::Response'->new
Truth table33%1/3
A || B
A= 'Dancer::SharedData'->responseB= 'Dancer::Response'->new
ABresult
1X1
011
000
408 $resp->header('Content-Type' => exists($options{content_type}) ?
409 1 ▶ $options{content_type} : Dancer::MIME->default());
Branch: 1 branch
BranchTrueFalseTotal
exists $options{'content_type'} ? : 1 0 1
410 1 $resp->content($$path);
411 } else {
412 # real send_file
413 8 ▶ if ($options{system_path} && -f $path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{'system_path'} and -f $path) { } 2 6 8
Condition66%2/3
$options{"system_path"} and -f $path
!ll&&!rl&&r
602
MC/DC50%1/2
$options{"system_path"} and -f $path
$options{"system_path"} -f $path
Truth table66%2/3
A and B
A= $options{"system_path"}B= -f $path
ABresult
0X0
100
111
414 2 $resp = Dancer::Renderer->get_file_response_for_path($path);
415 } else {
416 6 $resp = Dancer::Renderer->get_file_response();
417 }
418 }
419  
420 9 ▶ if ($resp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp) 8 1 9
421  
422 8 ▶ if (exists($options{filename})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options{"filename"}) 2 6 8
423 2 $resp->push_header('Content-Disposition' =>
424 "attachment; filename=\"$options{filename}\""
425 );
426 }
427  
428 8 ▶ if ( $options{'streaming'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"streaming"}) 0 8 8
429 # handle streaming
430 $resp->streamed( sub {
431 0 ▶ my ( $status, $headers ) = @_;
Subroutine __ANON__: not called CC=2 SCAR=17.9
432 my %callbacks = defined $options{'callbacks'} ?
433 0 ▶ %{ $options{'callbacks'} } :
Branch: 1 branch
BranchTrueFalseTotal
defined $options{'callbacks'} ? : 0 0 0
434 ();
435  
436 return sub {
437 0 ▶ my $respond = shift;
Subroutine __ANON__: not called CC=7 SCAR=40.3
438 exists $callbacks{'override'}
439 0 ▶ and return $callbacks{'override'}->( $respond, $resp );
Branch: 1 branch
BranchTrueFalseTotal
exists $callbacks{"override"} and return $callbacks{"override"}->($respond, $resp) 0 0 0
440  
441 # get respond callback and set headers, get writer in return
442 0 my $writer = $respond->( [
443 $status,
444 $headers,
445 ] );
446  
447 # get content from original response
448 0 my $content = $resp->content;
449  
450 exists $callbacks{'around'}
451 0 ▶ and return $callbacks{'around'}->( $writer, $content );
Branch: 1 branch
BranchTrueFalseTotal
exists $callbacks{"around"} and return $callbacks{"around"}->($writer, $content) 0 0 0
452  
453 0 ▶ if ( ref $content ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content) { } 0 0 0
454 0 ▶ my $bytes = $options{'bytes'} || '43008'; # 42K (dams)
Condition0%0/2
$options{'bytes'} || '43008'
l!l
00
MC/DC0%0/1
$options{'bytes'} || '43008'
$options{'bytes'}
Truth table0%0/2
A
A= $options{'bytes'}
Aresult
11
00
455 0 my $buf;
456 0 ▶ while ( ( my $read = sysread $content, $buf, $bytes ) != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $read = sysread($content, $buf, $bytes)) != 0) 0 0 0
457 0 ▶ if ( exists $callbacks{'around_content'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $callbacks{'around_content'}) { } 0 0 0
458 0 $callbacks{'around_content'}->( $writer, $buf );
459 } else {
460 0 $writer->write($buf);
461 }
462 }
463 } else {
464 0 $writer->write($content);
465 }
466 0 };
467 0 } );
468 }
469  
470 8 return $resp;
471  
472 }
473  
474 Dancer::Error->new(
475 1 code => 404,
476 message => "No such file: `$path'"
477 )->render();
478 }
479  
480 # Start/Run the application with the chosen apphandler
481 sub _start {
482 2 ▶ my ($class, $request) = @_;
Subroutine _start: called CC=2 SCAR=7.8
483 2 Dancer::Config->load;
484  
485 # Backward compatibility for app.psgi that has sub { Dancer->dance($req) }
486 2 ▶ if ($request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request) 0 2 2
487 0 Dancer::Handler->init_request_headers( $request->env );
488 # TODO _build_headers should either not be private, or we should call
489 # init
490 0 $request->_build_headers;
491 0 return Dancer::Handler->handle_request($request);
492 }
493  
494 2 my $handler = Dancer::Handler->get_handler;
495 2 Dancer::Logger::core("loading handler '".ref($handler)."'");
496 2 return $handler->dance;
497 }
498  
499  
500 169 1;
501  
502 __END__
« blib/lib/Dancer/Config.pm ↑ Summary blib/lib/Dancer/Test.pm »