| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Plack::Middleware::Options; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
23646
|
use strict; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
78
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
64
|
|
|
5
|
2
|
|
|
2
|
|
1179
|
use parent 'Plack::Middleware'; |
|
|
2
|
|
|
|
|
318
|
|
|
|
2
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my @HTTP_METHODS = qw/CONNECT DELETE GET HEAD POST PUT TRACE/; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub prepare_app { |
|
12
|
3
|
|
|
3
|
1
|
4202
|
my ( $self ) = @_; |
|
13
|
|
|
|
|
|
|
|
|
14
|
3
|
|
|
|
|
89
|
my $allowed = $self->{'allowed'}; |
|
15
|
3
|
100
|
|
|
|
16
|
if(ref $allowed eq 'ARRAY') { |
|
|
|
100
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
2
|
$allowed = { map { $_ => 1 } @$allowed }; |
|
|
2
|
|
|
|
|
8
|
|
|
17
|
|
|
|
|
|
|
} elsif(ref $allowed ne 'HASH') { |
|
18
|
7
|
|
|
|
|
15
|
$allowed = { |
|
19
|
1
|
|
|
|
|
2
|
map { $_ => 1 } @HTTP_METHODS, |
|
20
|
|
|
|
|
|
|
}; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
3
|
|
|
|
|
10
|
$self->{'allowed'} = $allowed; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub call { |
|
26
|
24
|
|
|
24
|
1
|
138179
|
my ( $self, $env ) = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
24
|
|
|
|
|
64
|
my $method = $env->{'REQUEST_METHOD'}; |
|
29
|
|
|
|
|
|
|
|
|
30
|
24
|
100
|
|
|
|
134
|
if($method eq 'OPTIONS') { |
|
|
|
100
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
6
|
my @allowed; |
|
32
|
|
|
|
|
|
|
|
|
33
|
3
|
50
|
|
|
|
11
|
if($env->{'REQUEST_URI'} eq '*') { |
|
34
|
0
|
|
|
|
|
0
|
@allowed = @HTTP_METHODS; |
|
35
|
|
|
|
|
|
|
} else { |
|
36
|
3
|
|
|
|
|
7
|
@allowed = keys %{ $self->{'allowed'} }; |
|
|
3
|
|
|
|
|
124
|
|
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
return [ |
|
40
|
3
|
|
|
|
|
38
|
200, |
|
41
|
|
|
|
|
|
|
['Allow' => join(', ', @allowed)], |
|
42
|
|
|
|
|
|
|
[], |
|
43
|
|
|
|
|
|
|
]; |
|
44
|
|
|
|
|
|
|
} elsif(exists $self->{'allowed'}{$method}) { |
|
45
|
12
|
|
|
|
|
55
|
return $self->app->($env); |
|
46
|
|
|
|
|
|
|
} else { |
|
47
|
|
|
|
|
|
|
return [ |
|
48
|
9
|
|
|
|
|
146
|
405, |
|
49
|
|
|
|
|
|
|
[ |
|
50
|
9
|
|
|
|
|
24
|
'Allow' => join(', ', keys %{ $self->{'allowed'} }), |
|
51
|
|
|
|
|
|
|
'Content-Type' => 'text/plain', |
|
52
|
|
|
|
|
|
|
], |
|
53
|
|
|
|
|
|
|
['Method not allowed'], |
|
54
|
|
|
|
|
|
|
]; |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
}; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |