Commit | Line | Data |
4ed4fb42 |
1 | package Web::Dispatch::Wrapper; |
2 | |
3 | use strictures 1; |
445b3ea0 |
4 | use Exporter 'import'; |
4ed4fb42 |
5 | |
445b3ea0 |
6 | our @EXPORT_OK = qw(dispatch_wrapper redispatch_to response_filter); |
7 | |
8 | sub dispatch_wrapper (&) { |
4ed4fb42 |
9 | my ($class, $code) = @_; |
10 | bless(\$code, $class); |
11 | } |
12 | |
445b3ea0 |
13 | sub redispatch_to { |
14 | my ($class, $new_path) = @_; |
15 | $class->from_code(sub { |
16 | $_[1]->({ %{$_[0]}, PATH_INFO => $new_path }); |
17 | }); |
18 | } |
19 | |
20 | sub response_filter (&) { |
21 | my ($class, $code) = @_; |
22 | $class->from_code(sub { |
23 | my @result = $_[1]->($_[0]); |
24 | if (@result) { |
25 | $code->(@result); |
26 | } else { |
27 | () |
28 | } |
29 | }); |
30 | } |
31 | |
4ed4fb42 |
32 | sub wrap { |
33 | my $code = ${$_[0]}; |
34 | my $app = $_[1]; |
35 | sub { $code->($_[0], $app) } |
36 | } |
37 | |
38 | 1; |