line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::MethodOverride; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
16845
|
use 5.010; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
161
|
|
4
|
5
|
|
|
5
|
|
421
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
5
|
|
|
|
|
5931
|
|
|
5
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1259
|
use Scalar::Util qw(weaken); |
|
5
|
|
|
|
|
20
|
|
|
5
|
|
|
|
|
1731
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.052'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
4
|
|
|
4
|
1
|
120
|
my ($self, $app, $conf) = @_; |
12
|
|
|
|
|
|
|
|
13
|
4
|
100
|
|
|
|
12
|
my $header = |
14
|
|
|
|
|
|
|
exists $conf->{header} ? $conf->{header} : 'X-HTTP-Method-Override'; |
15
|
4
|
100
|
|
|
|
7
|
my $param = exists $conf->{param} ? $conf->{param} : undef; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$app->hook( |
18
|
|
|
|
|
|
|
after_build_tx => sub { |
19
|
39
|
|
|
39
|
|
197709
|
my $tx = shift; |
20
|
|
|
|
|
|
|
|
21
|
39
|
|
|
|
|
106
|
weaken $tx; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$tx->req->content->on(body => sub { |
24
|
39
|
|
|
|
|
16588
|
my $req = $tx->req; |
25
|
|
|
|
|
|
|
|
26
|
39
|
100
|
|
|
|
170
|
return unless $req->method eq 'POST'; |
27
|
|
|
|
|
|
|
|
28
|
35
|
|
100
|
|
|
277
|
my $method = defined $header && $req->headers->header($header); |
29
|
|
|
|
|
|
|
|
30
|
35
|
100
|
|
|
|
327
|
if ($method) { |
|
|
100
|
|
|
|
|
|
31
|
8
|
|
|
|
|
17
|
$req->headers->remove($header); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
elsif (defined $param) { |
34
|
21
|
|
|
|
|
44
|
$method = $req->url->query->clone->param($param); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
35
|
100
|
66
|
|
|
2006
|
if ($method and $method =~ /^[A-Za-z]+$/) { |
38
|
21
|
|
66
|
|
|
70
|
$app->log->debug(($header // $param) . ': ' . $method); |
39
|
21
|
|
|
|
|
566
|
$req->method($method); |
40
|
|
|
|
|
|
|
} |
41
|
39
|
|
|
|
|
90
|
}); |
42
|
|
|
|
|
|
|
} |
43
|
4
|
|
|
|
|
27
|
); |
44
|
|
|
|
|
|
|
|
45
|
4
|
100
|
|
|
|
59
|
if (defined $param) { |
46
|
|
|
|
|
|
|
$app->hook(before_dispatch => sub { |
47
|
25
|
|
|
25
|
|
8201
|
shift->req->url->query->remove($param); |
48
|
3
|
|
|
|
|
10
|
}); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
1; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |