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