line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::Dispatch::Wrapper; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
82
|
use strictures 1; |
|
14
|
|
|
|
|
117
|
|
|
14
|
|
|
|
|
824
|
|
4
|
14
|
|
|
14
|
|
2692
|
use Moo; |
|
14
|
|
|
|
|
3092
|
|
|
14
|
|
|
|
|
1127
|
|
5
|
14
|
|
|
14
|
|
25930
|
use Exporter 'import'; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
6211
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw(dispatch_wrapper redispatch_to response_filter); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
extends 'Plack::Middleware'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'wrapper' => (is => 'ro', required => 1); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub dispatch_wrapper (&) { |
14
|
0
|
|
|
0
|
0
|
0
|
my ($code) = @_; |
15
|
0
|
|
|
|
|
0
|
__PACKAGE__->from_code($code); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub from_code { |
19
|
1
|
|
|
1
|
0
|
3
|
my ($class, $code) = @_; |
20
|
1
|
|
|
|
|
4
|
$class->new(wrapper => $code); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub redispatch_to { |
24
|
0
|
|
|
0
|
0
|
0
|
my ($new_path) = @_; |
25
|
|
|
|
|
|
|
__PACKAGE__->from_code(sub { |
26
|
0
|
|
|
0
|
|
0
|
$_[1]->({ %{$_[0]}, PATH_INFO => $new_path }); |
|
0
|
|
|
|
|
0
|
|
27
|
0
|
|
|
|
|
0
|
}); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub response_filter (&) { |
31
|
1
|
|
|
1
|
0
|
9
|
my ($code) = @_; |
32
|
|
|
|
|
|
|
__PACKAGE__->from_code(sub { |
33
|
1
|
|
|
1
|
|
3
|
my @result = $_[1]->($_[0]); |
34
|
1
|
50
|
|
|
|
7
|
if (@result) { |
35
|
1
|
|
|
|
|
4
|
$code->(@result); |
36
|
|
|
|
|
|
|
} else { |
37
|
|
|
|
|
|
|
() |
38
|
0
|
|
|
|
|
0
|
} |
39
|
1
|
|
|
|
|
11
|
}); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub to_app { |
43
|
1
|
|
|
1
|
1
|
4
|
my $code = $_[0]->wrapper; |
44
|
1
|
|
|
|
|
3
|
my $app = $_[0]->app; |
45
|
1
|
|
|
1
|
|
3
|
sub { $code->($_[0], $app) } |
46
|
1
|
|
|
|
|
8
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |