line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::App::Cascade; |
2
|
2
|
|
|
2
|
|
116727
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
3
|
2
|
|
|
2
|
|
8
|
use base qw(Plack::Component); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
717
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
12
|
use Plack::Util; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
39
|
|
6
|
2
|
|
|
2
|
|
782
|
use Plack::Util::Accessor qw(apps catch codes); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub add { |
9
|
6
|
|
|
6
|
1
|
21
|
my $self = shift; |
10
|
6
|
100
|
|
|
|
11
|
$self->apps([]) unless $self->apps; |
11
|
6
|
|
|
|
|
10
|
push @{$self->apps}, @_; |
|
6
|
|
|
|
|
10
|
|
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub prepare_app { |
15
|
6
|
|
|
6
|
1
|
16
|
my $self = shift; |
16
|
6
|
100
|
|
|
|
10
|
my %codes = map { $_ => 1 } @{ $self->catch || [ 404 ] }; |
|
8
|
|
|
|
|
26
|
|
|
6
|
|
|
|
|
17
|
|
17
|
6
|
|
|
|
|
20
|
$self->codes(\%codes); |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub call { |
21
|
6
|
|
|
6
|
1
|
12
|
my($self, $env) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
return sub { |
24
|
6
|
|
|
6
|
|
11
|
my $respond = shift; |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
|
|
7
|
my $done; |
27
|
|
|
|
|
|
|
my $respond_wrapper = sub { |
28
|
9
|
|
|
|
|
21
|
my $res = shift; |
29
|
9
|
100
|
|
|
|
18
|
if ($self->codes->{$res->[0]}) { |
30
|
|
|
|
|
|
|
# suppress output by giving the app an |
31
|
|
|
|
|
|
|
# output spool which drops everything on the floor |
32
|
|
|
|
|
|
|
return Plack::Util::inline_object |
33
|
7
|
|
|
|
|
35
|
write => sub { }, close => sub { }; |
34
|
|
|
|
|
|
|
} else { |
35
|
2
|
|
|
|
|
4
|
$done = 1; |
36
|
2
|
|
|
|
|
12
|
return $respond->($res); |
37
|
|
|
|
|
|
|
} |
38
|
6
|
|
|
|
|
17
|
}; |
39
|
|
|
|
|
|
|
|
40
|
6
|
100
|
|
|
|
11
|
my @try = @{$self->apps || []}; |
|
6
|
|
|
|
|
13
|
|
41
|
6
|
|
|
|
|
10
|
my $tries_left = 0 + @try; |
42
|
|
|
|
|
|
|
|
43
|
6
|
100
|
|
|
|
13
|
if (not $tries_left) { |
44
|
1
|
|
|
|
|
4
|
return $respond->([ 404, [ 'Content-Type' => 'text/html' ], [ '404 Not Found' ] ]) |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
13
|
for my $app (@try) { |
48
|
12
|
|
|
|
|
38
|
my $res = $app->($env); |
49
|
12
|
100
|
|
|
|
89
|
if ($tries_left-- == 1) { |
50
|
3
|
|
|
|
|
13
|
$respond_wrapper = sub { $respond->(shift) }; |
|
3
|
|
|
|
|
16
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
12
|
100
|
|
|
|
30
|
if (ref $res eq 'CODE') { |
54
|
4
|
|
|
|
|
8
|
$res->($respond_wrapper); |
55
|
|
|
|
|
|
|
} else { |
56
|
8
|
|
|
|
|
13
|
$respond_wrapper->($res); |
57
|
|
|
|
|
|
|
} |
58
|
12
|
100
|
|
|
|
68
|
return if $done; |
59
|
|
|
|
|
|
|
} |
60
|
6
|
|
|
|
|
46
|
}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |