line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::Static::Combine; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Plack::Middleware::Static::Combine::VERSION = '0.01'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
#ABSTRACT: Serve multiple static files combined |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
25174
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
73
|
|
8
|
2
|
|
|
2
|
|
892
|
use parent qw(Plack::Middleware::Static); |
|
2
|
|
|
|
|
320
|
|
|
2
|
|
|
|
|
13
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
41456
|
use Plack::Util; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
82
|
|
11
|
2
|
|
|
2
|
|
9
|
use Plack::Util::Accessor qw(files); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
9
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub _handle_static { |
14
|
5
|
|
|
5
|
|
31162
|
my ($self, $env) = @_; |
15
|
|
|
|
|
|
|
|
16
|
5
|
50
|
|
|
|
26
|
my $path_match = $self->path or return; |
17
|
5
|
|
|
|
|
192
|
my $path = $env->{PATH_INFO}; |
18
|
|
|
|
|
|
|
|
19
|
5
|
|
|
|
|
11
|
for ($path) { |
20
|
5
|
50
|
|
|
|
38
|
my $matched = 'CODE' eq ref $path_match ? $path_match->($_) : $_ =~ $path_match; |
21
|
5
|
50
|
|
|
|
20
|
return unless $matched; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
5
|
|
50
|
|
|
36
|
$self->{file} ||= Plack::App::File->new({ root => $self->root || '.', encoding => $self->encoding }); |
|
|
|
33
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# copied from Plack::Middleware::Static up to this line |
27
|
|
|
|
|
|
|
|
28
|
5
|
|
|
|
|
220
|
my ($res, $type, $lastmod); |
29
|
5
|
|
|
|
|
9
|
my $length = 0; |
30
|
|
|
|
|
|
|
|
31
|
5
|
100
|
|
|
|
6
|
foreach my $file ( @{ $self->files || [] } ) { |
|
5
|
|
|
|
|
17
|
|
32
|
|
|
|
|
|
|
|
33
|
8
|
|
|
|
|
143
|
local $env->{PATH_INFO} = $file; |
34
|
8
|
|
|
|
|
35
|
my $got = $self->{file}->call($env); |
35
|
8
|
|
|
8
|
|
1914
|
Plack::Util::response_cb($got, sub { $got = shift; }); |
|
8
|
|
|
|
|
110
|
|
36
|
|
|
|
|
|
|
|
37
|
8
|
100
|
|
|
|
153
|
return $got unless $got->[0] eq '200'; |
38
|
|
|
|
|
|
|
|
39
|
7
|
100
|
|
|
|
18
|
if ($res) { |
40
|
3
|
100
|
|
|
|
12
|
if ( $type ne Plack::Util::header_get($got->[1],'Content-Type') ) { |
41
|
1
|
|
|
|
|
33
|
$res = [500,['Content-Type'=>'text/plain'],['files must have same type']]; |
42
|
1
|
|
|
|
|
18
|
$length = length $res->[2]->[0]; |
43
|
1
|
|
|
|
|
15
|
last; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# TODO: better combine by sub? |
47
|
2
|
|
|
|
|
59
|
my $body = $res->[2]; |
48
|
2
|
50
|
|
|
|
8
|
if (ref $body ne 'ARRAY') { |
49
|
2
|
|
|
|
|
5
|
$res->[2] = [ ]; |
50
|
2
|
|
|
2
|
|
14
|
Plack::Util::foreach($body,sub { push @{$res->[2]}, shift; }); |
|
2
|
|
|
|
|
203
|
|
|
2
|
|
|
|
|
53
|
|
51
|
|
|
|
|
|
|
} |
52
|
2
|
|
|
2
|
|
141
|
Plack::Util::foreach($got->[2],sub { push @{$res->[2]}, shift; }); |
|
2
|
|
|
|
|
146
|
|
|
2
|
|
|
|
|
46
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# TODO: Adjust Last-Modified |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
} else { |
57
|
4
|
|
|
|
|
17
|
$type = Plack::Util::header_get($got->[1],'Content-Type'); |
58
|
4
|
|
|
|
|
127
|
$lastmod = Plack::Util::header_get($got->[1],'Last-Modified'); |
59
|
4
|
|
|
|
|
101
|
$res = $got; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
6
|
|
|
|
|
97
|
$length += Plack::Util::header_get($got->[1],'Content-Length'); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
4
|
100
|
|
|
|
76
|
Plack::Util::header_set($res->[1],'Content-Length',$length) if $res; |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
95
|
return $res; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |