line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
41402
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
2
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
860
|
|
4
|
1
|
|
|
1
|
|
724
|
use Plack::Request (); |
|
1
|
|
|
|
|
77284
|
|
|
1
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Plack::Middleware::MethodOverride; |
7
|
|
|
|
|
|
|
$Plack::Middleware::MethodOverride::VERSION = '0.15'; |
8
|
|
|
|
|
|
|
# ABSTRACT: Override REST methods to Plack apps via POST |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
11
|
use parent 'Plack::Middleware'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
7314
|
use Plack::Util::Accessor 'param'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %allowed_method = map { $_ => undef } qw(GET HEAD PUT DELETE OPTIONS TRACE CONNECT PATCH); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
2
|
|
|
2
|
1
|
585
|
my $class = shift; |
17
|
2
|
|
|
|
|
18
|
my $self = $class->SUPER::new(@_); |
18
|
2
|
100
|
|
|
|
84
|
$self->{param} = 'x-tunneled-method' unless exists $self->{param}; |
19
|
2
|
100
|
|
|
|
9
|
$self->{header} = 'X-HTTP-Method-Override' unless exists $self->{header}; |
20
|
2
|
|
|
|
|
8
|
$self->header($self->{header}); # munge it |
21
|
2
|
|
|
|
|
5
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub call { |
25
|
32
|
|
|
32
|
1
|
76796
|
my ($self, $env) = @_; |
26
|
32
|
|
|
|
|
67
|
my $meth = $env->{'plack.original_request_method'} = $env->{REQUEST_METHOD}; |
27
|
|
|
|
|
|
|
|
28
|
32
|
100
|
66
|
|
|
158
|
if ($meth and uc $meth eq 'POST') { |
29
|
1
|
|
|
1
|
|
191
|
no warnings 'uninitialized'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
249
|
|
30
|
|
|
|
|
|
|
my $override = uc ( |
31
|
|
|
|
|
|
|
$env->{$self->header} |
32
|
28
|
|
66
|
|
|
57
|
or $env->{QUERY_STRING} && Plack::Request->new($env)->query_parameters->{$self->param} |
33
|
|
|
|
|
|
|
); |
34
|
28
|
100
|
|
|
|
520
|
$env->{REQUEST_METHOD} = $override if exists $allowed_method{$override}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
32
|
|
|
|
|
87
|
$self->app->($env); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub header { |
41
|
30
|
|
|
30
|
1
|
34
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
30
|
100
|
|
|
|
187
|
return $self->{header} if not @_; |
44
|
2
|
50
|
|
|
|
6
|
return $self->{header} = '' if not $_[0]; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
|
|
10
|
(my $key = 'HTTP_'.$_[0]) =~ tr/-a-z/_A-Z/; |
47
|
2
|
|
|
|
|
5
|
return $self->{header} = $key; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
__END__ |