lib/Dancer2/Core/Dispatcher.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 6 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 100% 50 / 50 CC 4 SCAR 7.9
CC
4
Cov
100%
dispatch
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« lib/Dancer2/Core/Role/HasEnvironment.pm ↑ Summary blib/lib/auto/share/dist/Dancer2/skel/default/lib/AppFile.pm »
1 package Dancer2::Core::Dispatcher;
2 # ABSTRACT: Class for dispatching request to the appropriate route handler
3 178 $Dancer2::Core::Dispatcher::VERSION = '2.3.0';
4 178 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 178 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 178 ▶use Dancer2::Core::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 178 ▶use Dancer2::Core::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 has apps => (
11 is => 'rw',
12 isa => ArrayRef,
13 3 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 178 );
15  
16 178 has apps_psgi => (
17 is => 'ro',
18 isa => ArrayRef,
19 lazy => 1,
20 builder => '_build_apps_psgi',
21 );
22  
23 45 ▶sub _build_apps_psgi {
Subroutine _build_apps_psgi: called CC=1 SCAR=0.0
24 45 my $self = shift;
25 45 return [ map +( $_->name, $_->to_app ), @{ $self->apps } ];
26 }
27  
28 149 ▶sub dispatch {
Subroutine dispatch: called CC=4 SCAR=13.9
Pod documented
29 149 my ( $self, $env ) = @_;
30 149 my @apps = @{ $self->apps_psgi };
31  
32 149 DISPATCH: while (1) {
33 168 ▶ for ( my $i = 0; $i < @apps; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @apps) 220 10 230
34 220 my ( $app_name, $app ) = @apps[ $i, $i + 1 ];
35  
36 220 my $response = $app->($env);
37  
38 # check for an internal request
39 220 ▶ delete Dancer2->runner->{'internal_forward'}
Branch: 1 branch
BranchTrueFalseTotal
delete "Dancer2"->runner->{"internal_forward"} and next DISPATCH 19 201 220
40 and next DISPATCH;
41  
42 # the app raised a flag saying it couldn't match anything
43 # which is different than "I matched and it's a 404"
44 delete Dancer2->runner->{'internal_404'}
45 201 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
delete "Dancer2"->runner->{"internal_404"} or do { delete "Dancer2"->runner->{"internal_request"}; return $response } 62 139 201
46 139 delete Dancer2->runner->{'internal_request'};
47 139 return $response;
48 };
49 }
50  
51 # don't run anymore
52 10 delete Dancer2->runner->{'internal_request'};
53 10 last;
54 } # while
55  
56 # a 404 on all apps, using the first app
57 10 my $default_app = $self->apps->[0];
58 10 my $request = $default_app->build_request($env);
59 10 return $default_app->response_not_found($request)->to_psgi;
60 }
61  
62 178 1;
63  
64 __END__
« lib/Dancer2/Core/Role/HasEnvironment.pm ↑ Summary blib/lib/auto/share/dist/Dancer2/skel/default/lib/AppFile.pm »