line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Static; |
2
|
4
|
|
|
4
|
|
58330
|
use strict; |
|
4
|
|
|
|
|
22
|
|
|
4
|
|
|
|
|
106
|
|
3
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
105
|
|
4
|
4
|
|
|
4
|
|
378
|
use parent qw/Plack::Middleware/; |
|
4
|
|
|
|
|
271
|
|
|
4
|
|
|
|
|
20
|
|
5
|
4
|
|
|
4
|
|
1606
|
use Plack::App::File; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
140
|
|
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
22
|
use Plack::Util::Accessor qw( path root encoding pass_through content_type ); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
16
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub call { |
10
|
41
|
|
|
41
|
1
|
58
|
my $self = shift; |
11
|
41
|
|
|
|
|
54
|
my $env = shift; |
12
|
|
|
|
|
|
|
|
13
|
41
|
|
|
|
|
73
|
my $res = $self->_handle_static($env); |
14
|
41
|
100
|
66
|
|
|
267
|
if ($res && not ($self->pass_through and $res->[0] == 404)) { |
|
|
|
100
|
|
|
|
|
15
|
12
|
|
|
|
|
63
|
return $res; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
29
|
|
|
|
|
65
|
return $self->app->($env); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _handle_static { |
22
|
41
|
|
|
41
|
|
58
|
my($self, $env) = @_; |
23
|
|
|
|
|
|
|
|
24
|
41
|
50
|
|
|
|
97
|
my $path_match = $self->path or return; |
25
|
41
|
|
|
|
|
58
|
my $path = $env->{PATH_INFO}; |
26
|
|
|
|
|
|
|
|
27
|
41
|
|
|
|
|
61
|
for ($path) { |
28
|
41
|
100
|
|
|
|
153
|
my $matched = 'CODE' eq ref $path_match ? $path_match->($_, $env) : $_ =~ $path_match; |
29
|
41
|
100
|
|
|
|
191
|
return unless $matched; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
13
|
|
50
|
|
|
55
|
$self->{file} ||= Plack::App::File->new({ root => $self->root || '.', encoding => $self->encoding, content_type => $self->content_type }); |
|
|
|
66
|
|
|
|
|
33
|
13
|
|
|
|
|
44
|
local $env->{PATH_INFO} = $path; # rewrite PATH |
34
|
13
|
|
|
|
|
46
|
return $self->{file}->call($env); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
__END__ |